Turn VolumeApiProvider into a mixin
This commit is contained in:
parent
37b7e9f839
commit
9993b09e7f
|
@ -11,7 +11,6 @@ targets:
|
|||
import: package:selfprivacy/utils/scalars.dart
|
||||
clients:
|
||||
- graphql
|
||||
- graphql_flutter
|
||||
json_serializable:
|
||||
options:
|
||||
create_factory: true
|
||||
|
|
|
@ -4,14 +4,20 @@ import 'dart:io';
|
|||
import 'package:dio/dio.dart';
|
||||
import 'package:selfprivacy/config/get_it_config.dart';
|
||||
import 'package:selfprivacy/logic/api_maps/rest_maps/providers/volume_provider.dart';
|
||||
import 'package:selfprivacy/logic/api_maps/rest_maps/providers/provider.dart';
|
||||
import 'package:selfprivacy/logic/models/hive/server_domain.dart';
|
||||
import 'package:selfprivacy/logic/models/json/provider_server_info.dart';
|
||||
import 'package:selfprivacy/logic/models/json/hetzner_server_info.dart';
|
||||
import 'package:selfprivacy/logic/models/hive/server_details.dart';
|
||||
import 'package:selfprivacy/logic/models/hive/user.dart';
|
||||
import 'package:selfprivacy/logic/models/server_basic_info.dart';
|
||||
import 'package:selfprivacy/utils/password_generator.dart';
|
||||
|
||||
class HetznerApi extends VolumeProviderApi {
|
||||
HetznerApi({final super.hasLogger = false, final super.isWithToken = true});
|
||||
class HetznerApi extends ServerProviderApi with VolumeProviderApi {
|
||||
HetznerApi({final this.hasLogger = false, final this.isWithToken = true});
|
||||
@override
|
||||
bool hasLogger;
|
||||
@override
|
||||
bool isWithToken;
|
||||
|
||||
@override
|
||||
BaseOptions get options {
|
||||
|
@ -258,7 +264,7 @@ class HetznerApi extends VolumeProviderApi {
|
|||
return details;
|
||||
}
|
||||
|
||||
details = await createServerByVolume(
|
||||
details = await createServerWithVolume(
|
||||
dnsApiToken: dnsApiToken,
|
||||
rootUser: rootUser,
|
||||
domainName: domainName,
|
||||
|
@ -272,7 +278,7 @@ class HetznerApi extends VolumeProviderApi {
|
|||
return details;
|
||||
}
|
||||
|
||||
Future<ServerHostingDetails?> createServerByVolume({
|
||||
Future<ServerHostingDetails?> createServerWithVolume({
|
||||
required final String dnsApiToken,
|
||||
required final User rootUser,
|
||||
required final String domainName,
|
||||
|
@ -441,26 +447,46 @@ class HetznerApi extends VolumeProviderApi {
|
|||
return res.data;
|
||||
}
|
||||
|
||||
Future<ProviderServerInfo> getInfo() async {
|
||||
Future<HetznerServerInfo> getInfo() async {
|
||||
final ServerHostingDetails? hetznerServer =
|
||||
getIt<ApiConfigModel>().serverDetails;
|
||||
final Dio client = await getClient();
|
||||
final Response response = await client.get('/servers/${hetznerServer!.id}');
|
||||
close(client);
|
||||
|
||||
return ProviderServerInfo.fromJson(response.data!['server']);
|
||||
return HetznerServerInfo.fromJson(response.data!['server']);
|
||||
}
|
||||
|
||||
@override
|
||||
Future<List<ProviderServerInfo>> getServers() async {
|
||||
final Dio client = await getClient();
|
||||
final Response response = await client.get('/servers');
|
||||
close(client);
|
||||
Future<List<ServerBasicInfo>> getServers() async {
|
||||
List<ServerBasicInfo> servers = [];
|
||||
|
||||
return (response.data!['servers'] as List)
|
||||
// ignore: unnecessary_lambdas
|
||||
.map((final e) => ProviderServerInfo.fromJson(e))
|
||||
.toList();
|
||||
final Dio client = await getClient();
|
||||
try {
|
||||
final Response response = await client.get('/servers');
|
||||
servers = (response.data!['servers'] as List)
|
||||
.map(
|
||||
(final e) => HetznerServerInfo.fromJson(e),
|
||||
)
|
||||
.toList()
|
||||
.map(
|
||||
(final HetznerServerInfo server) => ServerBasicInfo(
|
||||
id: server.id,
|
||||
name: server.name,
|
||||
ip: server.publicNet.ipv4.ip,
|
||||
reverseDns: server.publicNet.ipv4.reverseDns,
|
||||
created: server.created,
|
||||
volumeId: server.volumes.isNotEmpty ? server.volumes[0] : 0,
|
||||
),
|
||||
)
|
||||
.toList();
|
||||
} catch (e) {
|
||||
print(e);
|
||||
} finally {
|
||||
close(client);
|
||||
}
|
||||
|
||||
return servers;
|
||||
}
|
||||
|
||||
@override
|
||||
|
|
|
@ -6,7 +6,7 @@ import 'package:selfprivacy/logic/api_maps/rest_maps/providers/volume_provider.d
|
|||
class HetznerApiFactory extends ProviderApiFactory
|
||||
with VolumeProviderApiFactory {
|
||||
@override
|
||||
ProviderApi getProvider({
|
||||
ServerProviderApi getProvider({
|
||||
final ProviderApiSettings settings = const ProviderApiSettings(),
|
||||
}) =>
|
||||
HetznerApi(
|
||||
|
|
|
@ -2,16 +2,10 @@ import 'package:selfprivacy/logic/api_maps/rest_maps/api_map.dart';
|
|||
import 'package:selfprivacy/logic/models/hive/server_details.dart';
|
||||
import 'package:selfprivacy/logic/models/hive/server_domain.dart';
|
||||
import 'package:selfprivacy/logic/models/hive/user.dart';
|
||||
import 'package:selfprivacy/logic/models/json/provider_server_info.dart';
|
||||
import 'package:selfprivacy/logic/models/server_basic_info.dart';
|
||||
|
||||
abstract class ProviderApi extends ApiMap {
|
||||
ProviderApi({this.hasLogger = false, this.isWithToken = true});
|
||||
@override
|
||||
bool hasLogger;
|
||||
@override
|
||||
bool isWithToken;
|
||||
|
||||
Future<List<ProviderServerInfo>> getServers();
|
||||
abstract class ServerProviderApi extends ApiMap {
|
||||
Future<List<ServerBasicInfo>> getServers();
|
||||
|
||||
Future<ServerHostingDetails> restart();
|
||||
Future<ServerHostingDetails> powerOn();
|
||||
|
|
|
@ -8,7 +8,7 @@ class ProviderApiSettings {
|
|||
}
|
||||
|
||||
abstract class ProviderApiFactory {
|
||||
ProviderApi getProvider({
|
||||
ServerProviderApi getProvider({
|
||||
final ProviderApiSettings settings = const ProviderApiSettings(),
|
||||
});
|
||||
}
|
||||
|
|
|
@ -1,12 +1,7 @@
|
|||
import 'package:selfprivacy/logic/api_maps/rest_maps/providers/provider.dart';
|
||||
import 'package:selfprivacy/logic/api_maps/rest_maps/api_map.dart';
|
||||
import 'package:selfprivacy/logic/models/hive/server_details.dart';
|
||||
|
||||
abstract class VolumeProviderApi extends ProviderApi {
|
||||
VolumeProviderApi({
|
||||
final super.hasLogger = false,
|
||||
final super.isWithToken = true,
|
||||
});
|
||||
|
||||
mixin VolumeProviderApi on ApiMap {
|
||||
Future<ServerVolume?> createVolume();
|
||||
Future<List<ServerVolume>> getVolumes({final String? status});
|
||||
Future<ServerVolume?> getVolume(final int id);
|
||||
|
|
|
@ -3,7 +3,7 @@ import 'package:equatable/equatable.dart';
|
|||
import 'package:selfprivacy/config/get_it_config.dart';
|
||||
import 'package:selfprivacy/logic/cubit/server_detailed_info/server_detailed_info_repository.dart';
|
||||
import 'package:selfprivacy/logic/models/json/auto_upgrade_settings.dart';
|
||||
import 'package:selfprivacy/logic/models/json/provider_server_info.dart';
|
||||
import 'package:selfprivacy/logic/models/json/hetzner_server_info.dart';
|
||||
import 'package:selfprivacy/logic/models/timezone_settings.dart';
|
||||
|
||||
part 'server_detailed_info_state.dart';
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
import 'package:selfprivacy/logic/api_maps/rest_maps/providers/hetzner/hetzner.dart';
|
||||
import 'package:selfprivacy/logic/api_maps/rest_maps/server.dart';
|
||||
import 'package:selfprivacy/logic/models/json/auto_upgrade_settings.dart';
|
||||
import 'package:selfprivacy/logic/models/json/provider_server_info.dart';
|
||||
import 'package:selfprivacy/logic/models/json/hetzner_server_info.dart';
|
||||
import 'package:selfprivacy/logic/models/timezone_settings.dart';
|
||||
|
||||
class ServerDetailsRepository {
|
||||
|
@ -24,7 +24,7 @@ class ServerDetailsRepositoryDto {
|
|||
required this.serverTimezone,
|
||||
required this.autoUpgradeSettings,
|
||||
});
|
||||
final ProviderServerInfo hetznerServerInfo;
|
||||
final HetznerServerInfo hetznerServerInfo;
|
||||
|
||||
final TimeZoneSettings serverTimezone;
|
||||
|
||||
|
|
|
@ -22,7 +22,7 @@ class Loaded extends ServerDetailsState {
|
|||
required this.autoUpgradeSettings,
|
||||
required this.checkTime,
|
||||
});
|
||||
final ProviderServerInfo serverInfo;
|
||||
final HetznerServerInfo serverInfo;
|
||||
|
||||
final TimeZoneSettings serverTimezone;
|
||||
|
||||
|
|
|
@ -50,29 +50,14 @@ class ServerInstallationCubit extends Cubit<ServerInstallationState> {
|
|||
}
|
||||
}
|
||||
|
||||
RegExp getProviderApiTokenValidation() {
|
||||
if (repository.providerApiFactory == null) {
|
||||
print(
|
||||
"validateProviderApiToken: Factory for API provider doesn't exist!",
|
||||
);
|
||||
return RegExp(r'');
|
||||
}
|
||||
RegExp getProviderApiTokenValidation() => repository.serverProviderApiFactory!
|
||||
.getProvider()
|
||||
.getApiTokenValidation();
|
||||
|
||||
return repository.providerApiFactory!.getProvider().getApiTokenValidation();
|
||||
}
|
||||
|
||||
Future<bool> isProviderApiTokenValid(final String providerToken) async {
|
||||
if (repository.providerApiFactory == null) {
|
||||
print(
|
||||
"validateProviderApiToken: Factory for API provider doesn't exist!",
|
||||
);
|
||||
return false;
|
||||
}
|
||||
|
||||
return repository.providerApiFactory!
|
||||
.getProvider(settings: const ProviderApiSettings(isWithToken: false))
|
||||
.isApiTokenValid(providerToken);
|
||||
}
|
||||
Future<bool> isProviderApiTokenValid(final String providerToken) async =>
|
||||
repository.serverProviderApiFactory!
|
||||
.getProvider(settings: const ProviderApiSettings(isWithToken: false))
|
||||
.isApiTokenValid(providerToken);
|
||||
|
||||
void setHetznerKey(final String hetznerKey) async {
|
||||
await repository.saveHetznerKey(hetznerKey);
|
||||
|
@ -143,16 +128,12 @@ class ServerInstallationCubit extends Cubit<ServerInstallationState> {
|
|||
);
|
||||
|
||||
Future<void> onSuccess(final ServerHostingDetails serverDetails) async {
|
||||
final bool dnsRecordsCreated = await repository.createDnsRecords(
|
||||
serverDetails.ip4,
|
||||
await repository.createDnsRecords(
|
||||
serverDetails,
|
||||
state.serverDomain!,
|
||||
onCancel: onCancel,
|
||||
);
|
||||
|
||||
if (dnsRecordsCreated) {
|
||||
repository.onCreationSuccess(serverDetails, state.serverDomain!);
|
||||
}
|
||||
|
||||
emit(
|
||||
(state as ServerInstallationNotFinished).copyWith(
|
||||
isLoading: false,
|
||||
|
|
|
@ -20,7 +20,6 @@ import 'package:selfprivacy/logic/models/hive/server_details.dart';
|
|||
import 'package:selfprivacy/logic/models/hive/server_domain.dart';
|
||||
import 'package:selfprivacy/logic/models/hive/user.dart';
|
||||
import 'package:selfprivacy/logic/models/json/device_token.dart';
|
||||
import 'package:selfprivacy/logic/models/json/provider_server_info.dart';
|
||||
import 'package:selfprivacy/logic/models/message.dart';
|
||||
import 'package:selfprivacy/logic/models/server_basic_info.dart';
|
||||
import 'package:selfprivacy/ui/components/action_button/action_button.dart';
|
||||
|
@ -41,7 +40,7 @@ class ServerAuthorizationException implements Exception {
|
|||
class ServerInstallationRepository {
|
||||
Box box = Hive.box(BNames.serverInstallationBox);
|
||||
Box<User> usersBox = Hive.box(BNames.usersBox);
|
||||
ProviderApiFactory? providerApiFactory =
|
||||
ProviderApiFactory? serverProviderApiFactory =
|
||||
ApiFactoryCreator.createProviderApiFactory(
|
||||
ServerProvider.hetzner, // HARDCODE FOR NOW!!!
|
||||
); // Remove when provider selection is implemented.
|
||||
|
@ -56,7 +55,7 @@ class ServerInstallationRepository {
|
|||
getIt<ApiConfigModel>().serverDetails;
|
||||
|
||||
if (serverDetails != null) {
|
||||
providerApiFactory =
|
||||
serverProviderApiFactory =
|
||||
ApiFactoryCreator.createProviderApiFactory(serverDetails.provider);
|
||||
}
|
||||
|
||||
|
@ -141,15 +140,10 @@ class ServerInstallationRepository {
|
|||
Future<ServerHostingDetails?> startServer(
|
||||
final ServerHostingDetails hetznerServer,
|
||||
) async {
|
||||
ServerHostingDetails? details;
|
||||
ServerHostingDetails? serverDetails;
|
||||
|
||||
if (providerApiFactory == null) {
|
||||
print("startServer: Factory for API provider doesn't exist!");
|
||||
return details;
|
||||
}
|
||||
|
||||
final ProviderApi api = providerApiFactory!.getProvider();
|
||||
final ServerHostingDetails serverDetails = await api.powerOn();
|
||||
final ServerProviderApi api = serverProviderApiFactory!.getProvider();
|
||||
serverDetails = await api.powerOn();
|
||||
|
||||
return serverDetails;
|
||||
}
|
||||
|
@ -226,12 +220,7 @@ class ServerInstallationRepository {
|
|||
required final Future<void> Function(ServerHostingDetails serverDetails)
|
||||
onSuccess,
|
||||
}) async {
|
||||
if (providerApiFactory == null) {
|
||||
print("createServer: Factory for API provider doesn't exist!");
|
||||
return;
|
||||
}
|
||||
|
||||
final ProviderApi api = providerApiFactory!.getProvider();
|
||||
final ServerProviderApi api = serverProviderApiFactory!.getProvider();
|
||||
try {
|
||||
final ServerHostingDetails? serverDetails = await api.createServer(
|
||||
dnsApiToken: cloudFlareKey,
|
||||
|
@ -291,42 +280,22 @@ class ServerInstallationRepository {
|
|||
}
|
||||
}
|
||||
|
||||
Future<void> onCreationSuccess(
|
||||
final ServerHostingDetails serverDetails,
|
||||
final ServerDomain domain,
|
||||
) async {
|
||||
if (providerApiFactory == null) {
|
||||
print("onCreationSuccess: Factory for API provider doesn't exist!");
|
||||
return;
|
||||
}
|
||||
final ProviderApi api = providerApiFactory!.getProvider();
|
||||
return api.createReverseDns(
|
||||
serverDetails: serverDetails,
|
||||
domain: domain,
|
||||
);
|
||||
}
|
||||
|
||||
Future<bool> createDnsRecords(
|
||||
final String ip4,
|
||||
final ServerHostingDetails serverDetails,
|
||||
final ServerDomain domain, {
|
||||
required final void Function() onCancel,
|
||||
}) async {
|
||||
final CloudflareApi cloudflareApi = CloudflareApi();
|
||||
|
||||
if (providerApiFactory == null) {
|
||||
print("createServer: Factory for API provider doesn't exist!");
|
||||
return false;
|
||||
}
|
||||
final ProviderApi api = providerApiFactory!.getProvider();
|
||||
final ServerProviderApi serverApi = serverProviderApiFactory!.getProvider();
|
||||
|
||||
await cloudflareApi.removeSimilarRecords(
|
||||
ip4: ip4,
|
||||
ip4: serverDetails.ip4,
|
||||
cloudFlareDomain: domain,
|
||||
);
|
||||
|
||||
try {
|
||||
await cloudflareApi.createMultipleDnsRecords(
|
||||
ip4: ip4,
|
||||
ip4: serverDetails.ip4,
|
||||
cloudFlareDomain: domain,
|
||||
);
|
||||
} on DioError catch (e) {
|
||||
|
@ -342,7 +311,7 @@ class ServerInstallationRepository {
|
|||
text: 'basis.delete'.tr(),
|
||||
isRed: true,
|
||||
onPressed: () async {
|
||||
await api.deleteServer(
|
||||
await serverApi.deleteServer(
|
||||
domainName: domain.domainName,
|
||||
);
|
||||
|
||||
|
@ -359,6 +328,11 @@ class ServerInstallationRepository {
|
|||
return false;
|
||||
}
|
||||
|
||||
await serverApi.createReverseDns(
|
||||
serverDetails: serverDetails,
|
||||
domain: domain,
|
||||
);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
@ -383,12 +357,12 @@ class ServerInstallationRepository {
|
|||
}
|
||||
|
||||
Future<ServerHostingDetails> restart() async {
|
||||
final ProviderApi api = providerApiFactory!.getProvider();
|
||||
final ServerProviderApi api = serverProviderApiFactory!.getProvider();
|
||||
return api.restart();
|
||||
}
|
||||
|
||||
Future<ServerHostingDetails> powerOn() async {
|
||||
final ProviderApi api = providerApiFactory!.getProvider();
|
||||
final ServerProviderApi api = serverProviderApiFactory!.getProvider();
|
||||
return api.powerOn();
|
||||
}
|
||||
|
||||
|
@ -625,27 +599,8 @@ class ServerInstallationRepository {
|
|||
}
|
||||
|
||||
Future<List<ServerBasicInfo>> getServersOnProviderAccount() async {
|
||||
if (providerApiFactory == null) {
|
||||
print(
|
||||
'getServersOnProviderAccount: '
|
||||
"Factory for API provider doesn't exist!",
|
||||
);
|
||||
return [];
|
||||
}
|
||||
final ProviderApi api = providerApiFactory!.getProvider();
|
||||
final List<ProviderServerInfo> servers = await api.getServers();
|
||||
return servers
|
||||
.map(
|
||||
(final ProviderServerInfo server) => ServerBasicInfo(
|
||||
id: server.id,
|
||||
name: server.name,
|
||||
ip: server.publicNet.ipv4.ip,
|
||||
reverseDns: server.publicNet.ipv4.reverseDns,
|
||||
created: server.created,
|
||||
volumeId: server.volumes.isNotEmpty ? server.volumes[0] : 0,
|
||||
),
|
||||
)
|
||||
.toList();
|
||||
final ServerProviderApi api = serverProviderApiFactory!.getProvider();
|
||||
return api.getServers();
|
||||
}
|
||||
|
||||
Future<void> saveServerDetails(
|
||||
|
@ -723,11 +678,7 @@ class ServerInstallationRepository {
|
|||
}
|
||||
|
||||
Future<void> deleteServer(final ServerDomain serverDomain) async {
|
||||
if (providerApiFactory == null) {
|
||||
print("deleteServer: Factory for API provider doesn't exist!");
|
||||
return;
|
||||
}
|
||||
final ProviderApi api = providerApiFactory!.getProvider();
|
||||
final ServerProviderApi api = serverProviderApiFactory!.getProvider();
|
||||
final CloudflareApi cloudFlare = CloudflareApi();
|
||||
|
||||
await api.deleteServer(
|
||||
|
|
|
@ -0,0 +1,115 @@
|
|||
import 'package:json_annotation/json_annotation.dart';
|
||||
|
||||
part 'hetzner_server_info.g.dart';
|
||||
|
||||
@JsonSerializable()
|
||||
class HetznerServerInfo {
|
||||
HetznerServerInfo(
|
||||
this.id,
|
||||
this.name,
|
||||
this.status,
|
||||
this.created,
|
||||
this.serverType,
|
||||
this.location,
|
||||
this.publicNet,
|
||||
this.volumes,
|
||||
);
|
||||
final int id;
|
||||
final String name;
|
||||
final ServerStatus status;
|
||||
final DateTime created;
|
||||
final List<int> volumes;
|
||||
|
||||
@JsonKey(name: 'server_type')
|
||||
final HetznerServerTypeInfo serverType;
|
||||
|
||||
@JsonKey(name: 'datacenter', fromJson: HetznerServerInfo.locationFromJson)
|
||||
final HetznerLocation location;
|
||||
|
||||
@JsonKey(name: 'public_net')
|
||||
final HetznerPublicNetInfo publicNet;
|
||||
|
||||
static HetznerLocation locationFromJson(final Map json) =>
|
||||
HetznerLocation.fromJson(json['location']);
|
||||
|
||||
static HetznerServerInfo fromJson(final Map<String, dynamic> json) =>
|
||||
_$HetznerServerInfoFromJson(json);
|
||||
}
|
||||
|
||||
@JsonSerializable()
|
||||
class HetznerPublicNetInfo {
|
||||
HetznerPublicNetInfo(this.ipv4);
|
||||
final HetznerIp4 ipv4;
|
||||
|
||||
static HetznerPublicNetInfo fromJson(final Map<String, dynamic> json) =>
|
||||
_$HetznerPublicNetInfoFromJson(json);
|
||||
}
|
||||
|
||||
@JsonSerializable()
|
||||
class HetznerIp4 {
|
||||
HetznerIp4(this.id, this.ip, this.blocked, this.reverseDns);
|
||||
final bool blocked;
|
||||
@JsonKey(name: 'dns_ptr')
|
||||
final String reverseDns;
|
||||
final int id;
|
||||
final String ip;
|
||||
|
||||
static HetznerIp4 fromJson(final Map<String, dynamic> json) =>
|
||||
_$HetznerIp4FromJson(json);
|
||||
}
|
||||
|
||||
enum ServerStatus {
|
||||
running,
|
||||
initializing,
|
||||
starting,
|
||||
stopping,
|
||||
off,
|
||||
deleting,
|
||||
migrating,
|
||||
rebuilding,
|
||||
unknown,
|
||||
}
|
||||
|
||||
@JsonSerializable()
|
||||
class HetznerServerTypeInfo {
|
||||
HetznerServerTypeInfo(this.cores, this.memory, this.disk, this.prices);
|
||||
final int cores;
|
||||
final num memory;
|
||||
final int disk;
|
||||
|
||||
final List<HetznerPriceInfo> prices;
|
||||
|
||||
static HetznerServerTypeInfo fromJson(final Map<String, dynamic> json) =>
|
||||
_$HetznerServerTypeInfoFromJson(json);
|
||||
}
|
||||
|
||||
@JsonSerializable()
|
||||
class HetznerPriceInfo {
|
||||
HetznerPriceInfo(this.hourly, this.monthly);
|
||||
|
||||
@JsonKey(name: 'price_hourly', fromJson: HetznerPriceInfo.getPrice)
|
||||
final double hourly;
|
||||
|
||||
@JsonKey(name: 'price_monthly', fromJson: HetznerPriceInfo.getPrice)
|
||||
final double monthly;
|
||||
|
||||
static HetznerPriceInfo fromJson(final Map<String, dynamic> json) =>
|
||||
_$HetznerPriceInfoFromJson(json);
|
||||
|
||||
static double getPrice(final Map json) =>
|
||||
double.parse(json['gross'] as String);
|
||||
}
|
||||
|
||||
@JsonSerializable()
|
||||
class HetznerLocation {
|
||||
HetznerLocation(this.country, this.city, this.description, this.zone);
|
||||
final String country;
|
||||
final String city;
|
||||
final String description;
|
||||
|
||||
@JsonKey(name: 'network_zone')
|
||||
final String zone;
|
||||
|
||||
static HetznerLocation fromJson(final Map<String, dynamic> json) =>
|
||||
_$HetznerLocationFromJson(json);
|
||||
}
|
|
@ -1,22 +1,21 @@
|
|||
// GENERATED CODE - DO NOT MODIFY BY HAND
|
||||
|
||||
part of 'provider_server_info.dart';
|
||||
part of 'hetzner_server_info.dart';
|
||||
|
||||
// **************************************************************************
|
||||
// JsonSerializableGenerator
|
||||
// **************************************************************************
|
||||
|
||||
ProviderServerInfo _$ProviderServerInfoFromJson(Map<String, dynamic> json) =>
|
||||
ProviderServerInfo(
|
||||
HetznerServerInfo _$HetznerServerInfoFromJson(Map<String, dynamic> json) =>
|
||||
HetznerServerInfo(
|
||||
json['id'] as int,
|
||||
json['name'] as String,
|
||||
$enumDecode(_$ServerStatusEnumMap, json['status']),
|
||||
DateTime.parse(json['created'] as String),
|
||||
ProviderServerTypeInfo.fromJson(
|
||||
HetznerServerTypeInfo.fromJson(
|
||||
json['server_type'] as Map<String, dynamic>),
|
||||
ProviderServerInfo.locationFromJson(json['datacenter'] as Map),
|
||||
ProviderPublicNetInfo.fromJson(
|
||||
json['public_net'] as Map<String, dynamic>),
|
||||
HetznerServerInfo.locationFromJson(json['datacenter'] as Map),
|
||||
HetznerPublicNetInfo.fromJson(json['public_net'] as Map<String, dynamic>),
|
||||
(json['volumes'] as List<dynamic>).map((e) => e as int).toList(),
|
||||
);
|
||||
|
||||
|
@ -32,38 +31,38 @@ const _$ServerStatusEnumMap = {
|
|||
ServerStatus.unknown: 'unknown',
|
||||
};
|
||||
|
||||
ProviderPublicNetInfo _$ProviderPublicNetInfoFromJson(
|
||||
HetznerPublicNetInfo _$HetznerPublicNetInfoFromJson(
|
||||
Map<String, dynamic> json) =>
|
||||
ProviderPublicNetInfo(
|
||||
ProviderIp4.fromJson(json['ipv4'] as Map<String, dynamic>),
|
||||
HetznerPublicNetInfo(
|
||||
HetznerIp4.fromJson(json['ipv4'] as Map<String, dynamic>),
|
||||
);
|
||||
|
||||
ProviderIp4 _$ProviderIp4FromJson(Map<String, dynamic> json) => ProviderIp4(
|
||||
HetznerIp4 _$HetznerIp4FromJson(Map<String, dynamic> json) => HetznerIp4(
|
||||
json['id'] as int,
|
||||
json['ip'] as String,
|
||||
json['blocked'] as bool,
|
||||
json['dns_ptr'] as String,
|
||||
);
|
||||
|
||||
ProviderServerTypeInfo _$ProviderServerTypeInfoFromJson(
|
||||
HetznerServerTypeInfo _$HetznerServerTypeInfoFromJson(
|
||||
Map<String, dynamic> json) =>
|
||||
ProviderServerTypeInfo(
|
||||
HetznerServerTypeInfo(
|
||||
json['cores'] as int,
|
||||
json['memory'] as num,
|
||||
json['disk'] as int,
|
||||
(json['prices'] as List<dynamic>)
|
||||
.map((e) => ProviderPriceInfo.fromJson(e as Map<String, dynamic>))
|
||||
.map((e) => HetznerPriceInfo.fromJson(e as Map<String, dynamic>))
|
||||
.toList(),
|
||||
);
|
||||
|
||||
ProviderPriceInfo _$ProviderPriceInfoFromJson(Map<String, dynamic> json) =>
|
||||
ProviderPriceInfo(
|
||||
ProviderPriceInfo.getPrice(json['price_hourly'] as Map),
|
||||
ProviderPriceInfo.getPrice(json['price_monthly'] as Map),
|
||||
HetznerPriceInfo _$HetznerPriceInfoFromJson(Map<String, dynamic> json) =>
|
||||
HetznerPriceInfo(
|
||||
HetznerPriceInfo.getPrice(json['price_hourly'] as Map),
|
||||
HetznerPriceInfo.getPrice(json['price_monthly'] as Map),
|
||||
);
|
||||
|
||||
ProviderLocation _$ProviderLocationFromJson(Map<String, dynamic> json) =>
|
||||
ProviderLocation(
|
||||
HetznerLocation _$HetznerLocationFromJson(Map<String, dynamic> json) =>
|
||||
HetznerLocation(
|
||||
json['country'] as String,
|
||||
json['city'] as String,
|
||||
json['description'] as String,
|
|
@ -1,115 +0,0 @@
|
|||
import 'package:json_annotation/json_annotation.dart';
|
||||
|
||||
part 'provider_server_info.g.dart';
|
||||
|
||||
@JsonSerializable()
|
||||
class ProviderServerInfo {
|
||||
ProviderServerInfo(
|
||||
this.id,
|
||||
this.name,
|
||||
this.status,
|
||||
this.created,
|
||||
this.serverType,
|
||||
this.location,
|
||||
this.publicNet,
|
||||
this.volumes,
|
||||
);
|
||||
final int id;
|
||||
final String name;
|
||||
final ServerStatus status;
|
||||
final DateTime created;
|
||||
final List<int> volumes;
|
||||
|
||||
@JsonKey(name: 'server_type')
|
||||
final ProviderServerTypeInfo serverType;
|
||||
|
||||
@JsonKey(name: 'datacenter', fromJson: ProviderServerInfo.locationFromJson)
|
||||
final ProviderLocation location;
|
||||
|
||||
@JsonKey(name: 'public_net')
|
||||
final ProviderPublicNetInfo publicNet;
|
||||
|
||||
static ProviderLocation locationFromJson(final Map json) =>
|
||||
ProviderLocation.fromJson(json['location']);
|
||||
|
||||
static ProviderServerInfo fromJson(final Map<String, dynamic> json) =>
|
||||
_$ProviderServerInfoFromJson(json);
|
||||
}
|
||||
|
||||
@JsonSerializable()
|
||||
class ProviderPublicNetInfo {
|
||||
ProviderPublicNetInfo(this.ipv4);
|
||||
final ProviderIp4 ipv4;
|
||||
|
||||
static ProviderPublicNetInfo fromJson(final Map<String, dynamic> json) =>
|
||||
_$ProviderPublicNetInfoFromJson(json);
|
||||
}
|
||||
|
||||
@JsonSerializable()
|
||||
class ProviderIp4 {
|
||||
ProviderIp4(this.id, this.ip, this.blocked, this.reverseDns);
|
||||
final bool blocked;
|
||||
@JsonKey(name: 'dns_ptr')
|
||||
final String reverseDns;
|
||||
final int id;
|
||||
final String ip;
|
||||
|
||||
static ProviderIp4 fromJson(final Map<String, dynamic> json) =>
|
||||
_$ProviderIp4FromJson(json);
|
||||
}
|
||||
|
||||
enum ServerStatus {
|
||||
running,
|
||||
initializing,
|
||||
starting,
|
||||
stopping,
|
||||
off,
|
||||
deleting,
|
||||
migrating,
|
||||
rebuilding,
|
||||
unknown,
|
||||
}
|
||||
|
||||
@JsonSerializable()
|
||||
class ProviderServerTypeInfo {
|
||||
ProviderServerTypeInfo(this.cores, this.memory, this.disk, this.prices);
|
||||
final int cores;
|
||||
final num memory;
|
||||
final int disk;
|
||||
|
||||
final List<ProviderPriceInfo> prices;
|
||||
|
||||
static ProviderServerTypeInfo fromJson(final Map<String, dynamic> json) =>
|
||||
_$ProviderServerTypeInfoFromJson(json);
|
||||
}
|
||||
|
||||
@JsonSerializable()
|
||||
class ProviderPriceInfo {
|
||||
ProviderPriceInfo(this.hourly, this.monthly);
|
||||
|
||||
@JsonKey(name: 'price_hourly', fromJson: ProviderPriceInfo.getPrice)
|
||||
final double hourly;
|
||||
|
||||
@JsonKey(name: 'price_monthly', fromJson: ProviderPriceInfo.getPrice)
|
||||
final double monthly;
|
||||
|
||||
static ProviderPriceInfo fromJson(final Map<String, dynamic> json) =>
|
||||
_$ProviderPriceInfoFromJson(json);
|
||||
|
||||
static double getPrice(final Map json) =>
|
||||
double.parse(json['gross'] as String);
|
||||
}
|
||||
|
||||
@JsonSerializable()
|
||||
class ProviderLocation {
|
||||
ProviderLocation(this.country, this.city, this.description, this.zone);
|
||||
final String country;
|
||||
final String city;
|
||||
final String description;
|
||||
|
||||
@JsonKey(name: 'network_zone')
|
||||
final String zone;
|
||||
|
||||
static ProviderLocation fromJson(final Map<String, dynamic> json) =>
|
||||
_$ProviderLocationFromJson(json);
|
||||
}
|
|
@ -7,7 +7,7 @@ import 'package:selfprivacy/logic/cubit/forms/factories/field_cubit_factory.dart
|
|||
import 'package:selfprivacy/logic/cubit/forms/setup/initializing/backblaze_form_cubit.dart';
|
||||
import 'package:selfprivacy/logic/cubit/forms/setup/initializing/cloudflare_form_cubit.dart';
|
||||
import 'package:selfprivacy/logic/cubit/forms/setup/initializing/domain_cloudflare.dart';
|
||||
import 'package:selfprivacy/logic/cubit/forms/setup/initializing/hetzner_form_cubit.dart';
|
||||
import 'package:selfprivacy/logic/cubit/forms/setup/initializing/provider_form_cubit.dart';
|
||||
import 'package:selfprivacy/logic/cubit/forms/setup/initializing/root_user_form_cubit.dart';
|
||||
import 'package:selfprivacy/ui/components/brand_bottom_sheet/brand_bottom_sheet.dart';
|
||||
import 'package:selfprivacy/ui/components/brand_button/brand_button.dart';
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
import 'package:easy_localization/easy_localization.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:selfprivacy/config/brand_theme.dart';
|
||||
import 'package:selfprivacy/logic/cubit/forms/setup/initializing/hetzner_form_cubit.dart';
|
||||
import 'package:selfprivacy/logic/cubit/forms/setup/initializing/provider_form_cubit.dart';
|
||||
import 'package:selfprivacy/ui/components/brand_bottom_sheet/brand_bottom_sheet.dart';
|
||||
import 'package:selfprivacy/ui/components/brand_button/filled_button.dart';
|
||||
import 'package:selfprivacy/ui/components/brand_button/brand_button.dart';
|
||||
|
|
|
@ -1,3 +1,5 @@
|
|||
// ignore_for_file: prefer_final_parameters, prefer_expression_function_bodies
|
||||
|
||||
String dateTimeToJson(DateTime data) {
|
||||
return data.toIso8601String();
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue