mirror of
https://git.selfprivacy.org/kherel/selfprivacy.org.app.git
synced 2025-01-23 09:16:54 +00:00
fix(region): Move region settings for provider api to factory
This commit is contained in:
parent
72760e7980
commit
8a93af2b06
|
@ -87,6 +87,9 @@ class BNames {
|
|||
/// A String field of [serverInstallationBox] box.
|
||||
static String hetznerKey = 'hetznerKey';
|
||||
|
||||
/// A String field of [serverLocation] box.
|
||||
static String serverLocation = 'serverLocation';
|
||||
|
||||
/// A String field of [serverInstallationBox] box.
|
||||
static String cloudFlareKey = 'cloudFlareKey';
|
||||
|
||||
|
|
|
@ -1,3 +1,4 @@
|
|||
import 'package:selfprivacy/logic/api_maps/rest_maps/api_factory_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/dns_provider_factory.dart';
|
||||
import 'package:selfprivacy/logic/api_maps/rest_maps/server_providers/digital_ocean/digital_ocean_factory.dart';
|
||||
|
@ -13,9 +14,9 @@ class UnknownApiProviderException implements Exception {
|
|||
|
||||
class ApiFactoryCreator {
|
||||
static ServerProviderApiFactory createServerProviderApiFactory(
|
||||
final ServerProvider provider,
|
||||
final ServerProviderApiFactorySettings settings,
|
||||
) {
|
||||
switch (provider) {
|
||||
switch (settings.provider) {
|
||||
case ServerProvider.hetzner:
|
||||
return HetznerApiFactory();
|
||||
case ServerProvider.digitalOcean:
|
||||
|
@ -26,9 +27,9 @@ class ApiFactoryCreator {
|
|||
}
|
||||
|
||||
static DnsProviderApiFactory createDnsProviderApiFactory(
|
||||
final DnsProvider provider,
|
||||
final DnsProviderApiFactorySettings settings,
|
||||
) {
|
||||
switch (provider) {
|
||||
switch (settings.provider) {
|
||||
case DnsProvider.cloudflare:
|
||||
return CloudflareApiFactory();
|
||||
case DnsProvider.unknown:
|
||||
|
@ -39,9 +40,9 @@ class ApiFactoryCreator {
|
|||
|
||||
class VolumeApiFactoryCreator {
|
||||
static VolumeProviderApiFactory createVolumeProviderApiFactory(
|
||||
final ServerProvider provider,
|
||||
final ServerProviderApiFactorySettings settings,
|
||||
) {
|
||||
switch (provider) {
|
||||
switch (settings.provider) {
|
||||
case ServerProvider.hetzner:
|
||||
return HetznerApiFactory();
|
||||
case ServerProvider.digitalOcean:
|
||||
|
|
20
lib/logic/api_maps/rest_maps/api_factory_settings.dart
Normal file
20
lib/logic/api_maps/rest_maps/api_factory_settings.dart
Normal file
|
@ -0,0 +1,20 @@
|
|||
import 'package:selfprivacy/logic/models/hive/server_details.dart';
|
||||
import 'package:selfprivacy/logic/models/hive/server_domain.dart';
|
||||
|
||||
class ServerProviderApiFactorySettings {
|
||||
ServerProviderApiFactorySettings({
|
||||
required this.provider,
|
||||
this.location,
|
||||
});
|
||||
|
||||
final ServerProvider provider;
|
||||
final String? location;
|
||||
}
|
||||
|
||||
class DnsProviderApiFactorySettings {
|
||||
DnsProviderApiFactorySettings({
|
||||
required this.provider,
|
||||
});
|
||||
|
||||
final DnsProvider provider;
|
||||
}
|
|
@ -27,7 +27,7 @@ class DigitalOceanApi extends ServerProviderApi with VolumeProviderApi {
|
|||
@override
|
||||
bool isWithToken;
|
||||
|
||||
final String region;
|
||||
final String? region;
|
||||
|
||||
@override
|
||||
BaseOptions get options {
|
||||
|
@ -631,6 +631,7 @@ class DigitalOceanApi extends ServerProviderApi with VolumeProviderApi {
|
|||
value: rawSize['price_monthly'],
|
||||
currency: 'USD',
|
||||
),
|
||||
location: location,
|
||||
),
|
||||
);
|
||||
}
|
||||
|
|
|
@ -8,7 +8,8 @@ class DigitalOceanApiFactory extends ServerProviderApiFactory
|
|||
with VolumeProviderApiFactory {
|
||||
@override
|
||||
ServerProviderApi getServerProvider({
|
||||
required final ServerProviderApiSettings settings,
|
||||
final ServerProviderApiSettings settings =
|
||||
const ServerProviderApiSettings(),
|
||||
}) =>
|
||||
DigitalOceanApi(
|
||||
region: settings.region,
|
||||
|
@ -18,7 +19,8 @@ class DigitalOceanApiFactory extends ServerProviderApiFactory
|
|||
|
||||
@override
|
||||
VolumeProviderApi getVolumeProvider({
|
||||
required final ServerProviderApiSettings settings,
|
||||
final ServerProviderApiSettings settings =
|
||||
const ServerProviderApiSettings(),
|
||||
}) =>
|
||||
DigitalOceanApi(
|
||||
region: settings.region,
|
||||
|
|
|
@ -18,7 +18,7 @@ import 'package:selfprivacy/utils/password_generator.dart';
|
|||
|
||||
class HetznerApi extends ServerProviderApi with VolumeProviderApi {
|
||||
HetznerApi({
|
||||
required this.region,
|
||||
this.region,
|
||||
this.hasLogger = false,
|
||||
this.isWithToken = true,
|
||||
});
|
||||
|
@ -27,7 +27,7 @@ class HetznerApi extends ServerProviderApi with VolumeProviderApi {
|
|||
@override
|
||||
bool isWithToken;
|
||||
|
||||
final String region;
|
||||
final String? region;
|
||||
|
||||
@override
|
||||
BaseOptions get options {
|
||||
|
@ -336,6 +336,11 @@ class HetznerApi extends ServerProviderApi with VolumeProviderApi {
|
|||
final String userdataString =
|
||||
"#cloud-config\nruncmd:\n- curl https://git.selfprivacy.org/SelfPrivacy/selfprivacy-nixos-infect/raw/branch/master/nixos-infect | PROVIDER=hetzner NIX_CHANNEL=nixos-21.05 DOMAIN='$domainName' LUSER='${rootUser.login}' ENCODED_PASSWORD='$base64Password' CF_TOKEN=$dnsApiToken DB_PASSWORD=$dbPassword API_TOKEN=$apiToken HOSTNAME=$hostname bash 2>&1 | tee /tmp/infect.log";
|
||||
|
||||
ServerHostingDetails? serverDetails;
|
||||
DioError? hetznerError;
|
||||
bool success = false;
|
||||
|
||||
try {
|
||||
final Map<String, Object> data = {
|
||||
'name': hostname,
|
||||
'server_type': 'cx11',
|
||||
|
@ -346,15 +351,10 @@ class HetznerApi extends ServerProviderApi with VolumeProviderApi {
|
|||
'user_data': userdataString,
|
||||
'labels': {},
|
||||
'automount': true,
|
||||
'location': region,
|
||||
'location': region!,
|
||||
};
|
||||
print('Decoded data: $data');
|
||||
|
||||
ServerHostingDetails? serverDetails;
|
||||
DioError? hetznerError;
|
||||
bool success = false;
|
||||
|
||||
try {
|
||||
final Response serverCreateResponse = await client.post(
|
||||
'/servers',
|
||||
data: data,
|
||||
|
@ -616,6 +616,7 @@ class HetznerApi extends ServerProviderApi with VolumeProviderApi {
|
|||
value: rawPrice['price_monthly']['gross'],
|
||||
currency: 'EUR',
|
||||
),
|
||||
location: location,
|
||||
),
|
||||
);
|
||||
}
|
||||
|
|
|
@ -6,22 +6,28 @@ import 'package:selfprivacy/logic/api_maps/rest_maps/server_providers/volume_pro
|
|||
|
||||
class HetznerApiFactory extends ServerProviderApiFactory
|
||||
with VolumeProviderApiFactory {
|
||||
HetznerApiFactory({this.region});
|
||||
|
||||
final String? region;
|
||||
|
||||
@override
|
||||
ServerProviderApi getServerProvider({
|
||||
required final ServerProviderApiSettings settings,
|
||||
final ServerProviderApiSettings settings =
|
||||
const ServerProviderApiSettings(),
|
||||
}) =>
|
||||
HetznerApi(
|
||||
region: settings.region,
|
||||
region: settings.region ?? region,
|
||||
hasLogger: settings.hasLogger,
|
||||
isWithToken: settings.isWithToken,
|
||||
);
|
||||
|
||||
@override
|
||||
VolumeProviderApi getVolumeProvider({
|
||||
required final ServerProviderApiSettings settings,
|
||||
final ServerProviderApiSettings settings =
|
||||
const ServerProviderApiSettings(),
|
||||
}) =>
|
||||
HetznerApi(
|
||||
region: settings.region,
|
||||
region: settings.region ?? region,
|
||||
hasLogger: settings.hasLogger,
|
||||
isWithToken: settings.isWithToken,
|
||||
);
|
||||
|
|
|
@ -2,10 +2,10 @@ import 'package:selfprivacy/logic/api_maps/rest_maps/provider_api_settings.dart'
|
|||
|
||||
class ServerProviderApiSettings extends ProviderApiSettings {
|
||||
const ServerProviderApiSettings({
|
||||
required this.region,
|
||||
this.region,
|
||||
super.hasLogger = false,
|
||||
super.isWithToken = true,
|
||||
});
|
||||
|
||||
final String region;
|
||||
final String? region;
|
||||
}
|
||||
|
|
|
@ -4,12 +4,12 @@ import 'package:selfprivacy/logic/api_maps/rest_maps/server_providers/volume_pro
|
|||
|
||||
abstract class ServerProviderApiFactory {
|
||||
ServerProviderApi getServerProvider({
|
||||
required final ServerProviderApiSettings settings,
|
||||
final ServerProviderApiSettings settings,
|
||||
});
|
||||
}
|
||||
|
||||
mixin VolumeProviderApiFactory {
|
||||
VolumeProviderApi getVolumeProvider({
|
||||
required final ServerProviderApiSettings settings,
|
||||
final ServerProviderApiSettings settings,
|
||||
});
|
||||
}
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
import 'package:cubit_form/cubit_form.dart';
|
||||
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/api_maps/rest_maps/dns_providers/dns_provider.dart';
|
||||
import 'package:selfprivacy/logic/api_maps/rest_maps/dns_providers/dns_provider_factory.dart';
|
||||
import 'package:selfprivacy/logic/cubit/app_config_dependent/authentication_dependend_cubit.dart';
|
||||
|
@ -20,8 +21,9 @@ class DnsRecordsCubit
|
|||
|
||||
DnsProviderApiFactory? dnsProviderApiFactory =
|
||||
ApiFactoryCreator.createDnsProviderApiFactory(
|
||||
DnsProvider.cloudflare, // TODO: HARDCODE FOR NOW!!!
|
||||
); // TODO: Remove when provider selection is implemented.
|
||||
DnsProviderApiFactorySettings(provider: DnsProvider.cloudflare),
|
||||
); // TODO: HARDCODE FOR NOW!!!
|
||||
// TODO: Remove when provider selection is implemented.
|
||||
|
||||
final ServerApi api = ServerApi();
|
||||
|
||||
|
|
|
@ -1,3 +1,4 @@
|
|||
import 'package:selfprivacy/config/get_it_config.dart';
|
||||
import 'package:selfprivacy/logic/api_maps/rest_maps/server_providers/hetzner/hetzner.dart';
|
||||
import 'package:selfprivacy/logic/common_enum/common_enum.dart';
|
||||
import 'package:selfprivacy/logic/models/hetzner_metrics.dart';
|
||||
|
@ -27,8 +28,9 @@ class HetznerMetricsRepository {
|
|||
}
|
||||
|
||||
final HetznerApi api = HetznerApi(
|
||||
/// TODO: Hetzner hardcode (???)
|
||||
hasLogger: false,
|
||||
region: 'fra1',
|
||||
region: getIt<ApiConfigModel>().serverLocation,
|
||||
);
|
||||
|
||||
final List<Map<String, dynamic>> results = await Future.wait([
|
||||
|
|
|
@ -2,6 +2,7 @@ import 'package:easy_localization/easy_localization.dart';
|
|||
import 'package:selfprivacy/config/get_it_config.dart';
|
||||
import 'package:selfprivacy/logic/api_maps/graphql_maps/server_api/server.dart';
|
||||
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/api_maps/rest_maps/server_providers/server_provider_api_settings.dart';
|
||||
import 'package:selfprivacy/logic/api_maps/rest_maps/server_providers/server_provider_factory.dart';
|
||||
import 'package:selfprivacy/logic/common_enum/common_enum.dart';
|
||||
|
@ -25,22 +26,21 @@ class ApiProviderVolumeCubit
|
|||
Future<void> load() async {
|
||||
if (serverInstallationCubit.state is ServerInstallationFinished) {
|
||||
final serverDetails = getIt<ApiConfigModel>().serverDetails;
|
||||
final serverLocation = getIt<ApiConfigModel>().serverLocation;
|
||||
providerApi = serverDetails == null
|
||||
? null
|
||||
: VolumeApiFactoryCreator.createVolumeProviderApiFactory(
|
||||
getIt<ApiConfigModel>().serverDetails!.provider,
|
||||
ServerProviderApiFactorySettings(
|
||||
location: serverLocation,
|
||||
provider: getIt<ApiConfigModel>().serverDetails!.provider,
|
||||
),
|
||||
);
|
||||
_refetch();
|
||||
}
|
||||
}
|
||||
|
||||
Future<Price?> getPricePerGb() async => providerApi!
|
||||
.getVolumeProvider(
|
||||
settings: const ServerProviderApiSettings(
|
||||
region: 'fra1',
|
||||
),
|
||||
)
|
||||
.getPricePerGb();
|
||||
Future<Price?> getPricePerGb() async =>
|
||||
providerApi!.getVolumeProvider().getPricePerGb();
|
||||
|
||||
Future<void> refresh() async {
|
||||
emit(const ApiProviderVolumeState([], LoadingStatus.refreshing, false));
|
||||
|
@ -52,13 +52,8 @@ class ApiProviderVolumeCubit
|
|||
return emit(const ApiProviderVolumeState([], LoadingStatus.error, false));
|
||||
}
|
||||
|
||||
final List<ServerVolume> volumes = await providerApi!
|
||||
.getVolumeProvider(
|
||||
settings: const ServerProviderApiSettings(
|
||||
region: 'fra1',
|
||||
),
|
||||
)
|
||||
.getVolumes();
|
||||
final List<ServerVolume> volumes =
|
||||
await providerApi!.getVolumeProvider().getVolumes();
|
||||
|
||||
if (volumes.isEmpty) {
|
||||
return emit(const ApiProviderVolumeState([], LoadingStatus.error, false));
|
||||
|
@ -70,22 +65,14 @@ class ApiProviderVolumeCubit
|
|||
Future<void> attachVolume(final DiskVolume volume) async {
|
||||
final ServerHostingDetails server = getIt<ApiConfigModel>().serverDetails!;
|
||||
await providerApi!
|
||||
.getVolumeProvider(
|
||||
settings: const ServerProviderApiSettings(
|
||||
region: 'fra1',
|
||||
),
|
||||
)
|
||||
.getVolumeProvider()
|
||||
.attachVolume(volume.providerVolume!.id.toString(), server.id);
|
||||
refresh();
|
||||
}
|
||||
|
||||
Future<void> detachVolume(final DiskVolume volume) async {
|
||||
await providerApi!
|
||||
.getVolumeProvider(
|
||||
settings: const ServerProviderApiSettings(
|
||||
region: 'fra1',
|
||||
),
|
||||
)
|
||||
.getVolumeProvider()
|
||||
.detachVolume(volume.providerVolume!.id.toString());
|
||||
refresh();
|
||||
}
|
||||
|
@ -99,13 +86,7 @@ class ApiProviderVolumeCubit
|
|||
'Starting resize',
|
||||
);
|
||||
emit(state.copyWith(isResizing: true));
|
||||
final bool resized = await providerApi!
|
||||
.getVolumeProvider(
|
||||
settings: const ServerProviderApiSettings(
|
||||
region: 'fra1',
|
||||
),
|
||||
)
|
||||
.resizeVolume(
|
||||
final bool resized = await providerApi!.getVolumeProvider().resizeVolume(
|
||||
volume.providerVolume!.id.toString(),
|
||||
newSizeGb,
|
||||
);
|
||||
|
@ -141,13 +122,8 @@ class ApiProviderVolumeCubit
|
|||
}
|
||||
|
||||
Future<void> createVolume() async {
|
||||
final ServerVolume? volume = await providerApi!
|
||||
.getVolumeProvider(
|
||||
settings: const ServerProviderApiSettings(
|
||||
region: 'fra1',
|
||||
),
|
||||
)
|
||||
.createVolume();
|
||||
final ServerVolume? volume =
|
||||
await providerApi!.getVolumeProvider().createVolume();
|
||||
|
||||
final diskVolume = DiskVolume(providerVolume: volume);
|
||||
await attachVolume(diskVolume);
|
||||
|
@ -160,11 +136,7 @@ class ApiProviderVolumeCubit
|
|||
|
||||
Future<void> deleteVolume(final DiskVolume volume) async {
|
||||
await providerApi!
|
||||
.getVolumeProvider(
|
||||
settings: const ServerProviderApiSettings(
|
||||
region: 'fra1',
|
||||
),
|
||||
)
|
||||
.getVolumeProvider()
|
||||
.deleteVolume(volume.providerVolume!.id.toString());
|
||||
refresh();
|
||||
}
|
||||
|
|
|
@ -1,3 +1,4 @@
|
|||
import 'package:selfprivacy/config/get_it_config.dart';
|
||||
import 'package:selfprivacy/logic/api_maps/rest_maps/server_providers/hetzner/hetzner.dart';
|
||||
import 'package:selfprivacy/logic/api_maps/graphql_maps/server_api/server.dart';
|
||||
import 'package:selfprivacy/logic/models/auto_upgrade_settings.dart';
|
||||
|
@ -5,7 +6,10 @@ import 'package:selfprivacy/logic/models/json/hetzner_server_info.dart';
|
|||
import 'package:selfprivacy/logic/models/timezone_settings.dart';
|
||||
|
||||
class ServerDetailsRepository {
|
||||
HetznerApi hetzner = HetznerApi(region: 'fra1');
|
||||
HetznerApi hetzner = HetznerApi(
|
||||
/// TODO: Hetzner hardcode (???)
|
||||
region: getIt<ApiConfigModel>().serverLocation,
|
||||
);
|
||||
ServerApi server = ServerApi();
|
||||
|
||||
Future<ServerDetailsRepositoryDto> load() async {
|
||||
|
|
|
@ -5,6 +5,7 @@ import 'package:easy_localization/easy_localization.dart';
|
|||
import 'package:equatable/equatable.dart';
|
||||
import 'package:selfprivacy/config/get_it_config.dart';
|
||||
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/api_maps/rest_maps/dns_providers/dns_provider_api_settings.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,17 +58,15 @@ class ServerInstallationCubit extends Cubit<ServerInstallationState> {
|
|||
void setServerProviderType(final ServerProvider providerType) {
|
||||
repository.serverProviderApiFactory =
|
||||
ApiFactoryCreator.createServerProviderApiFactory(
|
||||
providerType,
|
||||
ServerProviderApiFactorySettings(
|
||||
provider: providerType,
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
RegExp getServerProviderApiTokenValidation() =>
|
||||
repository.serverProviderApiFactory!
|
||||
.getServerProvider(
|
||||
settings: const ServerProviderApiSettings(
|
||||
region: 'fra1',
|
||||
),
|
||||
)
|
||||
.getServerProvider()
|
||||
.getApiTokenValidation();
|
||||
|
||||
RegExp getDnsProviderApiTokenValidation() => repository.dnsProviderApiFactory!
|
||||
|
@ -80,7 +79,6 @@ class ServerInstallationCubit extends Cubit<ServerInstallationState> {
|
|||
repository.serverProviderApiFactory!
|
||||
.getServerProvider(
|
||||
settings: const ServerProviderApiSettings(
|
||||
region: 'fra1',
|
||||
isWithToken: false,
|
||||
),
|
||||
)
|
||||
|
@ -101,9 +99,7 @@ class ServerInstallationCubit extends Cubit<ServerInstallationState> {
|
|||
}
|
||||
|
||||
return repository.serverProviderApiFactory!
|
||||
.getServerProvider(
|
||||
settings: const ServerProviderApiSettings(region: 'fra1'),
|
||||
)
|
||||
.getServerProvider()
|
||||
.getAvailableLocations();
|
||||
}
|
||||
|
||||
|
@ -115,9 +111,7 @@ class ServerInstallationCubit extends Cubit<ServerInstallationState> {
|
|||
}
|
||||
|
||||
return repository.serverProviderApiFactory!
|
||||
.getServerProvider(
|
||||
settings: const ServerProviderApiSettings(region: 'fra1'),
|
||||
)
|
||||
.getServerProvider()
|
||||
.getServerTypesByLocation(location: location);
|
||||
}
|
||||
|
||||
|
@ -141,12 +135,20 @@ class ServerInstallationCubit extends Cubit<ServerInstallationState> {
|
|||
);
|
||||
}
|
||||
|
||||
void setServerType(final String serverTypeId) async {
|
||||
await repository.saveServerType(serverTypeId);
|
||||
void setServerType(final ServerType serverType) async {
|
||||
await repository.saveServerType(serverType);
|
||||
|
||||
repository.serverProviderApiFactory =
|
||||
ApiFactoryCreator.createServerProviderApiFactory(
|
||||
ServerProviderApiFactorySettings(
|
||||
provider: getIt<ApiConfigModel>().serverDetails!.provider,
|
||||
location: serverType.location.identifier,
|
||||
),
|
||||
);
|
||||
|
||||
emit(
|
||||
(state as ServerInstallationNotFinished).copyWith(
|
||||
serverTypeIdentificator: serverTypeId,
|
||||
serverTypeIdentificator: serverType.identifier,
|
||||
),
|
||||
);
|
||||
}
|
||||
|
|
|
@ -10,6 +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_factory_creator.dart';
|
||||
import 'package:selfprivacy/logic/api_maps/rest_maps/api_factory_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/rest_maps/dns_providers/dns_provider_factory.dart';
|
||||
|
@ -25,6 +26,7 @@ import 'package:selfprivacy/logic/models/hive/user.dart';
|
|||
import 'package:selfprivacy/logic/models/json/device_token.dart';
|
||||
import 'package:selfprivacy/logic/models/message.dart';
|
||||
import 'package:selfprivacy/logic/models/server_basic_info.dart';
|
||||
import 'package:selfprivacy/logic/models/server_type.dart';
|
||||
import 'package:selfprivacy/ui/components/action_button/action_button.dart';
|
||||
import 'package:selfprivacy/ui/components/brand_alert/brand_alert.dart';
|
||||
|
||||
|
@ -44,11 +46,14 @@ class ServerInstallationRepository {
|
|||
ServerProviderApiFactory? serverProviderApiFactory;
|
||||
DnsProviderApiFactory? dnsProviderApiFactory =
|
||||
ApiFactoryCreator.createDnsProviderApiFactory(
|
||||
DnsProvider.cloudflare, // TODO: HARDCODE FOR NOW!!!
|
||||
DnsProviderApiFactorySettings(
|
||||
provider: DnsProvider.cloudflare,
|
||||
), // TODO: HARDCODE FOR NOW!!!
|
||||
);
|
||||
|
||||
Future<ServerInstallationState> load() async {
|
||||
final String? providerApiToken = getIt<ApiConfigModel>().serverProviderKey;
|
||||
final String? location = getIt<ApiConfigModel>().serverLocation;
|
||||
final String? cloudflareToken = getIt<ApiConfigModel>().cloudFlareKey;
|
||||
final String? serverTypeIdentificator = getIt<ApiConfigModel>().serverType;
|
||||
final ServerDomain? serverDomain = getIt<ApiConfigModel>().serverDomain;
|
||||
|
@ -61,13 +66,18 @@ class ServerInstallationRepository {
|
|||
serverDetails.provider != ServerProvider.unknown) {
|
||||
serverProviderApiFactory =
|
||||
ApiFactoryCreator.createServerProviderApiFactory(
|
||||
serverDetails.provider,
|
||||
ServerProviderApiFactorySettings(
|
||||
provider: serverDetails.provider,
|
||||
location: location,
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
if (serverDomain != null && serverDomain.provider != DnsProvider.unknown) {
|
||||
dnsProviderApiFactory = ApiFactoryCreator.createDnsProviderApiFactory(
|
||||
serverDomain.provider,
|
||||
DnsProviderApiFactorySettings(
|
||||
provider: serverDomain.provider,
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
|
@ -155,11 +165,7 @@ class ServerInstallationRepository {
|
|||
) async {
|
||||
ServerHostingDetails serverDetails;
|
||||
|
||||
final ServerProviderApi api = serverProviderApiFactory!.getServerProvider(
|
||||
settings: const ServerProviderApiSettings(
|
||||
region: 'fra1',
|
||||
),
|
||||
);
|
||||
final ServerProviderApi api = serverProviderApiFactory!.getServerProvider();
|
||||
serverDetails = await api.powerOn();
|
||||
|
||||
return serverDetails;
|
||||
|
@ -235,11 +241,7 @@ class ServerInstallationRepository {
|
|||
required final Future<void> Function(ServerHostingDetails serverDetails)
|
||||
onSuccess,
|
||||
}) async {
|
||||
final ServerProviderApi api = serverProviderApiFactory!.getServerProvider(
|
||||
settings: const ServerProviderApiSettings(
|
||||
region: 'fra1',
|
||||
),
|
||||
);
|
||||
final ServerProviderApi api = serverProviderApiFactory!.getServerProvider();
|
||||
try {
|
||||
final ServerHostingDetails? serverDetails = await api.createServer(
|
||||
dnsApiToken: cloudFlareKey,
|
||||
|
@ -344,11 +346,7 @@ class ServerInstallationRepository {
|
|||
final DnsProviderApi dnsProviderApi =
|
||||
dnsProviderApiFactory!.getDnsProvider();
|
||||
final ServerProviderApi serverApi =
|
||||
serverProviderApiFactory!.getServerProvider(
|
||||
settings: const ServerProviderApiSettings(
|
||||
region: 'fra1',
|
||||
),
|
||||
);
|
||||
serverProviderApiFactory!.getServerProvider();
|
||||
|
||||
await dnsProviderApi.removeSimilarRecords(
|
||||
ip4: serverDetails.ip4,
|
||||
|
@ -420,20 +418,12 @@ class ServerInstallationRepository {
|
|||
}
|
||||
|
||||
Future<ServerHostingDetails> restart() async {
|
||||
final ServerProviderApi api = serverProviderApiFactory!.getServerProvider(
|
||||
settings: const ServerProviderApiSettings(
|
||||
region: 'fra1',
|
||||
),
|
||||
);
|
||||
final ServerProviderApi api = serverProviderApiFactory!.getServerProvider();
|
||||
return api.restart();
|
||||
}
|
||||
|
||||
Future<ServerHostingDetails> powerOn() async {
|
||||
final ServerProviderApi api = serverProviderApiFactory!.getServerProvider(
|
||||
settings: const ServerProviderApiSettings(
|
||||
region: 'fra1',
|
||||
),
|
||||
);
|
||||
final ServerProviderApi api = serverProviderApiFactory!.getServerProvider();
|
||||
return api.powerOn();
|
||||
}
|
||||
|
||||
|
@ -676,11 +666,7 @@ class ServerInstallationRepository {
|
|||
}
|
||||
|
||||
Future<List<ServerBasicInfo>> getServersOnProviderAccount() async {
|
||||
final ServerProviderApi api = serverProviderApiFactory!.getServerProvider(
|
||||
settings: const ServerProviderApiSettings(
|
||||
region: 'fra1',
|
||||
),
|
||||
);
|
||||
final ServerProviderApi api = serverProviderApiFactory!.getServerProvider();
|
||||
return api.getServers();
|
||||
}
|
||||
|
||||
|
@ -699,8 +685,13 @@ class ServerInstallationRepository {
|
|||
await getIt<ApiConfigModel>().storeServerProviderKey(key);
|
||||
}
|
||||
|
||||
Future<void> saveServerType(final String serverType) async {
|
||||
await getIt<ApiConfigModel>().storeServerTypeIdentifier(serverType);
|
||||
Future<void> saveServerType(final ServerType serverType) async {
|
||||
await getIt<ApiConfigModel>().storeServerTypeIdentifier(
|
||||
serverType.identifier,
|
||||
);
|
||||
await getIt<ApiConfigModel>().storeServerLocation(
|
||||
serverType.location.identifier,
|
||||
);
|
||||
}
|
||||
|
||||
Future<void> deleteServerProviderKey() async {
|
||||
|
@ -762,11 +753,7 @@ class ServerInstallationRepository {
|
|||
}
|
||||
|
||||
Future<void> deleteServer(final ServerDomain serverDomain) async {
|
||||
final ServerProviderApi api = serverProviderApiFactory!.getServerProvider(
|
||||
settings: const ServerProviderApiSettings(
|
||||
region: 'fra1',
|
||||
),
|
||||
);
|
||||
final ServerProviderApi api = serverProviderApiFactory!.getServerProvider();
|
||||
final DnsProviderApi dnsProviderApi =
|
||||
dnsProviderApiFactory!.getDnsProvider();
|
||||
|
||||
|
|
|
@ -172,7 +172,8 @@ class ServerInstallationNotFinished extends ServerInstallationState {
|
|||
}) =>
|
||||
ServerInstallationNotFinished(
|
||||
providerApiToken: providerApiToken ?? this.providerApiToken,
|
||||
serverTypeIdentificator: serverTypeIdentificator ?? this.serverTypeIdentificator,
|
||||
serverTypeIdentificator:
|
||||
serverTypeIdentificator ?? this.serverTypeIdentificator,
|
||||
cloudFlareKey: cloudFlareKey ?? this.cloudFlareKey,
|
||||
backblazeCredential: backblazeCredential ?? this.backblazeCredential,
|
||||
serverDomain: serverDomain ?? this.serverDomain,
|
||||
|
@ -316,7 +317,8 @@ class ServerInstallationRecovery extends ServerInstallationState {
|
|||
}) =>
|
||||
ServerInstallationRecovery(
|
||||
providerApiToken: providerApiToken ?? this.providerApiToken,
|
||||
serverTypeIdentificator: serverTypeIdentificator ?? this.serverTypeIdentificator,
|
||||
serverTypeIdentificator:
|
||||
serverTypeIdentificator ?? this.serverTypeIdentificator,
|
||||
cloudFlareKey: cloudFlareKey ?? this.cloudFlareKey,
|
||||
backblazeCredential: backblazeCredential ?? this.backblazeCredential,
|
||||
serverDomain: serverDomain ?? this.serverDomain,
|
||||
|
|
|
@ -10,6 +10,7 @@ class ApiConfigModel {
|
|||
|
||||
ServerHostingDetails? get serverDetails => _serverDetails;
|
||||
String? get serverProviderKey => _serverProviderKey;
|
||||
String? get serverLocation => _serverLocation;
|
||||
String? get serverType => _serverType;
|
||||
String? get cloudFlareKey => _cloudFlareKey;
|
||||
BackblazeCredential? get backblazeCredential => _backblazeCredential;
|
||||
|
@ -17,6 +18,7 @@ class ApiConfigModel {
|
|||
BackblazeBucket? get backblazeBucket => _backblazeBucket;
|
||||
|
||||
String? _serverProviderKey;
|
||||
String? _serverLocation;
|
||||
String? _cloudFlareKey;
|
||||
String? _serverType;
|
||||
ServerHostingDetails? _serverDetails;
|
||||
|
@ -39,6 +41,11 @@ class ApiConfigModel {
|
|||
_serverType = typeIdentifier;
|
||||
}
|
||||
|
||||
Future<void> storeServerLocation(final String serverLocation) async {
|
||||
await _box.put(BNames.serverLocation, serverLocation);
|
||||
_serverLocation = serverLocation;
|
||||
}
|
||||
|
||||
Future<void> storeBackblazeCredential(final BackblazeCredential value) async {
|
||||
await _box.put(BNames.backblazeCredential, value);
|
||||
_backblazeCredential = value;
|
||||
|
@ -61,19 +68,23 @@ class ApiConfigModel {
|
|||
|
||||
void clear() {
|
||||
_serverProviderKey = null;
|
||||
_serverLocation = null;
|
||||
_cloudFlareKey = null;
|
||||
_backblazeCredential = null;
|
||||
_serverDomain = null;
|
||||
_serverDetails = null;
|
||||
_backblazeBucket = null;
|
||||
_serverType = null;
|
||||
}
|
||||
|
||||
void init() {
|
||||
_serverProviderKey = _box.get(BNames.hetznerKey);
|
||||
_serverLocation = _box.get(BNames.serverLocation);
|
||||
_cloudFlareKey = _box.get(BNames.cloudFlareKey);
|
||||
_backblazeCredential = _box.get(BNames.backblazeCredential);
|
||||
_serverDomain = _box.get(BNames.serverDomain);
|
||||
_serverDetails = _box.get(BNames.serverDetails);
|
||||
_backblazeBucket = _box.get(BNames.backblazeBucket);
|
||||
_serverType = _box.get(BNames.serverTypeIdentifier);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
import 'package:selfprivacy/logic/models/disk_size.dart';
|
||||
import 'package:selfprivacy/logic/models/price.dart';
|
||||
import 'package:selfprivacy/logic/models/server_provider_location.dart';
|
||||
|
||||
class ServerType {
|
||||
ServerType({
|
||||
|
@ -9,6 +10,7 @@ class ServerType {
|
|||
required this.cores,
|
||||
required this.disk,
|
||||
required this.price,
|
||||
required this.location,
|
||||
});
|
||||
final String title;
|
||||
final String identifier;
|
||||
|
@ -16,4 +18,5 @@ class ServerType {
|
|||
final DiskSize disk;
|
||||
final int cores;
|
||||
final Price price;
|
||||
final ServerProviderLocation location;
|
||||
}
|
||||
|
|
|
@ -133,7 +133,7 @@ class SelectTypePage extends StatelessWidget {
|
|||
...(snapshot.data! as List<ServerType>).map(
|
||||
(final type) => InkWell(
|
||||
onTap: () {
|
||||
serverInstallationCubit.setServerType(type.identifier);
|
||||
serverInstallationCubit.setServerType(type);
|
||||
},
|
||||
child: Card(
|
||||
child: Padding(
|
||||
|
@ -153,7 +153,8 @@ class SelectTypePage extends StatelessWidget {
|
|||
const SizedBox(height: 8),
|
||||
Text('disk: $type.disk.gibibyte'),
|
||||
const SizedBox(height: 8),
|
||||
Text('price: $type.price.value $type.price.currency'),
|
||||
Text(
|
||||
'price: $type.price.value $type.price.currency'),
|
||||
],
|
||||
),
|
||||
],
|
||||
|
|
Loading…
Reference in a new issue