mirror of
https://git.selfprivacy.org/kherel/selfprivacy.org.app.git
synced 2025-01-23 09:16:54 +00:00
fix: Move DNS entries creation step to server provider layer
This commit is contained in:
parent
b242838339
commit
da4b38b787
|
@ -230,7 +230,6 @@ class ServerInstallationCubit extends Cubit<ServerInstallationState> {
|
|||
final ServerHostingDetails serverDetails,
|
||||
) async {
|
||||
await repository.saveServerDetails(serverDetails);
|
||||
// TODO dns;
|
||||
emit(
|
||||
(state as ServerInstallationNotFinished).copyWith(
|
||||
isLoading: false,
|
||||
|
@ -247,10 +246,12 @@ class ServerInstallationCubit extends Cubit<ServerInstallationState> {
|
|||
rootUser: state.rootUser!,
|
||||
dnsApiToken: state.dnsApiToken!,
|
||||
dnsProviderType: state.serverDomain!.provider,
|
||||
domainName: state.serverDomain!.domainName,
|
||||
serverDomain: state.serverDomain!,
|
||||
serverTypeId: state.serverTypeIdentificator!,
|
||||
errorCallback: clearAppConfig,
|
||||
successCallback: onCreateServerSuccess,
|
||||
dnsProviderApi:
|
||||
ApiController.currentDnsProviderApiFactory!.getDnsProvider(),
|
||||
);
|
||||
|
||||
final result =
|
||||
|
|
|
@ -1,3 +1,4 @@
|
|||
import 'package:selfprivacy/logic/api_maps/rest_maps/dns_providers/dns_provider.dart';
|
||||
import 'package:selfprivacy/logic/models/hive/server_details.dart';
|
||||
import 'package:selfprivacy/logic/models/hive/server_domain.dart';
|
||||
import 'package:selfprivacy/logic/models/hive/user.dart';
|
||||
|
@ -7,7 +8,8 @@ class LaunchInstallationData {
|
|||
required this.rootUser,
|
||||
required this.dnsApiToken,
|
||||
required this.dnsProviderType,
|
||||
required this.domainName,
|
||||
required this.dnsProviderApi,
|
||||
required this.serverDomain,
|
||||
required this.serverTypeId,
|
||||
required this.errorCallback,
|
||||
required this.successCallback,
|
||||
|
@ -15,8 +17,9 @@ class LaunchInstallationData {
|
|||
|
||||
final User rootUser;
|
||||
final String dnsApiToken;
|
||||
final String domainName;
|
||||
final ServerDomain serverDomain;
|
||||
final DnsProviderType dnsProviderType;
|
||||
final DnsProviderApi dnsProviderApi;
|
||||
final String serverTypeId;
|
||||
final Function() errorCallback;
|
||||
final Function(ServerHostingDetails details) successCallback;
|
||||
|
|
|
@ -135,11 +135,13 @@ class DigitalOceanServerProvider extends ServerProvider {
|
|||
) async {
|
||||
ServerHostingDetails? serverDetails;
|
||||
final serverApiToken = StringGenerators.apiToken();
|
||||
final hostname = getHostnameFromDomain(installationData.domainName);
|
||||
final hostname = getHostnameFromDomain(
|
||||
installationData.serverDomain.domainName,
|
||||
);
|
||||
final serverResult = await _adapter.api().createServer(
|
||||
dnsApiToken: installationData.dnsApiToken,
|
||||
rootUser: installationData.rootUser,
|
||||
domainName: installationData.domainName,
|
||||
domainName: installationData.serverDomain.domainName,
|
||||
serverType: installationData.serverTypeId,
|
||||
dnsProviderType:
|
||||
dnsProviderToInfectName(installationData.dnsProviderType),
|
||||
|
@ -308,6 +310,7 @@ class DigitalOceanServerProvider extends ServerProvider {
|
|||
return GenericResult(success: true, data: types);
|
||||
}
|
||||
|
||||
@override
|
||||
Future<GenericResult<List<ServerBasicInfo>>> getServers() async {
|
||||
final List<ServerBasicInfo> servers = [];
|
||||
final result = await _adapter.api().getServers();
|
||||
|
@ -345,6 +348,7 @@ class DigitalOceanServerProvider extends ServerProvider {
|
|||
return GenericResult(success: true, data: servers);
|
||||
}
|
||||
|
||||
@override
|
||||
Future<GenericResult<List<ServerMetadataEntity>>> getMetadata(
|
||||
final int serverId,
|
||||
) async {
|
||||
|
@ -547,6 +551,7 @@ class DigitalOceanServerProvider extends ServerProvider {
|
|||
);
|
||||
}
|
||||
|
||||
@override
|
||||
Future<GenericResult<CallbackDialogueBranching?>> deleteServer(
|
||||
final String hostname,
|
||||
) async {
|
||||
|
|
|
@ -437,12 +437,14 @@ class HetznerServerProvider extends ServerProvider {
|
|||
|
||||
final volume = volumeResult.data['volume'];
|
||||
final serverApiToken = StringGenerators.apiToken();
|
||||
final hostname = getHostnameFromDomain(installationData.domainName);
|
||||
final hostname = getHostnameFromDomain(
|
||||
installationData.serverDomain.domainName,
|
||||
);
|
||||
|
||||
final serverResult = await _adapter.api().createServer(
|
||||
dnsApiToken: installationData.dnsApiToken,
|
||||
rootUser: installationData.rootUser,
|
||||
domainName: installationData.domainName,
|
||||
domainName: installationData.serverDomain.domainName,
|
||||
serverType: installationData.serverTypeId,
|
||||
dnsProviderType:
|
||||
dnsProviderToInfectName(installationData.dnsProviderType),
|
||||
|
@ -535,7 +537,7 @@ class HetznerServerProvider extends ServerProvider {
|
|||
final createDnsResult = await _adapter.api().createReverseDns(
|
||||
serverId: serverDetails.id,
|
||||
ip4: serverDetails.ip4,
|
||||
dnsPtr: installationData.domainName,
|
||||
dnsPtr: installationData.serverDomain.domainName,
|
||||
);
|
||||
|
||||
if (!createDnsResult.success) {
|
||||
|
@ -578,6 +580,15 @@ class HetznerServerProvider extends ServerProvider {
|
|||
}
|
||||
|
||||
await installationData.successCallback(serverDetails);
|
||||
await installationData.dnsProviderApi.removeSimilarRecords(
|
||||
ip4: serverDetails.ip4,
|
||||
domain: installationData.serverDomain,
|
||||
);
|
||||
await installationData.dnsProviderApi.createMultipleDnsRecords(
|
||||
ip4: serverDetails.ip4,
|
||||
domain: installationData.serverDomain,
|
||||
);
|
||||
|
||||
return GenericResult(success: true, data: null);
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue