feat: Implement DNS_PROVIDER_TYPE variable for infecting server

This commit is contained in:
NaiJi 2023-01-17 17:27:32 +04:00
parent 841aee73e8
commit 08cd59a709
4 changed files with 26 additions and 2 deletions

View file

@ -332,6 +332,7 @@ class DigitalOceanApi extends ServerProviderApi with VolumeProviderApi {
required final User rootUser, required final User rootUser,
required final String domainName, required final String domainName,
required final String serverType, required final String serverType,
required final DnsProvider dnsProvider,
}) async { }) async {
ServerHostingDetails? serverDetails; ServerHostingDetails? serverDetails;
@ -344,9 +345,10 @@ class DigitalOceanApi extends ServerProviderApi with VolumeProviderApi {
final String formattedHostname = getHostnameFromDomain(domainName); final String formattedHostname = getHostnameFromDomain(domainName);
const String infectBranch = 'providers/digital-ocean'; const String infectBranch = 'providers/digital-ocean';
final String stagingAcme = StagingOptions.stagingAcme ? 'true' : 'false'; final String stagingAcme = StagingOptions.stagingAcme ? 'true' : 'false';
final String dnsProviderType = dnsProviderToInfectName(dnsProvider);
final String userdataString = final String userdataString =
"#cloud-config\nruncmd:\n- curl https://git.selfprivacy.org/SelfPrivacy/selfprivacy-nixos-infect/raw/branch/$infectBranch/nixos-infect | PROVIDER=$infectProviderName STAGING_ACME='$stagingAcme' DOMAIN='$domainName' LUSER='${rootUser.login}' ENCODED_PASSWORD='$base64Password' CF_TOKEN=$dnsApiToken DB_PASSWORD=$dbPassword API_TOKEN=$apiToken HOSTNAME=$formattedHostname bash 2>&1 | tee /tmp/infect.log"; "#cloud-config\nruncmd:\n- curl https://git.selfprivacy.org/SelfPrivacy/selfprivacy-nixos-infect/raw/branch/$infectBranch/nixos-infect | PROVIDER=$infectProviderName DNS_PROVIDER_TYPE=$dnsProviderType STAGING_ACME='$stagingAcme' DOMAIN='$domainName' LUSER='${rootUser.login}' ENCODED_PASSWORD='$base64Password' CF_TOKEN=$dnsApiToken DB_PASSWORD=$dbPassword API_TOKEN=$apiToken HOSTNAME=$formattedHostname bash 2>&1 | tee /tmp/infect.log";
print(userdataString); print(userdataString);
Response? serverCreateResponse; Response? serverCreateResponse;

View file

@ -356,6 +356,7 @@ class HetznerApi extends ServerProviderApi with VolumeProviderApi {
required final User rootUser, required final User rootUser,
required final String domainName, required final String domainName,
required final String serverType, required final String serverType,
required final DnsProvider dnsProvider,
}) async { }) async {
final APIGenericResult<ServerVolume?> newVolumeResponse = final APIGenericResult<ServerVolume?> newVolumeResponse =
await createVolume(); await createVolume();
@ -374,6 +375,7 @@ class HetznerApi extends ServerProviderApi with VolumeProviderApi {
domainName: domainName, domainName: domainName,
volume: newVolumeResponse.data!, volume: newVolumeResponse.data!,
serverType: serverType, serverType: serverType,
dnsProvider: dnsProvider,
); );
} }
@ -383,6 +385,7 @@ class HetznerApi extends ServerProviderApi with VolumeProviderApi {
required final String domainName, required final String domainName,
required final ServerVolume volume, required final ServerVolume volume,
required final String serverType, required final String serverType,
required final DnsProvider dnsProvider,
}) async { }) async {
final Dio client = await getClient(); final Dio client = await getClient();
@ -395,9 +398,10 @@ class HetznerApi extends ServerProviderApi with VolumeProviderApi {
final String stagingAcme = StagingOptions.stagingAcme ? 'true' : 'false'; final String stagingAcme = StagingOptions.stagingAcme ? 'true' : 'false';
final String base64Password = final String base64Password =
base64.encode(utf8.encode(rootUser.password ?? 'PASS')); base64.encode(utf8.encode(rootUser.password ?? 'PASS'));
final String dnsProviderType = dnsProviderToInfectName(dnsProvider);
final String userdataString = final String userdataString =
"#cloud-config\nruncmd:\n- curl https://git.selfprivacy.org/SelfPrivacy/selfprivacy-nixos-infect/raw/branch/$infectBranch/nixos-infect | STAGING_ACME='$stagingAcme' PROVIDER=$infectProviderName NIX_CHANNEL=nixos-21.05 DOMAIN='$domainName' LUSER='${rootUser.login}' ENCODED_PASSWORD='$base64Password' CF_TOKEN=$dnsApiToken DB_PASSWORD=$dbPassword API_TOKEN=$apiToken HOSTNAME=$hostname bash 2>&1 | tee /tmp/infect.log"; "#cloud-config\nruncmd:\n- curl https://git.selfprivacy.org/SelfPrivacy/selfprivacy-nixos-infect/raw/branch/$infectBranch/nixos-infect | STAGING_ACME='$stagingAcme' PROVIDER=$infectProviderName DNS_PROVIDER_TYPE=$dnsProviderType NIX_CHANNEL=nixos-21.05 DOMAIN='$domainName' LUSER='${rootUser.login}' ENCODED_PASSWORD='$base64Password' CF_TOKEN=$dnsApiToken DB_PASSWORD=$dbPassword API_TOKEN=$apiToken HOSTNAME=$hostname bash 2>&1 | tee /tmp/infect.log";
Response? serverCreateResponse; Response? serverCreateResponse;
ServerHostingDetails? serverDetails; ServerHostingDetails? serverDetails;

View file

@ -39,6 +39,7 @@ abstract class ServerProviderApi extends ApiMap {
required final User rootUser, required final User rootUser,
required final String domainName, required final String domainName,
required final String serverType, required final String serverType,
required final DnsProvider dnsProvider,
}); });
Future<APIGenericResult<void>> createReverseDns({ Future<APIGenericResult<void>> createReverseDns({
required final ServerHostingDetails serverDetails, required final ServerHostingDetails serverDetails,
@ -54,6 +55,20 @@ abstract class ServerProviderApi extends ApiMap {
final DateTime end, final DateTime end,
); );
String dnsProviderToInfectName(final DnsProvider dnsProvider) {
String dnsProviderType;
switch (dnsProvider) {
case DnsProvider.digitalOcean:
dnsProviderType = 'DIGITALOCEAN';
break;
case DnsProvider.cloudflare:
default:
dnsProviderType = 'CLOUDFLARE';
break;
}
return dnsProviderType;
}
/// Provider name key which lets infect understand what kind of installation /// Provider name key which lets infect understand what kind of installation
/// it requires, for example 'digitaloceal' for Digital Ocean /// it requires, for example 'digitaloceal' for Digital Ocean
String get infectProviderName; String get infectProviderName;

View file

@ -260,6 +260,7 @@ class ServerInstallationRepository {
ServerHostingDetails? serverDetails; ServerHostingDetails? serverDetails;
try { try {
final APIGenericResult createResult = await api.createServer( final APIGenericResult createResult = await api.createServer(
dnsProvider: getIt<ApiConfigModel>().dnsProvider!,
dnsApiToken: cloudFlareKey, dnsApiToken: cloudFlareKey,
rootUser: rootUser, rootUser: rootUser,
domainName: domainName, domainName: domainName,
@ -284,6 +285,7 @@ class ServerInstallationRepository {
try { try {
final APIGenericResult<ServerHostingDetails?> createServerResult = final APIGenericResult<ServerHostingDetails?> createServerResult =
await api.createServer( await api.createServer(
dnsProvider: getIt<ApiConfigModel>().dnsProvider!,
dnsApiToken: cloudFlareKey, dnsApiToken: cloudFlareKey,
rootUser: rootUser, rootUser: rootUser,
domainName: domainName, domainName: domainName,
@ -308,6 +310,7 @@ class ServerInstallationRepository {
ServerHostingDetails? serverDetails; ServerHostingDetails? serverDetails;
try { try {
final APIGenericResult createResult = await api.createServer( final APIGenericResult createResult = await api.createServer(
dnsProvider: getIt<ApiConfigModel>().dnsProvider!,
dnsApiToken: cloudFlareKey, dnsApiToken: cloudFlareKey,
rootUser: rootUser, rootUser: rootUser,
domainName: domainName, domainName: domainName,