mirror of
https://git.selfprivacy.org/kherel/selfprivacy.org.app.git
synced 2024-11-18 06:39:14 +00:00
fix: Adapt usage of DNS provider interface to refactoring
This commit is contained in:
parent
b0769b8ed0
commit
d114d1477f
|
@ -19,7 +19,6 @@ class DigitalOceanDnsApi extends DnsProviderApi {
|
||||||
|
|
||||||
final String? customToken;
|
final String? customToken;
|
||||||
|
|
||||||
@override
|
|
||||||
RegExp getApiTokenValidation() =>
|
RegExp getApiTokenValidation() =>
|
||||||
RegExp(r'\s+|[!$%^&*()@+|~=`{}\[\]:<>?,.\/]');
|
RegExp(r'\s+|[!$%^&*()@+|~=`{}\[\]:<>?,.\/]');
|
||||||
|
|
||||||
|
@ -45,7 +44,6 @@ class DigitalOceanDnsApi extends DnsProviderApi {
|
||||||
@override
|
@override
|
||||||
String rootAddress = 'https://api.digitalocean.com/v2';
|
String rootAddress = 'https://api.digitalocean.com/v2';
|
||||||
|
|
||||||
@override
|
|
||||||
Future<GenericResult<bool>> isApiTokenValid(final String token) async {
|
Future<GenericResult<bool>> isApiTokenValid(final String token) async {
|
||||||
bool isValid = false;
|
bool isValid = false;
|
||||||
Response? response;
|
Response? response;
|
||||||
|
|
|
@ -25,14 +25,13 @@ class DnsRecordsCubit
|
||||||
emit(
|
emit(
|
||||||
DnsRecordsState(
|
DnsRecordsState(
|
||||||
dnsState: DnsRecordsStatus.refreshing,
|
dnsState: DnsRecordsStatus.refreshing,
|
||||||
dnsRecords: ApiController.currentDnsProviderApiFactory
|
dnsRecords:
|
||||||
?.getDnsProvider()
|
ProvidersController.currentDnsProvider?.getDesiredDnsRecords(
|
||||||
.getDesiredDnsRecords(
|
|
||||||
serverInstallationCubit.state.serverDomain?.domainName,
|
serverInstallationCubit.state.serverDomain?.domainName,
|
||||||
'',
|
'',
|
||||||
'',
|
'',
|
||||||
) ??
|
) ??
|
||||||
[],
|
[],
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
|
|
||||||
|
@ -45,13 +44,12 @@ class DnsRecordsCubit
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
final foundRecords = await ApiController.currentDnsProviderApiFactory!
|
final foundRecords =
|
||||||
.getDnsProvider()
|
await ProvidersController.currentDnsProvider!.validateDnsRecords(
|
||||||
.validateDnsRecords(
|
domain!,
|
||||||
domain!,
|
ipAddress!,
|
||||||
ipAddress!,
|
extractDkimRecord(await api.getDnsRecords())?.content ?? '',
|
||||||
extractDkimRecord(await api.getDnsRecords())?.content ?? '',
|
);
|
||||||
);
|
|
||||||
|
|
||||||
if (!foundRecords.success || foundRecords.data.isEmpty) {
|
if (!foundRecords.success || foundRecords.data.isEmpty) {
|
||||||
emit(const DnsRecordsState());
|
emit(const DnsRecordsState());
|
||||||
|
@ -89,10 +87,10 @@ class DnsRecordsCubit
|
||||||
emit(state.copyWith(dnsState: DnsRecordsStatus.refreshing));
|
emit(state.copyWith(dnsState: DnsRecordsStatus.refreshing));
|
||||||
final ServerDomain? domain = serverInstallationCubit.state.serverDomain;
|
final ServerDomain? domain = serverInstallationCubit.state.serverDomain;
|
||||||
final String? ipAddress = serverInstallationCubit.state.serverDetails?.ip4;
|
final String? ipAddress = serverInstallationCubit.state.serverDetails?.ip4;
|
||||||
await ProvidersController.currentDnsProvider!.removeSimilarRecords(
|
await ProvidersController.currentDnsProvider!.removeDomainRecords(
|
||||||
domain: domain!,
|
domain: domain!,
|
||||||
);
|
);
|
||||||
await ProvidersController.currentDnsProvider!.createMultipleDnsRecords(
|
await ProvidersController.currentDnsProvider!.createDomainRecords(
|
||||||
domain: domain,
|
domain: domain,
|
||||||
ip4: ipAddress,
|
ip4: ipAddress,
|
||||||
);
|
);
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
import 'package:cubit_form/cubit_form.dart';
|
import 'package:cubit_form/cubit_form.dart';
|
||||||
|
import 'package:selfprivacy/logic/api_maps/generic_result.dart';
|
||||||
import 'package:selfprivacy/logic/cubit/server_installation/server_installation_cubit.dart';
|
import 'package:selfprivacy/logic/cubit/server_installation/server_installation_cubit.dart';
|
||||||
import 'package:selfprivacy/logic/models/hive/server_domain.dart';
|
import 'package:selfprivacy/logic/models/hive/server_domain.dart';
|
||||||
import 'package:selfprivacy/logic/providers/providers_controller.dart';
|
import 'package:selfprivacy/logic/providers/providers_controller.dart';
|
||||||
|
@ -10,12 +11,12 @@ class DomainSetupCubit extends Cubit<DomainSetupState> {
|
||||||
|
|
||||||
Future<void> load() async {
|
Future<void> load() async {
|
||||||
emit(Loading(LoadingTypes.loadingDomain));
|
emit(Loading(LoadingTypes.loadingDomain));
|
||||||
final List<String> list =
|
final GenericResult<List<String>> result =
|
||||||
await ProvidersController.currentDnsProvider!.domainList();
|
await ProvidersController.currentDnsProvider!.domainList();
|
||||||
if (list.isEmpty) {
|
if (!result.success || result.data.isEmpty) {
|
||||||
emit(Empty());
|
emit(Empty());
|
||||||
} else if (list.length == 1) {
|
} else if (result.data.length == 1) {
|
||||||
emit(Loaded(list.first));
|
emit(Loaded(result.data.first));
|
||||||
} else {
|
} else {
|
||||||
emit(MoreThenOne());
|
emit(MoreThenOne());
|
||||||
}
|
}
|
||||||
|
@ -27,13 +28,13 @@ class DomainSetupCubit extends Cubit<DomainSetupState> {
|
||||||
|
|
||||||
emit(Loading(LoadingTypes.saving));
|
emit(Loading(LoadingTypes.saving));
|
||||||
|
|
||||||
final String? zoneId =
|
final GenericResult<String?> zoneIdResult =
|
||||||
await ProvidersController.currentDnsProvider!.getZoneId(domainName);
|
await ProvidersController.currentDnsProvider!.getZoneId(domainName);
|
||||||
|
|
||||||
if (zoneId != null) {
|
if (zoneIdResult.success || zoneIdResult.data != null) {
|
||||||
final ServerDomain domain = ServerDomain(
|
final ServerDomain domain = ServerDomain(
|
||||||
domainName: domainName,
|
domainName: domainName,
|
||||||
zoneId: zoneId,
|
zoneId: zoneIdResult.data!,
|
||||||
provider: DnsProviderType.cloudflare,
|
provider: DnsProviderType.cloudflare,
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|
|
@ -9,8 +9,6 @@ import 'package:selfprivacy/logic/models/callback_dialogue_branching.dart';
|
||||||
import 'package:selfprivacy/logic/models/launch_installation_data.dart';
|
import 'package:selfprivacy/logic/models/launch_installation_data.dart';
|
||||||
import 'package:selfprivacy/logic/providers/provider_settings.dart';
|
import 'package:selfprivacy/logic/providers/provider_settings.dart';
|
||||||
import 'package:selfprivacy/logic/providers/providers_controller.dart';
|
import 'package:selfprivacy/logic/providers/providers_controller.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.dart';
|
|
||||||
import 'package:selfprivacy/logic/api_maps/staging_options.dart';
|
import 'package:selfprivacy/logic/api_maps/staging_options.dart';
|
||||||
import 'package:selfprivacy/logic/models/hive/backblaze_credential.dart';
|
import 'package:selfprivacy/logic/models/hive/backblaze_credential.dart';
|
||||||
import 'package:selfprivacy/logic/models/hive/server_details.dart';
|
import 'package:selfprivacy/logic/models/hive/server_details.dart';
|
||||||
|
@ -258,7 +256,6 @@ class ServerInstallationCubit extends Cubit<ServerInstallationState> {
|
||||||
);
|
);
|
||||||
|
|
||||||
if (!result.success && result.data != null) {
|
if (!result.success && result.data != null) {
|
||||||
bool dialoguesResolved = false;
|
|
||||||
CallbackDialogueBranching branching = result.data!;
|
CallbackDialogueBranching branching = result.data!;
|
||||||
//while (!dialoguesResolved) {
|
//while (!dialoguesResolved) {
|
||||||
showPopUpAlert(
|
showPopUpAlert(
|
||||||
|
@ -268,7 +265,6 @@ class ServerInstallationCubit extends Cubit<ServerInstallationState> {
|
||||||
actionButtonOnPressed: () async {
|
actionButtonOnPressed: () async {
|
||||||
final branchingResult = await branching.choices[1].callback!();
|
final branchingResult = await branching.choices[1].callback!();
|
||||||
if (branchingResult.data == null) {
|
if (branchingResult.data == null) {
|
||||||
dialoguesResolved = true;
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -278,7 +274,6 @@ class ServerInstallationCubit extends Cubit<ServerInstallationState> {
|
||||||
cancelButtonOnPressed: () async {
|
cancelButtonOnPressed: () async {
|
||||||
final branchingResult = await branching.choices[0].callback!();
|
final branchingResult = await branching.choices[0].callback!();
|
||||||
if (branchingResult.data == null) {
|
if (branchingResult.data == null) {
|
||||||
dialoguesResolved = true;
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -12,8 +12,6 @@ import 'package:selfprivacy/config/get_it_config.dart';
|
||||||
import 'package:selfprivacy/config/hive_config.dart';
|
import 'package:selfprivacy/config/hive_config.dart';
|
||||||
import 'package:selfprivacy/logic/models/json/dns_records.dart';
|
import 'package:selfprivacy/logic/models/json/dns_records.dart';
|
||||||
import 'package:selfprivacy/logic/providers/provider_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';
|
import 'package:selfprivacy/logic/api_maps/graphql_maps/server_api/server_api.dart';
|
||||||
import 'package:selfprivacy/logic/api_maps/staging_options.dart';
|
import 'package:selfprivacy/logic/api_maps/staging_options.dart';
|
||||||
import 'package:selfprivacy/logic/cubit/server_installation/server_installation_cubit.dart';
|
import 'package:selfprivacy/logic/cubit/server_installation/server_installation_cubit.dart';
|
||||||
|
@ -173,16 +171,14 @@ class ServerInstallationRepository {
|
||||||
}
|
}
|
||||||
|
|
||||||
Future<String?> getDomainId(final String token, final String domain) async {
|
Future<String?> getDomainId(final String token, final String domain) async {
|
||||||
final DnsProviderApi dnsProviderApi =
|
final result =
|
||||||
ApiController.currentDnsProviderApiFactory!.getDnsProvider(
|
await ProvidersController.currentDnsProvider!.tryInitApiByToken(token);
|
||||||
settings: DnsProviderApiSettings(
|
return result.success
|
||||||
isWithToken: false,
|
? (await ProvidersController.currentDnsProvider!.getZoneId(
|
||||||
customToken: token,
|
domain,
|
||||||
),
|
))
|
||||||
);
|
.data
|
||||||
|
: null;
|
||||||
final String? domainId = await dnsProviderApi.getZoneId(domain);
|
|
||||||
return domainId;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Future<Map<String, bool>> isDnsAddressesMatch(
|
Future<Map<String, bool>> isDnsAddressesMatch(
|
||||||
|
@ -257,7 +253,7 @@ class ServerInstallationRepository {
|
||||||
}
|
}
|
||||||
|
|
||||||
final GenericResult removingResult =
|
final GenericResult removingResult =
|
||||||
await ProvidersController.currentDnsProvider!.removeSimilarRecords(
|
await ProvidersController.currentDnsProvider!.removeDomainRecords(
|
||||||
ip4: serverDetails.ip4,
|
ip4: serverDetails.ip4,
|
||||||
domain: domain,
|
domain: domain,
|
||||||
);
|
);
|
||||||
|
@ -270,9 +266,8 @@ class ServerInstallationRepository {
|
||||||
bool createdSuccessfully = false;
|
bool createdSuccessfully = false;
|
||||||
String errorMessage = 'domain.error'.tr();
|
String errorMessage = 'domain.error'.tr();
|
||||||
try {
|
try {
|
||||||
final GenericResult createResult = await ProvidersController
|
final GenericResult createResult =
|
||||||
.currentDnsProvider!
|
await ProvidersController.currentDnsProvider!.createDomainRecords(
|
||||||
.createMultipleDnsRecords(
|
|
||||||
ip4: serverDetails.ip4,
|
ip4: serverDetails.ip4,
|
||||||
domain: domain,
|
domain: domain,
|
||||||
);
|
);
|
||||||
|
@ -605,10 +600,6 @@ class ServerInstallationRepository {
|
||||||
getIt<ApiConfigModel>().init();
|
getIt<ApiConfigModel>().init();
|
||||||
}
|
}
|
||||||
|
|
||||||
Future<void> saveDnsProviderType(final DnsProvider type) async {
|
|
||||||
await getIt<ApiConfigModel>().storeDnsProviderType(type);
|
|
||||||
}
|
|
||||||
|
|
||||||
Future<void> saveBackblazeKey(
|
Future<void> saveBackblazeKey(
|
||||||
final BackblazeCredential backblazeCredential,
|
final BackblazeCredential backblazeCredential,
|
||||||
) async {
|
) async {
|
||||||
|
@ -683,7 +674,7 @@ class ServerInstallationRepository {
|
||||||
|
|
||||||
final GenericResult<void> removalResult = await ProvidersController
|
final GenericResult<void> removalResult = await ProvidersController
|
||||||
.currentDnsProvider!
|
.currentDnsProvider!
|
||||||
.removeSimilarRecords(domain: serverDomain);
|
.removeDomainRecords(domain: serverDomain);
|
||||||
|
|
||||||
if (!removalResult.success) {
|
if (!removalResult.success) {
|
||||||
getIt<NavigationService>().showSnackBar('modals.dns_removal_error'.tr());
|
getIt<NavigationService>().showSnackBar('modals.dns_removal_error'.tr());
|
||||||
|
|
|
@ -580,11 +580,11 @@ class HetznerServerProvider extends ServerProvider {
|
||||||
}
|
}
|
||||||
|
|
||||||
await installationData.successCallback(serverDetails);
|
await installationData.successCallback(serverDetails);
|
||||||
await installationData.dnsProvider.removeSimilarRecords(
|
await installationData.dnsProvider.removeDomainRecords(
|
||||||
ip4: serverDetails.ip4,
|
ip4: serverDetails.ip4,
|
||||||
domain: installationData.serverDomain,
|
domain: installationData.serverDomain,
|
||||||
);
|
);
|
||||||
await installationData.dnsProvider.createMultipleDnsRecords(
|
await installationData.dnsProvider.createDomainRecords(
|
||||||
ip4: serverDetails.ip4,
|
ip4: serverDetails.ip4,
|
||||||
domain: installationData.serverDomain,
|
domain: installationData.serverDomain,
|
||||||
);
|
);
|
||||||
|
|
|
@ -10,8 +10,6 @@ import 'package:selfprivacy/ui/components/brand_md/brand_md.dart';
|
||||||
import 'package:selfprivacy/ui/components/buttons/brand_button.dart';
|
import 'package:selfprivacy/ui/components/buttons/brand_button.dart';
|
||||||
import 'package:selfprivacy/ui/components/buttons/outlined_button.dart';
|
import 'package:selfprivacy/ui/components/buttons/outlined_button.dart';
|
||||||
import 'package:selfprivacy/ui/components/cards/outlined_card.dart';
|
import 'package:selfprivacy/ui/components/cards/outlined_card.dart';
|
||||||
import 'package:selfprivacy/utils/network_utils.dart';
|
|
||||||
import 'package:selfprivacy/utils/launch_url.dart';
|
|
||||||
import 'package:url_launcher/url_launcher_string.dart';
|
import 'package:url_launcher/url_launcher_string.dart';
|
||||||
|
|
||||||
class DnsProviderPicker extends StatefulWidget {
|
class DnsProviderPicker extends StatefulWidget {
|
||||||
|
|
|
@ -19,51 +19,45 @@ class RecoveryServerProviderConnected extends StatelessWidget {
|
||||||
create: (final BuildContext context) =>
|
create: (final BuildContext context) =>
|
||||||
ServerProviderFormCubit(appConfig),
|
ServerProviderFormCubit(appConfig),
|
||||||
child: Builder(
|
child: Builder(
|
||||||
builder: (final BuildContext context) {
|
builder: (final BuildContext context) => BrandHeroScreen(
|
||||||
final FormCubitState formCubitState =
|
heroTitle: 'recovering.server_provider_connected'.tr(),
|
||||||
context.watch<ServerProviderFormCubit>().state;
|
heroSubtitle: 'recovering.server_provider_connected_description'.tr(
|
||||||
|
args: [appConfig.state.serverDomain?.domainName ?? 'your domain'],
|
||||||
return BrandHeroScreen(
|
),
|
||||||
heroTitle: 'recovering.server_provider_connected'.tr(),
|
hasBackButton: true,
|
||||||
heroSubtitle: 'recovering.server_provider_connected_description'.tr(
|
hasFlashButton: false,
|
||||||
args: [appConfig.state.serverDomain?.domainName ?? 'your domain'],
|
ignoreBreakpoints: true,
|
||||||
|
hasSupportDrawer: true,
|
||||||
|
onBackButtonPressed: () {
|
||||||
|
Navigator.of(context).popUntil((final route) => route.isFirst);
|
||||||
|
},
|
||||||
|
children: [
|
||||||
|
CubitFormTextField(
|
||||||
|
formFieldCubit: context.read<ServerProviderFormCubit>().apiKey,
|
||||||
|
decoration: InputDecoration(
|
||||||
|
border: const OutlineInputBorder(),
|
||||||
|
labelText:
|
||||||
|
'recovering.server_provider_connected_placeholder'.tr(),
|
||||||
|
),
|
||||||
),
|
),
|
||||||
hasBackButton: true,
|
const SizedBox(height: 16),
|
||||||
hasFlashButton: false,
|
BrandButton.filled(
|
||||||
ignoreBreakpoints: true,
|
onPressed: () =>
|
||||||
hasSupportDrawer: true,
|
context.read<ServerProviderFormCubit>().trySubmit(),
|
||||||
onBackButtonPressed: () {
|
child: Text('basis.continue'.tr()),
|
||||||
Navigator.of(context).popUntil((final route) => route.isFirst);
|
),
|
||||||
},
|
const SizedBox(height: 16),
|
||||||
children: [
|
Builder(
|
||||||
CubitFormTextField(
|
builder: (final context) => BrandButton.text(
|
||||||
formFieldCubit: context.read<ServerProviderFormCubit>().apiKey,
|
title: 'initializing.how'.tr(),
|
||||||
decoration: InputDecoration(
|
onPressed: () => context.read<SupportSystemCubit>().showArticle(
|
||||||
border: const OutlineInputBorder(),
|
article: 'how_hetzner',
|
||||||
labelText:
|
context: context,
|
||||||
'recovering.server_provider_connected_placeholder'.tr(),
|
),
|
||||||
),
|
|
||||||
),
|
),
|
||||||
const SizedBox(height: 16),
|
),
|
||||||
BrandButton.filled(
|
],
|
||||||
onPressed: () =>
|
),
|
||||||
context.read<ServerProviderFormCubit>().trySubmit(),
|
|
||||||
child: Text('basis.continue'.tr()),
|
|
||||||
),
|
|
||||||
const SizedBox(height: 16),
|
|
||||||
Builder(
|
|
||||||
builder: (final context) => BrandButton.text(
|
|
||||||
title: 'initializing.how'.tr(),
|
|
||||||
onPressed: () =>
|
|
||||||
context.read<SupportSystemCubit>().showArticle(
|
|
||||||
article: 'how_hetzner',
|
|
||||||
context: context,
|
|
||||||
),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
],
|
|
||||||
);
|
|
||||||
},
|
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue