mirror of
https://git.selfprivacy.org/kherel/selfprivacy.org.app.git
synced 2024-11-05 16:33:13 +00:00
refactor(server-api): Make appearance provider name polymorphic and required for metadata
This commit is contained in:
parent
e20063a9ad
commit
7fdc546714
|
@ -41,7 +41,8 @@ abstract class ApiMap {
|
||||||
|
|
||||||
FutureOr<BaseOptions> get options;
|
FutureOr<BaseOptions> get options;
|
||||||
|
|
||||||
abstract final String rootAddress;
|
String get rootAddress;
|
||||||
|
|
||||||
abstract final bool hasLogger;
|
abstract final bool hasLogger;
|
||||||
abstract final bool isWithToken;
|
abstract final bool isWithToken;
|
||||||
|
|
||||||
|
|
|
@ -49,10 +49,13 @@ class DigitalOceanApi extends ServerProviderApi with VolumeProviderApi {
|
||||||
}
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
final String rootAddress = 'https://api.digitalocean.com/v2';
|
String get rootAddress => 'https://api.digitalocean.com/v2';
|
||||||
|
|
||||||
@override
|
@override
|
||||||
final String infectProviderName = 'digitalocean';
|
String get infectProviderName => 'digitalocean';
|
||||||
|
|
||||||
|
@override
|
||||||
|
String get appearanceProviderName => 'Digital Ocean';
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Future<bool> isApiTokenValid(final String token) async {
|
Future<bool> isApiTokenValid(final String token) async {
|
||||||
|
@ -452,7 +455,7 @@ class DigitalOceanApi extends ServerProviderApi with VolumeProviderApi {
|
||||||
final DateTime end,
|
final DateTime end,
|
||||||
) async {
|
) async {
|
||||||
ServerMetrics? metrics;
|
ServerMetrics? metrics;
|
||||||
return metrics!;
|
return metrics;
|
||||||
}
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
|
@ -498,7 +501,7 @@ class DigitalOceanApi extends ServerProviderApi with VolumeProviderApi {
|
||||||
ServerMetadataEntity(
|
ServerMetadataEntity(
|
||||||
type: MetadataType.other,
|
type: MetadataType.other,
|
||||||
name: 'server.provider'.tr(),
|
name: 'server.provider'.tr(),
|
||||||
value: 'Digital Ocean',
|
value: appearanceProviderName,
|
||||||
),
|
),
|
||||||
];
|
];
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
|
|
|
@ -50,10 +50,13 @@ class HetznerApi extends ServerProviderApi with VolumeProviderApi {
|
||||||
}
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
final String rootAddress = 'https://api.hetzner.cloud/v1';
|
String get rootAddress => 'https://api.hetzner.cloud/v1';
|
||||||
|
|
||||||
@override
|
@override
|
||||||
final String infectProviderName = 'hetzner';
|
String get infectProviderName => 'hetzner';
|
||||||
|
|
||||||
|
@override
|
||||||
|
String get appearanceProviderName => 'Hetzner';
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Future<bool> isApiTokenValid(final String token) async {
|
Future<bool> isApiTokenValid(final String token) async {
|
||||||
|
@ -349,12 +352,13 @@ class HetznerApi extends ServerProviderApi with VolumeProviderApi {
|
||||||
|
|
||||||
final String apiToken = StringGenerators.apiToken();
|
final String apiToken = StringGenerators.apiToken();
|
||||||
final String hostname = getHostnameFromDomain(domainName);
|
final String hostname = getHostnameFromDomain(domainName);
|
||||||
|
const String infectBranch = 'providers/hetzner';
|
||||||
|
|
||||||
final String base64Password =
|
final String base64Password =
|
||||||
base64.encode(utf8.encode(rootUser.password ?? 'PASS'));
|
base64.encode(utf8.encode(rootUser.password ?? 'PASS'));
|
||||||
|
|
||||||
final String userdataString =
|
final String userdataString =
|
||||||
"#cloud-config\nruncmd:\n- curl https://git.selfprivacy.org/SelfPrivacy/selfprivacy-nixos-infect/raw/branch/master/nixos-infect | 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 | 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";
|
||||||
|
|
||||||
ServerHostingDetails? serverDetails;
|
ServerHostingDetails? serverDetails;
|
||||||
DioError? hetznerError;
|
DioError? hetznerError;
|
||||||
|
@ -614,7 +618,7 @@ class HetznerApi extends ServerProviderApi with VolumeProviderApi {
|
||||||
ServerMetadataEntity(
|
ServerMetadataEntity(
|
||||||
type: MetadataType.other,
|
type: MetadataType.other,
|
||||||
name: 'server.provider'.tr(),
|
name: 'server.provider'.tr(),
|
||||||
value: 'Hetzner',
|
value: appearanceProviderName,
|
||||||
),
|
),
|
||||||
];
|
];
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
|
|
|
@ -48,5 +48,11 @@ abstract class ServerProviderApi extends ApiMap {
|
||||||
final DateTime end,
|
final DateTime end,
|
||||||
);
|
);
|
||||||
|
|
||||||
abstract final String infectProviderName;
|
/// Provider name key which lets infect understand what kind of installation
|
||||||
|
/// it requires, for example 'digitaloceal' for Digital Ocean
|
||||||
|
String get infectProviderName;
|
||||||
|
|
||||||
|
/// Actual provider name to render on information page for user,
|
||||||
|
/// for example 'Digital Ocean' for Digital Ocean
|
||||||
|
String get appearanceProviderName;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue