mirror of
https://git.selfprivacy.org/kherel/selfprivacy.org.app.git
synced 2024-11-16 05:33:17 +00:00
feat: Implement DNS_PROVIDER_TYPE variable for infecting server
This commit is contained in:
parent
841aee73e8
commit
08cd59a709
|
@ -332,6 +332,7 @@ class DigitalOceanApi extends ServerProviderApi with VolumeProviderApi {
|
|||
required final User rootUser,
|
||||
required final String domainName,
|
||||
required final String serverType,
|
||||
required final DnsProvider dnsProvider,
|
||||
}) async {
|
||||
ServerHostingDetails? serverDetails;
|
||||
|
||||
|
@ -344,9 +345,10 @@ class DigitalOceanApi extends ServerProviderApi with VolumeProviderApi {
|
|||
final String formattedHostname = getHostnameFromDomain(domainName);
|
||||
const String infectBranch = 'providers/digital-ocean';
|
||||
final String stagingAcme = StagingOptions.stagingAcme ? 'true' : 'false';
|
||||
final String dnsProviderType = dnsProviderToInfectName(dnsProvider);
|
||||
|
||||
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);
|
||||
|
||||
Response? serverCreateResponse;
|
||||
|
|
|
@ -356,6 +356,7 @@ class HetznerApi extends ServerProviderApi with VolumeProviderApi {
|
|||
required final User rootUser,
|
||||
required final String domainName,
|
||||
required final String serverType,
|
||||
required final DnsProvider dnsProvider,
|
||||
}) async {
|
||||
final APIGenericResult<ServerVolume?> newVolumeResponse =
|
||||
await createVolume();
|
||||
|
@ -374,6 +375,7 @@ class HetznerApi extends ServerProviderApi with VolumeProviderApi {
|
|||
domainName: domainName,
|
||||
volume: newVolumeResponse.data!,
|
||||
serverType: serverType,
|
||||
dnsProvider: dnsProvider,
|
||||
);
|
||||
}
|
||||
|
||||
|
@ -383,6 +385,7 @@ class HetznerApi extends ServerProviderApi with VolumeProviderApi {
|
|||
required final String domainName,
|
||||
required final ServerVolume volume,
|
||||
required final String serverType,
|
||||
required final DnsProvider dnsProvider,
|
||||
}) async {
|
||||
final Dio client = await getClient();
|
||||
|
||||
|
@ -395,9 +398,10 @@ class HetznerApi extends ServerProviderApi with VolumeProviderApi {
|
|||
final String stagingAcme = StagingOptions.stagingAcme ? 'true' : 'false';
|
||||
final String base64Password =
|
||||
base64.encode(utf8.encode(rootUser.password ?? 'PASS'));
|
||||
final String dnsProviderType = dnsProviderToInfectName(dnsProvider);
|
||||
|
||||
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;
|
||||
ServerHostingDetails? serverDetails;
|
||||
|
|
|
@ -39,6 +39,7 @@ abstract class ServerProviderApi extends ApiMap {
|
|||
required final User rootUser,
|
||||
required final String domainName,
|
||||
required final String serverType,
|
||||
required final DnsProvider dnsProvider,
|
||||
});
|
||||
Future<APIGenericResult<void>> createReverseDns({
|
||||
required final ServerHostingDetails serverDetails,
|
||||
|
@ -54,6 +55,20 @@ abstract class ServerProviderApi extends ApiMap {
|
|||
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
|
||||
/// it requires, for example 'digitaloceal' for Digital Ocean
|
||||
String get infectProviderName;
|
||||
|
|
|
@ -260,6 +260,7 @@ class ServerInstallationRepository {
|
|||
ServerHostingDetails? serverDetails;
|
||||
try {
|
||||
final APIGenericResult createResult = await api.createServer(
|
||||
dnsProvider: getIt<ApiConfigModel>().dnsProvider!,
|
||||
dnsApiToken: cloudFlareKey,
|
||||
rootUser: rootUser,
|
||||
domainName: domainName,
|
||||
|
@ -284,6 +285,7 @@ class ServerInstallationRepository {
|
|||
try {
|
||||
final APIGenericResult<ServerHostingDetails?> createServerResult =
|
||||
await api.createServer(
|
||||
dnsProvider: getIt<ApiConfigModel>().dnsProvider!,
|
||||
dnsApiToken: cloudFlareKey,
|
||||
rootUser: rootUser,
|
||||
domainName: domainName,
|
||||
|
@ -308,6 +310,7 @@ class ServerInstallationRepository {
|
|||
ServerHostingDetails? serverDetails;
|
||||
try {
|
||||
final APIGenericResult createResult = await api.createServer(
|
||||
dnsProvider: getIt<ApiConfigModel>().dnsProvider!,
|
||||
dnsApiToken: cloudFlareKey,
|
||||
rootUser: rootUser,
|
||||
domainName: domainName,
|
||||
|
|
Loading…
Reference in a new issue