mirror of
https://git.selfprivacy.org/kherel/selfprivacy.org.app.git
synced 2025-01-23 17:26:35 +00:00
chore: Implement basic DigitalOceanServerType model
This commit is contained in:
parent
8d8e8cf265
commit
f6424200e2
|
@ -326,7 +326,7 @@ class DigitalOceanApi extends ServerProviderApi with VolumeProviderApi {
|
||||||
'image': 'ubuntu-20-04-x64',
|
'image': 'ubuntu-20-04-x64',
|
||||||
'user_data': '#cloud-config\n'
|
'user_data': '#cloud-config\n'
|
||||||
'runcmd:\n'
|
'runcmd:\n'
|
||||||
'- curl https://git.selfprivacy.org/SelfPrivacy/selfprivacy-nixos-infect/raw/branch/providers/digital-ocean/nixos-infect | '
|
'- curl https://git.selfprivacy.org/SelfPrivacy/selfprivacy-nixos-infect/raw/branch/testing/final-digital-ocean/nixos-infect | '
|
||||||
"PROVIDER=$infectProviderName DNS_PROVIDER_TYPE=$dnsProviderType STAGING_ACME='$stagingAcme' DOMAIN='$domainName' "
|
"PROVIDER=$infectProviderName DNS_PROVIDER_TYPE=$dnsProviderType STAGING_ACME='$stagingAcme' DOMAIN='$domainName' "
|
||||||
"LUSER='${rootUser.login}' ENCODED_PASSWORD='$base64Password' CF_TOKEN=$dnsApiToken DB_PASSWORD=$databasePassword "
|
"LUSER='${rootUser.login}' ENCODED_PASSWORD='$base64Password' CF_TOKEN=$dnsApiToken DB_PASSWORD=$databasePassword "
|
||||||
'API_TOKEN=$serverApiToken HOSTNAME=$hostName bash 2>&1 | tee /tmp/infect.log',
|
'API_TOKEN=$serverApiToken HOSTNAME=$hostName bash 2>&1 | tee /tmp/infect.log',
|
||||||
|
@ -537,15 +537,18 @@ class DigitalOceanApi extends ServerProviderApi with VolumeProviderApi {
|
||||||
return GenericResult(data: locations, success: true);
|
return GenericResult(data: locations, success: true);
|
||||||
}
|
}
|
||||||
|
|
||||||
Future<GenericResult<List>> getAvailableServerTypes() async {
|
Future<GenericResult<List<DigitalOceanServerType>>>
|
||||||
List types = [];
|
getAvailableServerTypes() async {
|
||||||
|
final List<DigitalOceanServerType> types = [];
|
||||||
|
|
||||||
final Dio client = await getClient();
|
final Dio client = await getClient();
|
||||||
try {
|
try {
|
||||||
final Response response = await client.get(
|
final Response response = await client.get(
|
||||||
'/sizes',
|
'/sizes',
|
||||||
);
|
);
|
||||||
types = response.data!['sizes'];
|
for (final size in response.data!['sizes']) {
|
||||||
|
types.add(DigitalOceanServerType.fromJson(size));
|
||||||
|
}
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
print(e);
|
print(e);
|
||||||
return GenericResult(
|
return GenericResult(
|
||||||
|
|
|
@ -372,7 +372,7 @@ class HetznerApi extends ServerProviderApi with VolumeProviderApi {
|
||||||
'networks': [],
|
'networks': [],
|
||||||
'user_data': '#cloud-config\n'
|
'user_data': '#cloud-config\n'
|
||||||
'runcmd:\n'
|
'runcmd:\n'
|
||||||
'- curl https://git.selfprivacy.org/SelfPrivacy/selfprivacy-nixos-infect/raw/branch/providers/hetzner/nixos-infect | '
|
'- curl https://git.selfprivacy.org/SelfPrivacy/selfprivacy-nixos-infect/raw/branch/testing/final-hetzner/nixos-infect | '
|
||||||
"STAGING_ACME='$stagingAcme' PROVIDER=$infectProviderName DNS_PROVIDER_TYPE=$dnsProviderType "
|
"STAGING_ACME='$stagingAcme' PROVIDER=$infectProviderName DNS_PROVIDER_TYPE=$dnsProviderType "
|
||||||
"NIX_CHANNEL=nixos-21.05 DOMAIN='$domainName' LUSER='${rootUser.login}' ENCODED_PASSWORD='$base64Password' "
|
"NIX_CHANNEL=nixos-21.05 DOMAIN='$domainName' LUSER='${rootUser.login}' ENCODED_PASSWORD='$base64Password' "
|
||||||
'CF_TOKEN=$dnsApiToken DB_PASSWORD=$databasePassword API_TOKEN=$serverApiToken HOSTNAME=$hostName bash 2>&1 | '
|
'CF_TOKEN=$dnsApiToken DB_PASSWORD=$databasePassword API_TOKEN=$serverApiToken HOSTNAME=$hostName bash 2>&1 | '
|
||||||
|
|
|
@ -37,3 +37,29 @@ class DigitalOceanLocation {
|
||||||
static DigitalOceanLocation fromJson(final Map<String, dynamic> json) =>
|
static DigitalOceanLocation fromJson(final Map<String, dynamic> json) =>
|
||||||
_$DigitalOceanLocationFromJson(json);
|
_$DigitalOceanLocationFromJson(json);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@JsonSerializable()
|
||||||
|
class DigitalOceanServerType {
|
||||||
|
DigitalOceanServerType(
|
||||||
|
this.regions,
|
||||||
|
this.memory,
|
||||||
|
this.description,
|
||||||
|
this.disk,
|
||||||
|
this.priceMonthly,
|
||||||
|
this.slug,
|
||||||
|
this.vcpus,
|
||||||
|
);
|
||||||
|
|
||||||
|
final List<String> regions;
|
||||||
|
final double memory;
|
||||||
|
final String slug;
|
||||||
|
final String description;
|
||||||
|
final int vcpus;
|
||||||
|
final int disk;
|
||||||
|
|
||||||
|
@JsonKey(name: 'price_monthly')
|
||||||
|
final double priceMonthly;
|
||||||
|
|
||||||
|
static DigitalOceanServerType fromJson(final Map<String, dynamic> json) =>
|
||||||
|
_$DigitalOceanServerTypeFromJson(json);
|
||||||
|
}
|
||||||
|
|
|
@ -35,3 +35,27 @@ Map<String, dynamic> _$DigitalOceanLocationToJson(
|
||||||
'slug': instance.slug,
|
'slug': instance.slug,
|
||||||
'name': instance.name,
|
'name': instance.name,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
DigitalOceanServerType _$DigitalOceanServerTypeFromJson(
|
||||||
|
Map<String, dynamic> json) =>
|
||||||
|
DigitalOceanServerType(
|
||||||
|
(json['regions'] as List<dynamic>).map((e) => e as String).toList(),
|
||||||
|
(json['memory'] as num).toDouble(),
|
||||||
|
json['description'] as String,
|
||||||
|
json['disk'] as int,
|
||||||
|
(json['price_monthly'] as num).toDouble(),
|
||||||
|
json['slug'] as String,
|
||||||
|
json['vcpus'] as int,
|
||||||
|
);
|
||||||
|
|
||||||
|
Map<String, dynamic> _$DigitalOceanServerTypeToJson(
|
||||||
|
DigitalOceanServerType instance) =>
|
||||||
|
<String, dynamic>{
|
||||||
|
'regions': instance.regions,
|
||||||
|
'memory': instance.memory,
|
||||||
|
'slug': instance.slug,
|
||||||
|
'description': instance.description,
|
||||||
|
'vcpus': instance.vcpus,
|
||||||
|
'disk': instance.disk,
|
||||||
|
'price_monthly': instance.priceMonthly,
|
||||||
|
};
|
||||||
|
|
|
@ -291,20 +291,19 @@ class DigitalOceanServerProvider extends ServerProvider {
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
final List rawSizes = result.data;
|
final List<DigitalOceanServerType> rawSizes = result.data;
|
||||||
for (final rawSize in rawSizes) {
|
for (final rawSize in rawSizes) {
|
||||||
for (final rawRegion in rawSize['regions']) {
|
for (final rawRegion in rawSize.regions) {
|
||||||
final ramMb = rawSize['memory'].toDouble();
|
if (rawRegion == location.identifier && rawSize.memory > 1024) {
|
||||||
if (rawRegion.toString() == location.identifier && ramMb > 1024) {
|
|
||||||
types.add(
|
types.add(
|
||||||
ServerType(
|
ServerType(
|
||||||
title: rawSize['description'],
|
title: rawSize.description,
|
||||||
identifier: rawSize['slug'],
|
identifier: rawSize.slug,
|
||||||
ram: ramMb / 1024,
|
ram: rawSize.memory / 1024,
|
||||||
cores: rawSize['vcpus'],
|
cores: rawSize.vcpus,
|
||||||
disk: DiskSize(byte: rawSize['disk'] * 1024 * 1024 * 1024),
|
disk: DiskSize(byte: rawSize.disk * 1024 * 1024 * 1024),
|
||||||
price: Price(
|
price: Price(
|
||||||
value: rawSize['price_monthly'],
|
value: rawSize.priceMonthly,
|
||||||
currency: 'USD',
|
currency: 'USD',
|
||||||
),
|
),
|
||||||
location: location,
|
location: location,
|
||||||
|
|
Loading…
Reference in a new issue