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