mirror of
https://git.selfprivacy.org/kherel/selfprivacy.org.app.git
synced 2025-01-23 09:16:54 +00:00
feat: Implement general server provider and its factory
This commit is contained in:
parent
818de37acd
commit
a270f3dfbb
|
@ -69,9 +69,9 @@ class ServerApi extends ApiMap
|
|||
return apiVersion;
|
||||
}
|
||||
|
||||
Future<ServerProvider> getServerProviderType() async {
|
||||
Future<ServerProviderType> getServerProviderType() async {
|
||||
QueryResult<Query$SystemServerProvider> response;
|
||||
ServerProvider providerType = ServerProvider.unknown;
|
||||
ServerProviderType providerType = ServerProviderType.unknown;
|
||||
|
||||
try {
|
||||
final GraphQLClient client = await getClient();
|
||||
|
@ -79,7 +79,7 @@ class ServerApi extends ApiMap
|
|||
if (response.hasException) {
|
||||
print(response.exception.toString());
|
||||
}
|
||||
providerType = ServerProvider.fromGraphQL(
|
||||
providerType = ServerProviderType.fromGraphQL(
|
||||
response.parsedData!.system.provider.provider,
|
||||
);
|
||||
} catch (e) {
|
||||
|
@ -88,9 +88,9 @@ class ServerApi extends ApiMap
|
|||
return providerType;
|
||||
}
|
||||
|
||||
Future<DnsProvider> getDnsProviderType() async {
|
||||
Future<DnsProviderType> getDnsProviderType() async {
|
||||
QueryResult<Query$SystemDnsProvider> response;
|
||||
DnsProvider providerType = DnsProvider.unknown;
|
||||
DnsProviderType providerType = DnsProviderType.unknown;
|
||||
|
||||
try {
|
||||
final GraphQLClient client = await getClient();
|
||||
|
@ -98,7 +98,7 @@ class ServerApi extends ApiMap
|
|||
if (response.hasException) {
|
||||
print(response.exception.toString());
|
||||
}
|
||||
providerType = DnsProvider.fromGraphQL(
|
||||
providerType = DnsProviderType.fromGraphQL(
|
||||
response.parsedData!.system.domainInfo.provider,
|
||||
);
|
||||
} catch (e) {
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
import 'package:selfprivacy/logic/api_maps/rest_maps/api_factory_creator.dart';
|
||||
import 'package:selfprivacy/logic/api_maps/rest_maps/api_factory_settings.dart';
|
||||
import 'package:selfprivacy/logic/providers/provider_settings.dart';
|
||||
import 'package:selfprivacy/logic/api_maps/rest_maps/dns_providers/dns_provider_factory.dart';
|
||||
import 'package:selfprivacy/logic/api_maps/rest_maps/server_providers/server_provider_factory.dart';
|
||||
|
||||
|
@ -12,21 +12,21 @@ class ApiController {
|
|||
_serverProviderApiFactory;
|
||||
|
||||
static void initVolumeProviderApiFactory(
|
||||
final ServerProviderApiFactorySettings settings,
|
||||
final ServerProviderSettings settings,
|
||||
) {
|
||||
_volumeProviderApiFactory =
|
||||
VolumeApiFactoryCreator.createVolumeProviderApiFactory(settings);
|
||||
}
|
||||
|
||||
static void initDnsProviderApiFactory(
|
||||
final DnsProviderApiFactorySettings settings,
|
||||
final DnsProviderFactorySettings settings,
|
||||
) {
|
||||
_dnsProviderApiFactory =
|
||||
ApiFactoryCreator.createDnsProviderApiFactory(settings);
|
||||
}
|
||||
|
||||
static void initServerProviderApiFactory(
|
||||
final ServerProviderApiFactorySettings settings,
|
||||
final ServerProviderSettings settings,
|
||||
) {
|
||||
_serverProviderApiFactory =
|
||||
ApiFactoryCreator.createServerProviderApiFactory(settings);
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
import 'package:selfprivacy/logic/api_maps/rest_maps/api_factory_settings.dart';
|
||||
import 'package:selfprivacy/logic/providers/provider_settings.dart';
|
||||
import 'package:selfprivacy/logic/api_maps/rest_maps/dns_providers/cloudflare/cloudflare_factory.dart';
|
||||
import 'package:selfprivacy/logic/api_maps/rest_maps/dns_providers/digital_ocean_dns/digital_ocean_dns_factory.dart';
|
||||
import 'package:selfprivacy/logic/api_maps/rest_maps/dns_providers/dns_provider_factory.dart';
|
||||
|
@ -15,27 +15,27 @@ class UnknownApiProviderException implements Exception {
|
|||
|
||||
class ApiFactoryCreator {
|
||||
static ServerProviderApiFactory createServerProviderApiFactory(
|
||||
final ServerProviderApiFactorySettings settings,
|
||||
final ServerProviderSettings settings,
|
||||
) {
|
||||
switch (settings.provider) {
|
||||
case ServerProvider.hetzner:
|
||||
case ServerProviderType.hetzner:
|
||||
return HetznerApiFactory(region: settings.location);
|
||||
case ServerProvider.digitalOcean:
|
||||
case ServerProviderType.digitalOcean:
|
||||
return DigitalOceanApiFactory(region: settings.location);
|
||||
case ServerProvider.unknown:
|
||||
case ServerProviderType.unknown:
|
||||
throw UnknownApiProviderException('Unknown server provider');
|
||||
}
|
||||
}
|
||||
|
||||
static DnsProviderApiFactory createDnsProviderApiFactory(
|
||||
final DnsProviderApiFactorySettings settings,
|
||||
final DnsProviderFactorySettings settings,
|
||||
) {
|
||||
switch (settings.provider) {
|
||||
case DnsProvider.cloudflare:
|
||||
case DnsProviderType.cloudflare:
|
||||
return CloudflareApiFactory();
|
||||
case DnsProvider.digitalOcean:
|
||||
case DnsProviderType.digitalOcean:
|
||||
return DigitalOceanDnsApiFactory();
|
||||
case DnsProvider.unknown:
|
||||
case DnsProviderType.unknown:
|
||||
throw UnknownApiProviderException('Unknown DNS provider');
|
||||
}
|
||||
}
|
||||
|
@ -43,14 +43,14 @@ class ApiFactoryCreator {
|
|||
|
||||
class VolumeApiFactoryCreator {
|
||||
static VolumeProviderApiFactory createVolumeProviderApiFactory(
|
||||
final ServerProviderApiFactorySettings settings,
|
||||
final ServerProviderSettings settings,
|
||||
) {
|
||||
switch (settings.provider) {
|
||||
case ServerProvider.hetzner:
|
||||
case ServerProviderType.hetzner:
|
||||
return HetznerApiFactory();
|
||||
case ServerProvider.digitalOcean:
|
||||
case ServerProviderType.digitalOcean:
|
||||
return DigitalOceanApiFactory();
|
||||
case ServerProvider.unknown:
|
||||
case ServerProviderType.unknown:
|
||||
throw UnknownApiProviderException('Unknown volume provider');
|
||||
}
|
||||
}
|
||||
|
|
|
@ -332,7 +332,7 @@ class DigitalOceanApi extends ServerProviderApi with VolumeProviderApi {
|
|||
required final User rootUser,
|
||||
required final String domainName,
|
||||
required final String serverType,
|
||||
required final DnsProvider dnsProvider,
|
||||
required final DnsProviderType dnsProvider,
|
||||
}) async {
|
||||
ServerHostingDetails? serverDetails;
|
||||
|
||||
|
@ -394,7 +394,7 @@ class DigitalOceanApi extends ServerProviderApi with VolumeProviderApi {
|
|||
createTime: DateTime.now(),
|
||||
volume: newVolume,
|
||||
apiToken: apiToken,
|
||||
provider: ServerProvider.digitalOcean,
|
||||
provider: ServerProviderType.digitalOcean,
|
||||
);
|
||||
}
|
||||
} catch (e) {
|
||||
|
|
|
@ -356,7 +356,7 @@ class HetznerApi extends ServerProviderApi with VolumeProviderApi {
|
|||
required final User rootUser,
|
||||
required final String domainName,
|
||||
required final String serverType,
|
||||
required final DnsProvider dnsProvider,
|
||||
required final DnsProviderType dnsProvider,
|
||||
}) async {
|
||||
final APIGenericResult<ServerVolume?> newVolumeResponse =
|
||||
await createVolume();
|
||||
|
@ -385,7 +385,7 @@ class HetznerApi extends ServerProviderApi with VolumeProviderApi {
|
|||
required final String domainName,
|
||||
required final ServerVolume volume,
|
||||
required final String serverType,
|
||||
required final DnsProvider dnsProvider,
|
||||
required final DnsProviderType dnsProvider,
|
||||
}) async {
|
||||
final Dio client = await getClient();
|
||||
|
||||
|
@ -434,7 +434,7 @@ class HetznerApi extends ServerProviderApi with VolumeProviderApi {
|
|||
createTime: DateTime.now(),
|
||||
volume: volume,
|
||||
apiToken: apiToken,
|
||||
provider: ServerProvider.hetzner,
|
||||
provider: ServerProviderType.hetzner,
|
||||
);
|
||||
success = true;
|
||||
} on DioError catch (e) {
|
||||
|
|
|
@ -39,7 +39,7 @@ abstract class ServerProviderApi extends ApiMap {
|
|||
required final User rootUser,
|
||||
required final String domainName,
|
||||
required final String serverType,
|
||||
required final DnsProvider dnsProvider,
|
||||
required final DnsProviderType dnsProvider,
|
||||
});
|
||||
Future<APIGenericResult<void>> createReverseDns({
|
||||
required final ServerHostingDetails serverDetails,
|
||||
|
@ -55,13 +55,13 @@ abstract class ServerProviderApi extends ApiMap {
|
|||
final DateTime end,
|
||||
);
|
||||
|
||||
String dnsProviderToInfectName(final DnsProvider dnsProvider) {
|
||||
String dnsProviderToInfectName(final DnsProviderType dnsProvider) {
|
||||
String dnsProviderType;
|
||||
switch (dnsProvider) {
|
||||
case DnsProvider.digitalOcean:
|
||||
case DnsProviderType.digitalOcean:
|
||||
dnsProviderType = 'DIGITALOCEAN';
|
||||
break;
|
||||
case DnsProvider.cloudflare:
|
||||
case DnsProviderType.cloudflare:
|
||||
default:
|
||||
dnsProviderType = 'CLOUDFLARE';
|
||||
break;
|
||||
|
|
|
@ -39,7 +39,7 @@ class DomainSetupCubit extends Cubit<DomainSetupState> {
|
|||
final ServerDomain domain = ServerDomain(
|
||||
domainName: domainName,
|
||||
zoneId: zoneId,
|
||||
provider: DnsProvider.cloudflare,
|
||||
provider: DnsProviderType.cloudflare,
|
||||
);
|
||||
|
||||
serverInstallationCubit.setDomain(domain);
|
||||
|
|
|
@ -6,8 +6,9 @@ import 'package:equatable/equatable.dart';
|
|||
import 'package:selfprivacy/config/get_it_config.dart';
|
||||
import 'package:selfprivacy/logic/api_maps/graphql_maps/server_api/server_api.dart';
|
||||
import 'package:selfprivacy/logic/api_maps/rest_maps/api_controller.dart';
|
||||
import 'package:selfprivacy/logic/api_maps/rest_maps/api_factory_settings.dart';
|
||||
import 'package:selfprivacy/logic/providers/provider_settings.dart';
|
||||
import 'package:selfprivacy/logic/api_maps/rest_maps/dns_providers/dns_provider_api_settings.dart';
|
||||
import 'package:selfprivacy/logic/providers/providers_controller.dart';
|
||||
import 'package:selfprivacy/logic/api_maps/rest_maps/server_providers/server_provider.dart';
|
||||
import 'package:selfprivacy/logic/api_maps/rest_maps/server_providers/server_provider_api_settings.dart';
|
||||
import 'package:selfprivacy/logic/models/hive/backblaze_credential.dart';
|
||||
|
@ -57,45 +58,29 @@ class ServerInstallationCubit extends Cubit<ServerInstallationState> {
|
|||
}
|
||||
}
|
||||
|
||||
void setServerProviderType(final ServerProvider providerType) async {
|
||||
void setServerProviderType(final ServerProviderType providerType) async {
|
||||
await repository.saveServerProviderType(providerType);
|
||||
ApiController.initServerProviderApiFactory(
|
||||
ServerProviderApiFactorySettings(
|
||||
provider: providerType,
|
||||
),
|
||||
ProvidersController.initServerProvider(
|
||||
ServerProviderSettings(provider: providerType),
|
||||
);
|
||||
}
|
||||
|
||||
void setDnsProviderType(final DnsProvider providerType) async {
|
||||
void setDnsProviderType(final DnsProviderType providerType) async {
|
||||
await repository.saveDnsProviderType(providerType);
|
||||
ApiController.initDnsProviderApiFactory(
|
||||
DnsProviderApiFactorySettings(
|
||||
DnsProviderFactorySettings(
|
||||
provider: providerType,
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
ProviderApiTokenValidation serverProviderApiTokenValidation() =>
|
||||
ApiController.currentServerProviderApiFactory!
|
||||
.getServerProvider()
|
||||
.getApiTokenValidation();
|
||||
|
||||
RegExp getDnsProviderApiTokenValidation() =>
|
||||
ApiController.currentDnsProviderApiFactory!
|
||||
.getDnsProvider()
|
||||
.getApiTokenValidation();
|
||||
|
||||
Future<bool?> isServerProviderApiTokenValid(
|
||||
final String providerToken,
|
||||
) async {
|
||||
final APIGenericResult<bool> apiResponse =
|
||||
await ApiController.currentServerProviderApiFactory!
|
||||
.getServerProvider(
|
||||
settings: const ServerProviderApiSettings(
|
||||
isWithToken: false,
|
||||
),
|
||||
)
|
||||
.isApiTokenValid(providerToken);
|
||||
await ProvidersController.currentServerProvider!.isApiTokenValid(
|
||||
providerToken,
|
||||
);
|
||||
|
||||
if (!apiResponse.success) {
|
||||
getIt<NavigationService>().showSnackBar(
|
||||
|
@ -191,7 +176,7 @@ class ServerInstallationCubit extends Cubit<ServerInstallationState> {
|
|||
await repository.saveServerType(serverType);
|
||||
|
||||
ApiController.initServerProviderApiFactory(
|
||||
ServerProviderApiFactorySettings(
|
||||
ServerProviderSettings(
|
||||
provider: getIt<ApiConfigModel>().serverProvider!,
|
||||
location: serverType.location.identifier,
|
||||
),
|
||||
|
@ -200,7 +185,7 @@ class ServerInstallationCubit extends Cubit<ServerInstallationState> {
|
|||
// All server providers support volumes for now,
|
||||
// so it's safe to initialize.
|
||||
ApiController.initVolumeProviderApiFactory(
|
||||
ServerProviderApiFactorySettings(
|
||||
ServerProviderSettings(
|
||||
provider: getIt<ApiConfigModel>().serverProvider!,
|
||||
location: serverType.location.identifier,
|
||||
),
|
||||
|
@ -485,7 +470,7 @@ class ServerInstallationCubit extends Cubit<ServerInstallationState> {
|
|||
void submitDomainForAccessRecovery(final String domain) async {
|
||||
final ServerDomain serverDomain = ServerDomain(
|
||||
domainName: domain,
|
||||
provider: DnsProvider.unknown,
|
||||
provider: DnsProviderType.unknown,
|
||||
zoneId: '',
|
||||
);
|
||||
final ServerRecoveryCapabilities recoveryCapabilities =
|
||||
|
@ -537,20 +522,20 @@ class ServerInstallationCubit extends Cubit<ServerInstallationState> {
|
|||
token,
|
||||
dataState.recoveryCapabilities,
|
||||
);
|
||||
final ServerProvider serverProvider = await ServerApi(
|
||||
final ServerProviderType serverProvider = await ServerApi(
|
||||
customToken: serverDetails.apiToken,
|
||||
isWithToken: true,
|
||||
).getServerProviderType();
|
||||
final DnsProvider dnsProvider = await ServerApi(
|
||||
final DnsProviderType dnsProvider = await ServerApi(
|
||||
customToken: serverDetails.apiToken,
|
||||
isWithToken: true,
|
||||
).getDnsProviderType();
|
||||
if (serverProvider == ServerProvider.unknown) {
|
||||
if (serverProvider == ServerProviderType.unknown) {
|
||||
getIt<NavigationService>()
|
||||
.showSnackBar('recovering.generic_error'.tr());
|
||||
return;
|
||||
}
|
||||
if (dnsProvider == DnsProvider.unknown) {
|
||||
if (dnsProvider == DnsProviderType.unknown) {
|
||||
getIt<NavigationService>()
|
||||
.showSnackBar('recovering.generic_error'.tr());
|
||||
return;
|
||||
|
@ -684,7 +669,7 @@ class ServerInstallationCubit extends Cubit<ServerInstallationState> {
|
|||
linuxDevice: '',
|
||||
),
|
||||
apiToken: dataState.serverDetails!.apiToken,
|
||||
provider: ServerProvider.hetzner,
|
||||
provider: ServerProviderType.hetzner,
|
||||
);
|
||||
await repository.saveDomain(serverDomain);
|
||||
await repository.saveServerDetails(serverDetails);
|
||||
|
@ -714,7 +699,7 @@ class ServerInstallationCubit extends Cubit<ServerInstallationState> {
|
|||
ServerDomain(
|
||||
domainName: serverDomain.domainName,
|
||||
zoneId: zoneId,
|
||||
provider: DnsProvider.cloudflare,
|
||||
provider: DnsProviderType.cloudflare,
|
||||
),
|
||||
);
|
||||
await repository.setDnsApiToken(token);
|
||||
|
@ -723,7 +708,7 @@ class ServerInstallationCubit extends Cubit<ServerInstallationState> {
|
|||
serverDomain: ServerDomain(
|
||||
domainName: serverDomain.domainName,
|
||||
zoneId: zoneId,
|
||||
provider: DnsProvider.cloudflare,
|
||||
provider: DnsProviderType.cloudflare,
|
||||
),
|
||||
dnsApiToken: token,
|
||||
currentStep: RecoveryStep.backblazeToken,
|
||||
|
|
|
@ -10,7 +10,7 @@ import 'package:pub_semver/pub_semver.dart';
|
|||
import 'package:selfprivacy/config/get_it_config.dart';
|
||||
import 'package:selfprivacy/config/hive_config.dart';
|
||||
import 'package:selfprivacy/logic/api_maps/rest_maps/api_controller.dart';
|
||||
import 'package:selfprivacy/logic/api_maps/rest_maps/api_factory_settings.dart';
|
||||
import 'package:selfprivacy/logic/providers/provider_settings.dart';
|
||||
import 'package:selfprivacy/logic/api_maps/rest_maps/dns_providers/dns_provider.dart';
|
||||
import 'package:selfprivacy/logic/api_maps/rest_maps/dns_providers/dns_provider_api_settings.dart';
|
||||
import 'package:selfprivacy/logic/api_maps/graphql_maps/server_api/server_api.dart';
|
||||
|
@ -48,8 +48,8 @@ class ServerInstallationRepository {
|
|||
final String? cloudflareToken = getIt<ApiConfigModel>().dnsProviderKey;
|
||||
final String? serverTypeIdentificator = getIt<ApiConfigModel>().serverType;
|
||||
final ServerDomain? serverDomain = getIt<ApiConfigModel>().serverDomain;
|
||||
final DnsProvider? dnsProvider = getIt<ApiConfigModel>().dnsProvider;
|
||||
final ServerProvider? serverProvider =
|
||||
final DnsProviderType? dnsProvider = getIt<ApiConfigModel>().dnsProvider;
|
||||
final ServerProviderType? serverProvider =
|
||||
getIt<ApiConfigModel>().serverProvider;
|
||||
final BackblazeCredential? backblazeCredential =
|
||||
getIt<ApiConfigModel>().backblazeCredential;
|
||||
|
@ -58,9 +58,9 @@ class ServerInstallationRepository {
|
|||
|
||||
if (serverProvider != null ||
|
||||
(serverDetails != null &&
|
||||
serverDetails.provider != ServerProvider.unknown)) {
|
||||
serverDetails.provider != ServerProviderType.unknown)) {
|
||||
ApiController.initServerProviderApiFactory(
|
||||
ServerProviderApiFactorySettings(
|
||||
ServerProviderSettings(
|
||||
provider: serverProvider ?? serverDetails!.provider,
|
||||
location: location,
|
||||
),
|
||||
|
@ -69,7 +69,7 @@ class ServerInstallationRepository {
|
|||
// All current providers support volumes
|
||||
// so it's safe to hardcode for now
|
||||
ApiController.initVolumeProviderApiFactory(
|
||||
ServerProviderApiFactorySettings(
|
||||
ServerProviderSettings(
|
||||
provider: serverProvider ?? serverDetails!.provider,
|
||||
location: location,
|
||||
),
|
||||
|
@ -78,9 +78,9 @@ class ServerInstallationRepository {
|
|||
|
||||
if (dnsProvider != null ||
|
||||
(serverDomain != null &&
|
||||
serverDomain.provider != ServerProvider.unknown)) {
|
||||
serverDomain.provider != ServerProviderType.unknown)) {
|
||||
ApiController.initDnsProviderApiFactory(
|
||||
DnsProviderApiFactorySettings(
|
||||
DnsProviderFactorySettings(
|
||||
provider: dnsProvider ?? serverDomain!.provider,
|
||||
),
|
||||
);
|
||||
|
@ -147,8 +147,8 @@ class ServerInstallationRepository {
|
|||
) {
|
||||
if (serverDetails != null) {
|
||||
if (serverProviderToken != null) {
|
||||
if (serverDetails.provider != ServerProvider.unknown) {
|
||||
if (serverDomain.provider != DnsProvider.unknown) {
|
||||
if (serverDetails.provider != ServerProviderType.unknown) {
|
||||
if (serverDomain.provider != DnsProviderType.unknown) {
|
||||
return RecoveryStep.backblazeToken;
|
||||
}
|
||||
return RecoveryStep.dnsProviderToken;
|
||||
|
@ -534,7 +534,7 @@ class ServerInstallationRepository {
|
|||
serverId: 0,
|
||||
linuxDevice: '',
|
||||
),
|
||||
provider: ServerProvider.unknown,
|
||||
provider: ServerProviderType.unknown,
|
||||
id: 0,
|
||||
ip4: serverIp,
|
||||
startTime: null,
|
||||
|
@ -571,7 +571,7 @@ class ServerInstallationRepository {
|
|||
serverId: 0,
|
||||
linuxDevice: '',
|
||||
),
|
||||
provider: ServerProvider.unknown,
|
||||
provider: ServerProviderType.unknown,
|
||||
id: 0,
|
||||
ip4: serverIp,
|
||||
startTime: null,
|
||||
|
@ -606,7 +606,7 @@ class ServerInstallationRepository {
|
|||
sizeByte: 0,
|
||||
linuxDevice: '',
|
||||
),
|
||||
provider: ServerProvider.unknown,
|
||||
provider: ServerProviderType.unknown,
|
||||
id: 0,
|
||||
ip4: serverIp,
|
||||
startTime: null,
|
||||
|
@ -634,7 +634,7 @@ class ServerInstallationRepository {
|
|||
serverId: 0,
|
||||
linuxDevice: '',
|
||||
),
|
||||
provider: ServerProvider.unknown,
|
||||
provider: ServerProviderType.unknown,
|
||||
id: 0,
|
||||
ip4: serverIp,
|
||||
startTime: null,
|
||||
|
@ -691,11 +691,11 @@ class ServerInstallationRepository {
|
|||
getIt<ApiConfigModel>().init();
|
||||
}
|
||||
|
||||
Future<void> saveServerProviderType(final ServerProvider type) async {
|
||||
Future<void> saveServerProviderType(final ServerProviderType type) async {
|
||||
await getIt<ApiConfigModel>().storeServerProviderType(type);
|
||||
}
|
||||
|
||||
Future<void> saveDnsProviderType(final DnsProvider type) async {
|
||||
Future<void> saveDnsProviderType(final DnsProviderType type) async {
|
||||
await getIt<ApiConfigModel>().storeDnsProviderType(type);
|
||||
}
|
||||
|
||||
|
|
|
@ -13,8 +13,8 @@ class ApiConfigModel {
|
|||
String? get serverLocation => _serverLocation;
|
||||
String? get serverType => _serverType;
|
||||
String? get dnsProviderKey => _dnsProviderKey;
|
||||
ServerProvider? get serverProvider => _serverProvider;
|
||||
DnsProvider? get dnsProvider => _dnsProvider;
|
||||
ServerProviderType? get serverProvider => _serverProvider;
|
||||
DnsProviderType? get dnsProvider => _dnsProvider;
|
||||
BackblazeCredential? get backblazeCredential => _backblazeCredential;
|
||||
ServerDomain? get serverDomain => _serverDomain;
|
||||
BackblazeBucket? get backblazeBucket => _backblazeBucket;
|
||||
|
@ -23,19 +23,19 @@ class ApiConfigModel {
|
|||
String? _serverLocation;
|
||||
String? _dnsProviderKey;
|
||||
String? _serverType;
|
||||
ServerProvider? _serverProvider;
|
||||
DnsProvider? _dnsProvider;
|
||||
ServerProviderType? _serverProvider;
|
||||
DnsProviderType? _dnsProvider;
|
||||
ServerHostingDetails? _serverDetails;
|
||||
BackblazeCredential? _backblazeCredential;
|
||||
ServerDomain? _serverDomain;
|
||||
BackblazeBucket? _backblazeBucket;
|
||||
|
||||
Future<void> storeServerProviderType(final ServerProvider value) async {
|
||||
Future<void> storeServerProviderType(final ServerProviderType value) async {
|
||||
await _box.put(BNames.serverProvider, value);
|
||||
_serverProvider = value;
|
||||
}
|
||||
|
||||
Future<void> storeDnsProviderType(final DnsProvider value) async {
|
||||
Future<void> storeDnsProviderType(final DnsProviderType value) async {
|
||||
await _box.put(BNames.dnsProvider, value);
|
||||
_dnsProvider = value;
|
||||
}
|
||||
|
|
|
@ -33,8 +33,8 @@ class ServerHostingDetails {
|
|||
@HiveField(5)
|
||||
final String apiToken;
|
||||
|
||||
@HiveField(6, defaultValue: ServerProvider.hetzner)
|
||||
final ServerProvider provider;
|
||||
@HiveField(6, defaultValue: ServerProviderType.hetzner)
|
||||
final ServerProviderType provider;
|
||||
|
||||
ServerHostingDetails copyWith({final DateTime? startTime}) =>
|
||||
ServerHostingDetails(
|
||||
|
@ -77,7 +77,7 @@ class ServerVolume {
|
|||
}
|
||||
|
||||
@HiveType(typeId: 101)
|
||||
enum ServerProvider {
|
||||
enum ServerProviderType {
|
||||
@HiveField(0)
|
||||
unknown,
|
||||
@HiveField(1)
|
||||
|
@ -85,7 +85,7 @@ enum ServerProvider {
|
|||
@HiveField(2)
|
||||
digitalOcean;
|
||||
|
||||
factory ServerProvider.fromGraphQL(final Enum$ServerProvider provider) {
|
||||
factory ServerProviderType.fromGraphQL(final Enum$ServerProvider provider) {
|
||||
switch (provider) {
|
||||
case Enum$ServerProvider.HETZNER:
|
||||
return hetzner;
|
||||
|
@ -98,9 +98,9 @@ enum ServerProvider {
|
|||
|
||||
String get displayName {
|
||||
switch (this) {
|
||||
case ServerProvider.hetzner:
|
||||
case ServerProviderType.hetzner:
|
||||
return 'Hetzner Cloud';
|
||||
case ServerProvider.digitalOcean:
|
||||
case ServerProviderType.digitalOcean:
|
||||
return 'Digital Ocean';
|
||||
default:
|
||||
return 'Unknown';
|
||||
|
|
|
@ -17,15 +17,15 @@ class ServerDomain {
|
|||
@HiveField(1)
|
||||
final String zoneId;
|
||||
|
||||
@HiveField(2, defaultValue: DnsProvider.cloudflare)
|
||||
final DnsProvider provider;
|
||||
@HiveField(2, defaultValue: DnsProviderType.cloudflare)
|
||||
final DnsProviderType provider;
|
||||
|
||||
@override
|
||||
String toString() => '$domainName: $zoneId';
|
||||
}
|
||||
|
||||
@HiveType(typeId: 100)
|
||||
enum DnsProvider {
|
||||
enum DnsProviderType {
|
||||
@HiveField(0)
|
||||
unknown,
|
||||
@HiveField(1)
|
||||
|
@ -33,7 +33,7 @@ enum DnsProvider {
|
|||
@HiveField(2)
|
||||
digitalOcean;
|
||||
|
||||
factory DnsProvider.fromGraphQL(final Enum$DnsProvider provider) {
|
||||
factory DnsProviderType.fromGraphQL(final Enum$DnsProvider provider) {
|
||||
switch (provider) {
|
||||
case Enum$DnsProvider.CLOUDFLARE:
|
||||
return cloudflare;
|
||||
|
|
|
@ -1,20 +1,20 @@
|
|||
import 'package:selfprivacy/logic/models/hive/server_details.dart';
|
||||
import 'package:selfprivacy/logic/models/hive/server_domain.dart';
|
||||
|
||||
class ServerProviderApiFactorySettings {
|
||||
ServerProviderApiFactorySettings({
|
||||
class ServerProviderSettings {
|
||||
ServerProviderSettings({
|
||||
required this.provider,
|
||||
this.location,
|
||||
});
|
||||
|
||||
final ServerProvider provider;
|
||||
final ServerProviderType provider;
|
||||
final String? location;
|
||||
}
|
||||
|
||||
class DnsProviderApiFactorySettings {
|
||||
DnsProviderApiFactorySettings({
|
||||
class DnsProviderFactorySettings {
|
||||
DnsProviderFactorySettings({
|
||||
required this.provider,
|
||||
});
|
||||
|
||||
final DnsProvider provider;
|
||||
final DnsProviderType provider;
|
||||
}
|
20
lib/logic/providers/providers_controller.dart
Normal file
20
lib/logic/providers/providers_controller.dart
Normal file
|
@ -0,0 +1,20 @@
|
|||
import 'package:selfprivacy/logic/providers/provider_settings.dart';
|
||||
import 'package:selfprivacy/logic/providers/server_provider.dart';
|
||||
import 'package:selfprivacy/logic/providers/server_providers/server_provider_factory.dart';
|
||||
|
||||
class ProvidersController {
|
||||
static ServerProvider? get currentServerProvider => _serverProvider;
|
||||
|
||||
static void initServerProvider(
|
||||
final ServerProviderSettings settings,
|
||||
) {
|
||||
_serverProvider =
|
||||
ServerProviderFactory.createServerProviderInterface(settings);
|
||||
}
|
||||
|
||||
static void clearProviders() {
|
||||
_serverProvider = null;
|
||||
}
|
||||
|
||||
static ServerProvider? _serverProvider;
|
||||
}
|
5
lib/logic/providers/server_provider.dart
Normal file
5
lib/logic/providers/server_provider.dart
Normal file
|
@ -0,0 +1,5 @@
|
|||
import 'package:selfprivacy/logic/api_maps/api_generic_result.dart';
|
||||
|
||||
abstract class ServerProvider {
|
||||
Future<APIGenericResult<bool>> isApiTokenValid(final String apiToken);
|
||||
}
|
3
lib/logic/providers/server_providers/digital_ocean.dart
Normal file
3
lib/logic/providers/server_providers/digital_ocean.dart
Normal file
|
@ -0,0 +1,3 @@
|
|||
import 'package:selfprivacy/logic/providers/server_provider.dart';
|
||||
|
||||
class DigitalOceanServerProvider extends ServerProvider {}
|
|
@ -0,0 +1,3 @@
|
|||
import 'package:selfprivacy/logic/providers/server_provider.dart';
|
||||
|
||||
class HetznerServerProvider extends ServerProvider {}
|
|
@ -1,14 +1,25 @@
|
|||
import 'package:selfprivacy/logic/providers/provider_settings.dart';
|
||||
import 'package:selfprivacy/logic/models/hive/server_details.dart';
|
||||
import 'package:selfprivacy/logic/providers/server_provider.dart';
|
||||
import 'package:selfprivacy/logic/providers/server_providers/digital_ocean.dart';
|
||||
import 'package:selfprivacy/logic/providers/server_providers/hetzner.dart';
|
||||
|
||||
class UnknownProviderException implements Exception {
|
||||
UnknownProviderException(this.message);
|
||||
final String message;
|
||||
}
|
||||
|
||||
class ServerProviderFactory {
|
||||
static ServerProvider createServerProviderApiFactory(
|
||||
final ServerProviderApiFactorySettings settings,
|
||||
static ServerProvider createServerProviderInterface(
|
||||
final ServerProviderSettings settings,
|
||||
) {
|
||||
switch (settings.provider) {
|
||||
case ServerProvider.hetzner:
|
||||
return HetznerApiFactory(region: settings.location);
|
||||
case ServerProvider.digitalOcean:
|
||||
return DigitalOceanApiFactory(region: settings.location);
|
||||
case ServerProvider.unknown:
|
||||
throw UnknownApiProviderException('Unknown server provider');
|
||||
case ServerProviderType.hetzner:
|
||||
return HetznerServerProvider();
|
||||
case ServerProviderType.digitalOcean:
|
||||
return DigitalOceanServerProvider();
|
||||
case ServerProviderType.unknown:
|
||||
throw UnknownProviderException('Unknown server provider');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -28,9 +28,9 @@ class DnsProviderPicker extends StatefulWidget {
|
|||
}
|
||||
|
||||
class _DnsProviderPickerState extends State<DnsProviderPicker> {
|
||||
DnsProvider selectedProvider = DnsProvider.unknown;
|
||||
DnsProviderType selectedProvider = DnsProviderType.unknown;
|
||||
|
||||
void setProvider(final DnsProvider provider) {
|
||||
void setProvider(final DnsProviderType provider) {
|
||||
setState(() {
|
||||
selectedProvider = provider;
|
||||
});
|
||||
|
@ -39,17 +39,17 @@ class _DnsProviderPickerState extends State<DnsProviderPicker> {
|
|||
@override
|
||||
Widget build(final BuildContext context) {
|
||||
switch (selectedProvider) {
|
||||
case DnsProvider.unknown:
|
||||
case DnsProviderType.unknown:
|
||||
return ProviderSelectionPage(
|
||||
serverInstallationCubit: widget.serverInstallationCubit,
|
||||
callback: setProvider,
|
||||
);
|
||||
|
||||
case DnsProvider.cloudflare:
|
||||
case DnsProviderType.cloudflare:
|
||||
return ProviderInputDataPage(
|
||||
providerCubit: widget.formCubit,
|
||||
providerInfo: ProviderPageInfo(
|
||||
providerType: DnsProvider.cloudflare,
|
||||
providerType: DnsProviderType.cloudflare,
|
||||
pathToHow: 'how_cloudflare',
|
||||
image: Image.asset(
|
||||
'assets/images/logos/cloudflare.png',
|
||||
|
@ -58,11 +58,11 @@ class _DnsProviderPickerState extends State<DnsProviderPicker> {
|
|||
),
|
||||
);
|
||||
|
||||
case DnsProvider.digitalOcean:
|
||||
case DnsProviderType.digitalOcean:
|
||||
return ProviderInputDataPage(
|
||||
providerCubit: widget.formCubit,
|
||||
providerInfo: ProviderPageInfo(
|
||||
providerType: DnsProvider.digitalOcean,
|
||||
providerType: DnsProviderType.digitalOcean,
|
||||
pathToHow: 'how_digital_ocean_dns',
|
||||
image: Image.asset(
|
||||
'assets/images/logos/digital_ocean.png',
|
||||
|
@ -83,7 +83,7 @@ class ProviderPageInfo {
|
|||
|
||||
final String pathToHow;
|
||||
final Image image;
|
||||
final DnsProvider providerType;
|
||||
final DnsProviderType providerType;
|
||||
}
|
||||
|
||||
class ProviderInputDataPage extends StatelessWidget {
|
||||
|
@ -227,8 +227,8 @@ class ProviderSelectionPage extends StatelessWidget {
|
|||
title: 'basis.select'.tr(),
|
||||
onPressed: () {
|
||||
serverInstallationCubit
|
||||
.setDnsProviderType(DnsProvider.cloudflare);
|
||||
callback(DnsProvider.cloudflare);
|
||||
.setDnsProviderType(DnsProviderType.cloudflare);
|
||||
callback(DnsProviderType.cloudflare);
|
||||
},
|
||||
),
|
||||
// Outlined button that will open website
|
||||
|
@ -292,8 +292,8 @@ class ProviderSelectionPage extends StatelessWidget {
|
|||
title: 'basis.select'.tr(),
|
||||
onPressed: () {
|
||||
serverInstallationCubit
|
||||
.setDnsProviderType(DnsProvider.digitalOcean);
|
||||
callback(DnsProvider.digitalOcean);
|
||||
.setDnsProviderType(DnsProviderType.digitalOcean);
|
||||
callback(DnsProviderType.digitalOcean);
|
||||
},
|
||||
),
|
||||
// Outlined button that will open website
|
||||
|
|
|
@ -29,9 +29,9 @@ class ServerProviderPicker extends StatefulWidget {
|
|||
}
|
||||
|
||||
class _ServerProviderPickerState extends State<ServerProviderPicker> {
|
||||
ServerProvider selectedProvider = ServerProvider.unknown;
|
||||
ServerProviderType selectedProvider = ServerProviderType.unknown;
|
||||
|
||||
void setProvider(final ServerProvider provider) {
|
||||
void setProvider(final ServerProviderType provider) {
|
||||
setState(() {
|
||||
selectedProvider = provider;
|
||||
});
|
||||
|
@ -40,17 +40,17 @@ class _ServerProviderPickerState extends State<ServerProviderPicker> {
|
|||
@override
|
||||
Widget build(final BuildContext context) {
|
||||
switch (selectedProvider) {
|
||||
case ServerProvider.unknown:
|
||||
case ServerProviderType.unknown:
|
||||
return ProviderSelectionPage(
|
||||
serverInstallationCubit: widget.serverInstallationCubit,
|
||||
callback: setProvider,
|
||||
);
|
||||
|
||||
case ServerProvider.hetzner:
|
||||
case ServerProviderType.hetzner:
|
||||
return ProviderInputDataPage(
|
||||
providerCubit: widget.formCubit,
|
||||
providerInfo: ProviderPageInfo(
|
||||
providerType: ServerProvider.hetzner,
|
||||
providerType: ServerProviderType.hetzner,
|
||||
pathToHow: 'how_hetzner',
|
||||
image: Image.asset(
|
||||
'assets/images/logos/hetzner.png',
|
||||
|
@ -59,11 +59,11 @@ class _ServerProviderPickerState extends State<ServerProviderPicker> {
|
|||
),
|
||||
);
|
||||
|
||||
case ServerProvider.digitalOcean:
|
||||
case ServerProviderType.digitalOcean:
|
||||
return ProviderInputDataPage(
|
||||
providerCubit: widget.formCubit,
|
||||
providerInfo: ProviderPageInfo(
|
||||
providerType: ServerProvider.digitalOcean,
|
||||
providerType: ServerProviderType.digitalOcean,
|
||||
pathToHow: 'how_digital_ocean',
|
||||
image: Image.asset(
|
||||
'assets/images/logos/digital_ocean.png',
|
||||
|
@ -84,7 +84,7 @@ class ProviderPageInfo {
|
|||
|
||||
final String pathToHow;
|
||||
final Image image;
|
||||
final ServerProvider providerType;
|
||||
final ServerProviderType providerType;
|
||||
}
|
||||
|
||||
class ProviderInputDataPage extends StatelessWidget {
|
||||
|
@ -242,8 +242,8 @@ class ProviderSelectionPage extends StatelessWidget {
|
|||
title: 'basis.select'.tr(),
|
||||
onPressed: () {
|
||||
serverInstallationCubit
|
||||
.setServerProviderType(ServerProvider.hetzner);
|
||||
callback(ServerProvider.hetzner);
|
||||
.setServerProviderType(ServerProviderType.hetzner);
|
||||
callback(ServerProviderType.hetzner);
|
||||
},
|
||||
),
|
||||
// Outlined button that will open website
|
||||
|
@ -315,9 +315,9 @@ class ProviderSelectionPage extends StatelessWidget {
|
|||
FilledButton(
|
||||
title: 'basis.select'.tr(),
|
||||
onPressed: () {
|
||||
serverInstallationCubit
|
||||
.setServerProviderType(ServerProvider.digitalOcean);
|
||||
callback(ServerProvider.digitalOcean);
|
||||
serverInstallationCubit.setServerProviderType(
|
||||
ServerProviderType.digitalOcean);
|
||||
callback(ServerProviderType.digitalOcean);
|
||||
},
|
||||
),
|
||||
// Outlined button that will open website
|
||||
|
|
Loading…
Reference in a new issue