mirror of
https://git.selfprivacy.org/kherel/selfprivacy.org.app.git
synced 2024-11-20 11:29:14 +00:00
chore: Create infrastructure for Digital Ocean DNS provider
Also rename hardcoded cloudflare names from backend
This commit is contained in:
parent
968667e4bf
commit
18d3039dc4
|
@ -1,5 +1,6 @@
|
||||||
import 'package:selfprivacy/logic/api_maps/rest_maps/api_factory_settings.dart';
|
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/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';
|
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';
|
import 'package:selfprivacy/logic/api_maps/rest_maps/server_providers/digital_ocean/digital_ocean_factory.dart';
|
||||||
import 'package:selfprivacy/logic/api_maps/rest_maps/server_providers/hetzner/hetzner_factory.dart';
|
import 'package:selfprivacy/logic/api_maps/rest_maps/server_providers/hetzner/hetzner_factory.dart';
|
||||||
|
@ -32,6 +33,8 @@ class ApiFactoryCreator {
|
||||||
switch (settings.provider) {
|
switch (settings.provider) {
|
||||||
case DnsProvider.cloudflare:
|
case DnsProvider.cloudflare:
|
||||||
return CloudflareApiFactory();
|
return CloudflareApiFactory();
|
||||||
|
case DnsProvider.digitalOcean:
|
||||||
|
return DigitalOceanDnsApiFactory();
|
||||||
case DnsProvider.unknown:
|
case DnsProvider.unknown:
|
||||||
throw UnknownApiProviderException('Unknown DNS provider');
|
throw UnknownApiProviderException('Unknown DNS provider');
|
||||||
}
|
}
|
||||||
|
|
|
@ -27,7 +27,7 @@ class CloudflareApi extends DnsProviderApi {
|
||||||
BaseOptions get options {
|
BaseOptions get options {
|
||||||
final BaseOptions options = BaseOptions(baseUrl: rootAddress);
|
final BaseOptions options = BaseOptions(baseUrl: rootAddress);
|
||||||
if (isWithToken) {
|
if (isWithToken) {
|
||||||
final String? token = getIt<ApiConfigModel>().cloudFlareKey;
|
final String? token = getIt<ApiConfigModel>().dnsProviderKey;
|
||||||
assert(token != null);
|
assert(token != null);
|
||||||
options.headers = {'Authorization': 'Bearer $token'};
|
options.headers = {'Authorization': 'Bearer $token'};
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,304 @@
|
||||||
|
import 'dart:io';
|
||||||
|
|
||||||
|
import 'package:dio/dio.dart';
|
||||||
|
import 'package:selfprivacy/config/get_it_config.dart';
|
||||||
|
import 'package:selfprivacy/logic/api_maps/rest_maps/dns_providers/dns_provider.dart';
|
||||||
|
import 'package:selfprivacy/logic/models/hive/server_domain.dart';
|
||||||
|
import 'package:selfprivacy/logic/models/json/dns_records.dart';
|
||||||
|
|
||||||
|
class DigitalOceanDnsApi extends DnsProviderApi {
|
||||||
|
DigitalOceanDnsApi({
|
||||||
|
this.hasLogger = false,
|
||||||
|
this.isWithToken = true,
|
||||||
|
this.customToken,
|
||||||
|
});
|
||||||
|
@override
|
||||||
|
final bool hasLogger;
|
||||||
|
@override
|
||||||
|
final bool isWithToken;
|
||||||
|
|
||||||
|
final String? customToken;
|
||||||
|
|
||||||
|
@override
|
||||||
|
RegExp getApiTokenValidation() =>
|
||||||
|
RegExp(r'\s+|[!$%^&*()@+|~=`{}\[\]:<>?,.\/]');
|
||||||
|
|
||||||
|
@override
|
||||||
|
BaseOptions get options {
|
||||||
|
final BaseOptions options = BaseOptions(baseUrl: rootAddress);
|
||||||
|
if (isWithToken) {
|
||||||
|
final String? token = getIt<ApiConfigModel>().dnsProviderKey;
|
||||||
|
assert(token != null);
|
||||||
|
options.headers = {'Authorization': 'Bearer $token'};
|
||||||
|
}
|
||||||
|
|
||||||
|
if (customToken != null) {
|
||||||
|
options.headers = {'Authorization': 'Bearer $customToken'};
|
||||||
|
}
|
||||||
|
|
||||||
|
if (validateStatus != null) {
|
||||||
|
options.validateStatus = validateStatus!;
|
||||||
|
}
|
||||||
|
return options;
|
||||||
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
String rootAddress = 'https://api.digitalocean.com/v2';
|
||||||
|
|
||||||
|
@override
|
||||||
|
Future<APIGenericResult<bool>> isApiTokenValid(final String token) async {
|
||||||
|
bool isValid = false;
|
||||||
|
Response? response;
|
||||||
|
String message = '';
|
||||||
|
final Dio client = await getClient();
|
||||||
|
try {
|
||||||
|
response = await client.get(
|
||||||
|
'/account',
|
||||||
|
options: Options(
|
||||||
|
followRedirects: false,
|
||||||
|
validateStatus: (final status) =>
|
||||||
|
status != null && (status >= 200 || status == 401),
|
||||||
|
headers: {'Authorization': 'Bearer $token'},
|
||||||
|
),
|
||||||
|
);
|
||||||
|
} catch (e) {
|
||||||
|
print(e);
|
||||||
|
isValid = false;
|
||||||
|
message = e.toString();
|
||||||
|
} finally {
|
||||||
|
close(client);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (response == null) {
|
||||||
|
return APIGenericResult(
|
||||||
|
data: isValid,
|
||||||
|
success: false,
|
||||||
|
message: message,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (response.statusCode == HttpStatus.ok) {
|
||||||
|
isValid = true;
|
||||||
|
} else if (response.statusCode == HttpStatus.unauthorized) {
|
||||||
|
isValid = false;
|
||||||
|
} else {
|
||||||
|
throw Exception('code: ${response.statusCode}');
|
||||||
|
}
|
||||||
|
|
||||||
|
return APIGenericResult(
|
||||||
|
data: isValid,
|
||||||
|
success: true,
|
||||||
|
message: response.statusMessage,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
// TODO: Remove from DnsProviderInterface, stub for now
|
||||||
|
Future<String?> getZoneId(final String domain) async => domain;
|
||||||
|
|
||||||
|
@override
|
||||||
|
Future<APIGenericResult<void>> removeSimilarRecords({
|
||||||
|
required final ServerDomain domain,
|
||||||
|
final String? ip4,
|
||||||
|
}) async {
|
||||||
|
final String domainName = domain.domainName;
|
||||||
|
final String domainZoneId = domain.zoneId;
|
||||||
|
|
||||||
|
final String url = '/zones/$domainZoneId/dns_records';
|
||||||
|
|
||||||
|
final Dio client = await getClient();
|
||||||
|
try {
|
||||||
|
final Response response = await client.get(url);
|
||||||
|
|
||||||
|
final List records = response.data['result'] ?? [];
|
||||||
|
final List<Future> allDeleteFutures = <Future>[];
|
||||||
|
|
||||||
|
for (final record in records) {
|
||||||
|
if (record['zone_name'] == domainName) {
|
||||||
|
allDeleteFutures.add(
|
||||||
|
client.delete('$url/${record["id"]}'),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
await Future.wait(allDeleteFutures);
|
||||||
|
} catch (e) {
|
||||||
|
print(e);
|
||||||
|
return APIGenericResult(
|
||||||
|
success: false,
|
||||||
|
data: null,
|
||||||
|
message: e.toString(),
|
||||||
|
);
|
||||||
|
} finally {
|
||||||
|
close(client);
|
||||||
|
}
|
||||||
|
|
||||||
|
return APIGenericResult(success: true, data: null);
|
||||||
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
Future<List<DnsRecord>> getDnsRecords({
|
||||||
|
required final ServerDomain domain,
|
||||||
|
}) async {
|
||||||
|
Response response;
|
||||||
|
final String domainName = domain.domainName;
|
||||||
|
final String domainZoneId = domain.zoneId;
|
||||||
|
final List<DnsRecord> allRecords = <DnsRecord>[];
|
||||||
|
|
||||||
|
final String url = '/zones/$domainZoneId/dns_records';
|
||||||
|
|
||||||
|
final Dio client = await getClient();
|
||||||
|
try {
|
||||||
|
response = await client.get(url);
|
||||||
|
final List records = response.data['result'] ?? [];
|
||||||
|
|
||||||
|
for (final record in records) {
|
||||||
|
if (record['zone_name'] == domainName) {
|
||||||
|
allRecords.add(
|
||||||
|
DnsRecord(
|
||||||
|
name: record['name'],
|
||||||
|
type: record['type'],
|
||||||
|
content: record['content'],
|
||||||
|
ttl: record['ttl'],
|
||||||
|
proxied: record['proxied'],
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} catch (e) {
|
||||||
|
print(e);
|
||||||
|
} finally {
|
||||||
|
close(client);
|
||||||
|
}
|
||||||
|
|
||||||
|
return allRecords;
|
||||||
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
Future<APIGenericResult<void>> createMultipleDnsRecords({
|
||||||
|
required final ServerDomain domain,
|
||||||
|
final String? ip4,
|
||||||
|
}) async {
|
||||||
|
final String domainName = domain.domainName;
|
||||||
|
final String domainZoneId = domain.zoneId;
|
||||||
|
final List<DnsRecord> listDnsRecords = projectDnsRecords(domainName, ip4);
|
||||||
|
final List<Future> allCreateFutures = <Future>[];
|
||||||
|
|
||||||
|
final Dio client = await getClient();
|
||||||
|
try {
|
||||||
|
for (final DnsRecord record in listDnsRecords) {
|
||||||
|
allCreateFutures.add(
|
||||||
|
client.post(
|
||||||
|
'/zones/$domainZoneId/dns_records',
|
||||||
|
data: record.toJson(),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
await Future.wait(allCreateFutures);
|
||||||
|
} on DioError catch (e) {
|
||||||
|
print(e.message);
|
||||||
|
rethrow;
|
||||||
|
} catch (e) {
|
||||||
|
print(e);
|
||||||
|
return APIGenericResult(
|
||||||
|
success: false,
|
||||||
|
data: null,
|
||||||
|
message: e.toString(),
|
||||||
|
);
|
||||||
|
} finally {
|
||||||
|
close(client);
|
||||||
|
}
|
||||||
|
|
||||||
|
return APIGenericResult(success: true, data: null);
|
||||||
|
}
|
||||||
|
|
||||||
|
List<DnsRecord> projectDnsRecords(
|
||||||
|
final String? domainName,
|
||||||
|
final String? ip4,
|
||||||
|
) {
|
||||||
|
final DnsRecord domainA =
|
||||||
|
DnsRecord(type: 'A', name: domainName, content: ip4);
|
||||||
|
|
||||||
|
final DnsRecord mx = DnsRecord(type: 'MX', name: '@', content: domainName);
|
||||||
|
final DnsRecord apiA = DnsRecord(type: 'A', name: 'api', content: ip4);
|
||||||
|
final DnsRecord cloudA = DnsRecord(type: 'A', name: 'cloud', content: ip4);
|
||||||
|
final DnsRecord gitA = DnsRecord(type: 'A', name: 'git', content: ip4);
|
||||||
|
final DnsRecord meetA = DnsRecord(type: 'A', name: 'meet', content: ip4);
|
||||||
|
final DnsRecord passwordA =
|
||||||
|
DnsRecord(type: 'A', name: 'password', content: ip4);
|
||||||
|
final DnsRecord socialA =
|
||||||
|
DnsRecord(type: 'A', name: 'social', content: ip4);
|
||||||
|
final DnsRecord vpn = DnsRecord(type: 'A', name: 'vpn', content: ip4);
|
||||||
|
|
||||||
|
final DnsRecord txt1 = DnsRecord(
|
||||||
|
type: 'TXT',
|
||||||
|
name: '_dmarc',
|
||||||
|
content: 'v=DMARC1; p=none',
|
||||||
|
ttl: 18000,
|
||||||
|
);
|
||||||
|
|
||||||
|
final DnsRecord txt2 = DnsRecord(
|
||||||
|
type: 'TXT',
|
||||||
|
name: domainName,
|
||||||
|
content: 'v=spf1 a mx ip4:$ip4 -all',
|
||||||
|
ttl: 18000,
|
||||||
|
);
|
||||||
|
|
||||||
|
return <DnsRecord>[
|
||||||
|
domainA,
|
||||||
|
apiA,
|
||||||
|
cloudA,
|
||||||
|
gitA,
|
||||||
|
meetA,
|
||||||
|
passwordA,
|
||||||
|
socialA,
|
||||||
|
mx,
|
||||||
|
txt1,
|
||||||
|
txt2,
|
||||||
|
vpn
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
Future<void> setDnsRecord(
|
||||||
|
final DnsRecord record,
|
||||||
|
final ServerDomain domain,
|
||||||
|
) async {
|
||||||
|
final String domainZoneId = domain.zoneId;
|
||||||
|
final String url = '$rootAddress/zones/$domainZoneId/dns_records';
|
||||||
|
|
||||||
|
final Dio client = await getClient();
|
||||||
|
try {
|
||||||
|
await client.post(
|
||||||
|
url,
|
||||||
|
data: record.toJson(),
|
||||||
|
);
|
||||||
|
} catch (e) {
|
||||||
|
print(e);
|
||||||
|
} finally {
|
||||||
|
close(client);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
Future<List<String>> domainList() async {
|
||||||
|
final String url = '$rootAddress/zones';
|
||||||
|
List<String> domains = [];
|
||||||
|
|
||||||
|
final Dio client = await getClient();
|
||||||
|
try {
|
||||||
|
final Response response = await client.get(
|
||||||
|
url,
|
||||||
|
queryParameters: {'per_page': 50},
|
||||||
|
);
|
||||||
|
domains = response.data['result']
|
||||||
|
.map<String>((final el) => el['name'] as String)
|
||||||
|
.toList();
|
||||||
|
} catch (e) {
|
||||||
|
print(e);
|
||||||
|
} finally {
|
||||||
|
close(client);
|
||||||
|
}
|
||||||
|
|
||||||
|
return domains;
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,16 @@
|
||||||
|
import 'package:selfprivacy/logic/api_maps/rest_maps/dns_providers/digital_ocean_dns/digital_ocean_dns.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';
|
||||||
|
|
||||||
|
class DigitalOceanDnsApiFactory extends DnsProviderApiFactory {
|
||||||
|
@override
|
||||||
|
DnsProviderApi getDnsProvider({
|
||||||
|
final DnsProviderApiSettings settings = const DnsProviderApiSettings(),
|
||||||
|
}) =>
|
||||||
|
DigitalOceanDnsApi(
|
||||||
|
hasLogger: settings.hasLogger,
|
||||||
|
isWithToken: settings.isWithToken,
|
||||||
|
customToken: settings.customToken,
|
||||||
|
);
|
||||||
|
}
|
|
@ -20,7 +20,7 @@ class DnsProviderFormCubit extends FormCubit {
|
||||||
|
|
||||||
@override
|
@override
|
||||||
FutureOr<void> onSubmit() async {
|
FutureOr<void> onSubmit() async {
|
||||||
initializingCubit.setCloudflareKey(apiKey.state.value);
|
initializingCubit.setDnsApiToken(apiKey.state.value);
|
||||||
}
|
}
|
||||||
|
|
||||||
final ServerInstallationCubit initializingCubit;
|
final ServerInstallationCubit initializingCubit;
|
||||||
|
|
|
@ -214,16 +214,16 @@ class ServerInstallationCubit extends Cubit<ServerInstallationState> {
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
void setCloudflareKey(final String cloudFlareKey) async {
|
void setDnsApiToken(final String dnsApiToken) async {
|
||||||
if (state is ServerInstallationRecovery) {
|
if (state is ServerInstallationRecovery) {
|
||||||
setAndValidateCloudflareToken(cloudFlareKey);
|
setAndValidateCloudflareToken(dnsApiToken);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
await repository.saveCloudFlareKey(cloudFlareKey);
|
await repository.setDnsApiToken(dnsApiToken);
|
||||||
|
|
||||||
emit(
|
emit(
|
||||||
(state as ServerInstallationNotFinished)
|
(state as ServerInstallationNotFinished)
|
||||||
.copyWith(cloudFlareKey: cloudFlareKey),
|
.copyWith(dnsApiToken: dnsApiToken),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -284,7 +284,7 @@ class ServerInstallationCubit extends Cubit<ServerInstallationState> {
|
||||||
await repository.createServer(
|
await repository.createServer(
|
||||||
state.rootUser!,
|
state.rootUser!,
|
||||||
state.serverDomain!.domainName,
|
state.serverDomain!.domainName,
|
||||||
state.cloudFlareKey!,
|
state.dnsApiToken!,
|
||||||
state.backblazeCredential!,
|
state.backblazeCredential!,
|
||||||
onCancel: onCancel,
|
onCancel: onCancel,
|
||||||
onSuccess: onSuccess,
|
onSuccess: onSuccess,
|
||||||
|
@ -586,7 +586,7 @@ class ServerInstallationCubit extends Cubit<ServerInstallationState> {
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
break;
|
break;
|
||||||
case RecoveryStep.cloudflareToken:
|
case RecoveryStep.dnsProviderToken:
|
||||||
repository.deleteServerDetails();
|
repository.deleteServerDetails();
|
||||||
emit(
|
emit(
|
||||||
dataState.copyWith(
|
dataState.copyWith(
|
||||||
|
@ -673,7 +673,7 @@ class ServerInstallationCubit extends Cubit<ServerInstallationState> {
|
||||||
emit(
|
emit(
|
||||||
dataState.copyWith(
|
dataState.copyWith(
|
||||||
serverDetails: serverDetails,
|
serverDetails: serverDetails,
|
||||||
currentStep: RecoveryStep.cloudflareToken,
|
currentStep: RecoveryStep.dnsProviderToken,
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
@ -699,7 +699,7 @@ class ServerInstallationCubit extends Cubit<ServerInstallationState> {
|
||||||
provider: DnsProvider.cloudflare,
|
provider: DnsProvider.cloudflare,
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
await repository.saveCloudFlareKey(token);
|
await repository.setDnsApiToken(token);
|
||||||
emit(
|
emit(
|
||||||
dataState.copyWith(
|
dataState.copyWith(
|
||||||
serverDomain: ServerDomain(
|
serverDomain: ServerDomain(
|
||||||
|
@ -707,7 +707,7 @@ class ServerInstallationCubit extends Cubit<ServerInstallationState> {
|
||||||
zoneId: zoneId,
|
zoneId: zoneId,
|
||||||
provider: DnsProvider.cloudflare,
|
provider: DnsProvider.cloudflare,
|
||||||
),
|
),
|
||||||
cloudFlareKey: token,
|
dnsApiToken: token,
|
||||||
currentStep: RecoveryStep.backblazeToken,
|
currentStep: RecoveryStep.backblazeToken,
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
|
@ -754,7 +754,7 @@ class ServerInstallationCubit extends Cubit<ServerInstallationState> {
|
||||||
ServerInstallationNotFinished(
|
ServerInstallationNotFinished(
|
||||||
providerApiToken: state.providerApiToken,
|
providerApiToken: state.providerApiToken,
|
||||||
serverDomain: state.serverDomain,
|
serverDomain: state.serverDomain,
|
||||||
cloudFlareKey: state.cloudFlareKey,
|
dnsApiToken: state.dnsApiToken,
|
||||||
backblazeCredential: state.backblazeCredential,
|
backblazeCredential: state.backblazeCredential,
|
||||||
rootUser: state.rootUser,
|
rootUser: state.rootUser,
|
||||||
serverDetails: null,
|
serverDetails: null,
|
||||||
|
|
|
@ -45,7 +45,7 @@ class ServerInstallationRepository {
|
||||||
Future<ServerInstallationState> load() async {
|
Future<ServerInstallationState> load() async {
|
||||||
final String? providerApiToken = getIt<ApiConfigModel>().serverProviderKey;
|
final String? providerApiToken = getIt<ApiConfigModel>().serverProviderKey;
|
||||||
final String? location = getIt<ApiConfigModel>().serverLocation;
|
final String? location = getIt<ApiConfigModel>().serverLocation;
|
||||||
final String? cloudflareToken = getIt<ApiConfigModel>().cloudFlareKey;
|
final String? cloudflareToken = getIt<ApiConfigModel>().dnsProviderKey;
|
||||||
final String? serverTypeIdentificator = getIt<ApiConfigModel>().serverType;
|
final String? serverTypeIdentificator = getIt<ApiConfigModel>().serverType;
|
||||||
final ServerDomain? serverDomain = getIt<ApiConfigModel>().serverDomain;
|
final ServerDomain? serverDomain = getIt<ApiConfigModel>().serverDomain;
|
||||||
final ServerProvider? serverProvider =
|
final ServerProvider? serverProvider =
|
||||||
|
@ -86,7 +86,7 @@ class ServerInstallationRepository {
|
||||||
return ServerInstallationFinished(
|
return ServerInstallationFinished(
|
||||||
providerApiToken: providerApiToken!,
|
providerApiToken: providerApiToken!,
|
||||||
serverTypeIdentificator: serverTypeIdentificator ?? '',
|
serverTypeIdentificator: serverTypeIdentificator ?? '',
|
||||||
cloudFlareKey: cloudflareToken!,
|
dnsApiToken: cloudflareToken!,
|
||||||
serverDomain: serverDomain!,
|
serverDomain: serverDomain!,
|
||||||
backblazeCredential: backblazeCredential!,
|
backblazeCredential: backblazeCredential!,
|
||||||
serverDetails: serverDetails!,
|
serverDetails: serverDetails!,
|
||||||
|
@ -103,7 +103,7 @@ class ServerInstallationRepository {
|
||||||
serverDomain != null) {
|
serverDomain != null) {
|
||||||
return ServerInstallationRecovery(
|
return ServerInstallationRecovery(
|
||||||
providerApiToken: providerApiToken,
|
providerApiToken: providerApiToken,
|
||||||
cloudFlareKey: cloudflareToken,
|
dnsApiToken: cloudflareToken,
|
||||||
serverDomain: serverDomain,
|
serverDomain: serverDomain,
|
||||||
backblazeCredential: backblazeCredential,
|
backblazeCredential: backblazeCredential,
|
||||||
serverDetails: serverDetails,
|
serverDetails: serverDetails,
|
||||||
|
@ -120,7 +120,7 @@ class ServerInstallationRepository {
|
||||||
|
|
||||||
return ServerInstallationNotFinished(
|
return ServerInstallationNotFinished(
|
||||||
providerApiToken: providerApiToken,
|
providerApiToken: providerApiToken,
|
||||||
cloudFlareKey: cloudflareToken,
|
dnsApiToken: cloudflareToken,
|
||||||
serverDomain: serverDomain,
|
serverDomain: serverDomain,
|
||||||
backblazeCredential: backblazeCredential,
|
backblazeCredential: backblazeCredential,
|
||||||
serverDetails: serverDetails,
|
serverDetails: serverDetails,
|
||||||
|
@ -147,7 +147,7 @@ class ServerInstallationRepository {
|
||||||
if (serverDomain.provider != DnsProvider.unknown) {
|
if (serverDomain.provider != DnsProvider.unknown) {
|
||||||
return RecoveryStep.backblazeToken;
|
return RecoveryStep.backblazeToken;
|
||||||
}
|
}
|
||||||
return RecoveryStep.cloudflareToken;
|
return RecoveryStep.dnsProviderToken;
|
||||||
}
|
}
|
||||||
return RecoveryStep.serverSelection;
|
return RecoveryStep.serverSelection;
|
||||||
}
|
}
|
||||||
|
@ -717,8 +717,8 @@ class ServerInstallationRepository {
|
||||||
getIt<ApiConfigModel>().init();
|
getIt<ApiConfigModel>().init();
|
||||||
}
|
}
|
||||||
|
|
||||||
Future<void> saveCloudFlareKey(final String key) async {
|
Future<void> setDnsApiToken(final String key) async {
|
||||||
await getIt<ApiConfigModel>().storeCloudFlareKey(key);
|
await getIt<ApiConfigModel>().storeDnsProviderKey(key);
|
||||||
}
|
}
|
||||||
|
|
||||||
Future<void> deleteCloudFlareKey() async {
|
Future<void> deleteCloudFlareKey() async {
|
||||||
|
|
|
@ -4,7 +4,7 @@ abstract class ServerInstallationState extends Equatable {
|
||||||
const ServerInstallationState({
|
const ServerInstallationState({
|
||||||
required this.providerApiToken,
|
required this.providerApiToken,
|
||||||
required this.serverTypeIdentificator,
|
required this.serverTypeIdentificator,
|
||||||
required this.cloudFlareKey,
|
required this.dnsApiToken,
|
||||||
required this.backblazeCredential,
|
required this.backblazeCredential,
|
||||||
required this.serverDomain,
|
required this.serverDomain,
|
||||||
required this.rootUser,
|
required this.rootUser,
|
||||||
|
@ -18,7 +18,7 @@ abstract class ServerInstallationState extends Equatable {
|
||||||
List<Object?> get props => [
|
List<Object?> get props => [
|
||||||
providerApiToken,
|
providerApiToken,
|
||||||
serverTypeIdentificator,
|
serverTypeIdentificator,
|
||||||
cloudFlareKey,
|
dnsApiToken,
|
||||||
backblazeCredential,
|
backblazeCredential,
|
||||||
serverDomain,
|
serverDomain,
|
||||||
rootUser,
|
rootUser,
|
||||||
|
@ -28,7 +28,7 @@ abstract class ServerInstallationState extends Equatable {
|
||||||
];
|
];
|
||||||
|
|
||||||
final String? providerApiToken;
|
final String? providerApiToken;
|
||||||
final String? cloudFlareKey;
|
final String? dnsApiToken;
|
||||||
final String? serverTypeIdentificator;
|
final String? serverTypeIdentificator;
|
||||||
final BackblazeCredential? backblazeCredential;
|
final BackblazeCredential? backblazeCredential;
|
||||||
final ServerDomain? serverDomain;
|
final ServerDomain? serverDomain;
|
||||||
|
@ -40,7 +40,7 @@ abstract class ServerInstallationState extends Equatable {
|
||||||
|
|
||||||
bool get isServerProviderApiKeyFilled => providerApiToken != null;
|
bool get isServerProviderApiKeyFilled => providerApiToken != null;
|
||||||
bool get isServerTypeFilled => serverTypeIdentificator != null;
|
bool get isServerTypeFilled => serverTypeIdentificator != null;
|
||||||
bool get isDnsProviderFilled => cloudFlareKey != null;
|
bool get isDnsProviderFilled => dnsApiToken != null;
|
||||||
bool get isBackupsProviderFilled => backblazeCredential != null;
|
bool get isBackupsProviderFilled => backblazeCredential != null;
|
||||||
bool get isDomainSelected => serverDomain != null;
|
bool get isDomainSelected => serverDomain != null;
|
||||||
bool get isPrimaryUserFilled => rootUser != null;
|
bool get isPrimaryUserFilled => rootUser != null;
|
||||||
|
@ -87,7 +87,7 @@ class TimerState extends ServerInstallationNotFinished {
|
||||||
}) : super(
|
}) : super(
|
||||||
providerApiToken: dataState.providerApiToken,
|
providerApiToken: dataState.providerApiToken,
|
||||||
serverTypeIdentificator: dataState.serverTypeIdentificator,
|
serverTypeIdentificator: dataState.serverTypeIdentificator,
|
||||||
cloudFlareKey: dataState.cloudFlareKey,
|
dnsApiToken: dataState.dnsApiToken,
|
||||||
backblazeCredential: dataState.backblazeCredential,
|
backblazeCredential: dataState.backblazeCredential,
|
||||||
serverDomain: dataState.serverDomain,
|
serverDomain: dataState.serverDomain,
|
||||||
rootUser: dataState.rootUser,
|
rootUser: dataState.rootUser,
|
||||||
|
@ -114,7 +114,7 @@ enum ServerSetupProgress {
|
||||||
nothingYet,
|
nothingYet,
|
||||||
serverProviderFilled,
|
serverProviderFilled,
|
||||||
servertTypeFilled,
|
servertTypeFilled,
|
||||||
cloudFlareFilled,
|
dnsProviderFilled,
|
||||||
backblazeFilled,
|
backblazeFilled,
|
||||||
domainFilled,
|
domainFilled,
|
||||||
userFilled,
|
userFilled,
|
||||||
|
@ -133,7 +133,7 @@ class ServerInstallationNotFinished extends ServerInstallationState {
|
||||||
required this.dnsMatches,
|
required this.dnsMatches,
|
||||||
super.providerApiToken,
|
super.providerApiToken,
|
||||||
super.serverTypeIdentificator,
|
super.serverTypeIdentificator,
|
||||||
super.cloudFlareKey,
|
super.dnsApiToken,
|
||||||
super.backblazeCredential,
|
super.backblazeCredential,
|
||||||
super.serverDomain,
|
super.serverDomain,
|
||||||
super.rootUser,
|
super.rootUser,
|
||||||
|
@ -146,7 +146,7 @@ class ServerInstallationNotFinished extends ServerInstallationState {
|
||||||
List<Object?> get props => [
|
List<Object?> get props => [
|
||||||
providerApiToken,
|
providerApiToken,
|
||||||
serverTypeIdentificator,
|
serverTypeIdentificator,
|
||||||
cloudFlareKey,
|
dnsApiToken,
|
||||||
backblazeCredential,
|
backblazeCredential,
|
||||||
serverDomain,
|
serverDomain,
|
||||||
rootUser,
|
rootUser,
|
||||||
|
@ -160,7 +160,7 @@ class ServerInstallationNotFinished extends ServerInstallationState {
|
||||||
ServerInstallationNotFinished copyWith({
|
ServerInstallationNotFinished copyWith({
|
||||||
final String? providerApiToken,
|
final String? providerApiToken,
|
||||||
final String? serverTypeIdentificator,
|
final String? serverTypeIdentificator,
|
||||||
final String? cloudFlareKey,
|
final String? dnsApiToken,
|
||||||
final BackblazeCredential? backblazeCredential,
|
final BackblazeCredential? backblazeCredential,
|
||||||
final ServerDomain? serverDomain,
|
final ServerDomain? serverDomain,
|
||||||
final User? rootUser,
|
final User? rootUser,
|
||||||
|
@ -175,7 +175,7 @@ class ServerInstallationNotFinished extends ServerInstallationState {
|
||||||
providerApiToken: providerApiToken ?? this.providerApiToken,
|
providerApiToken: providerApiToken ?? this.providerApiToken,
|
||||||
serverTypeIdentificator:
|
serverTypeIdentificator:
|
||||||
serverTypeIdentificator ?? this.serverTypeIdentificator,
|
serverTypeIdentificator ?? this.serverTypeIdentificator,
|
||||||
cloudFlareKey: cloudFlareKey ?? this.cloudFlareKey,
|
dnsApiToken: dnsApiToken ?? this.dnsApiToken,
|
||||||
backblazeCredential: backblazeCredential ?? this.backblazeCredential,
|
backblazeCredential: backblazeCredential ?? this.backblazeCredential,
|
||||||
serverDomain: serverDomain ?? this.serverDomain,
|
serverDomain: serverDomain ?? this.serverDomain,
|
||||||
rootUser: rootUser ?? this.rootUser,
|
rootUser: rootUser ?? this.rootUser,
|
||||||
|
@ -192,7 +192,7 @@ class ServerInstallationNotFinished extends ServerInstallationState {
|
||||||
ServerInstallationFinished finish() => ServerInstallationFinished(
|
ServerInstallationFinished finish() => ServerInstallationFinished(
|
||||||
providerApiToken: providerApiToken!,
|
providerApiToken: providerApiToken!,
|
||||||
serverTypeIdentificator: serverTypeIdentificator ?? '',
|
serverTypeIdentificator: serverTypeIdentificator ?? '',
|
||||||
cloudFlareKey: cloudFlareKey!,
|
dnsApiToken: dnsApiToken!,
|
||||||
backblazeCredential: backblazeCredential!,
|
backblazeCredential: backblazeCredential!,
|
||||||
serverDomain: serverDomain!,
|
serverDomain: serverDomain!,
|
||||||
rootUser: rootUser!,
|
rootUser: rootUser!,
|
||||||
|
@ -208,7 +208,7 @@ class ServerInstallationEmpty extends ServerInstallationNotFinished {
|
||||||
: super(
|
: super(
|
||||||
providerApiToken: null,
|
providerApiToken: null,
|
||||||
serverTypeIdentificator: null,
|
serverTypeIdentificator: null,
|
||||||
cloudFlareKey: null,
|
dnsApiToken: null,
|
||||||
backblazeCredential: null,
|
backblazeCredential: null,
|
||||||
serverDomain: null,
|
serverDomain: null,
|
||||||
rootUser: null,
|
rootUser: null,
|
||||||
|
@ -225,7 +225,7 @@ class ServerInstallationFinished extends ServerInstallationState {
|
||||||
const ServerInstallationFinished({
|
const ServerInstallationFinished({
|
||||||
required String super.providerApiToken,
|
required String super.providerApiToken,
|
||||||
required String super.serverTypeIdentificator,
|
required String super.serverTypeIdentificator,
|
||||||
required String super.cloudFlareKey,
|
required String super.dnsApiToken,
|
||||||
required BackblazeCredential super.backblazeCredential,
|
required BackblazeCredential super.backblazeCredential,
|
||||||
required ServerDomain super.serverDomain,
|
required ServerDomain super.serverDomain,
|
||||||
required User super.rootUser,
|
required User super.rootUser,
|
||||||
|
@ -239,7 +239,7 @@ class ServerInstallationFinished extends ServerInstallationState {
|
||||||
List<Object?> get props => [
|
List<Object?> get props => [
|
||||||
providerApiToken,
|
providerApiToken,
|
||||||
serverTypeIdentificator,
|
serverTypeIdentificator,
|
||||||
cloudFlareKey,
|
dnsApiToken,
|
||||||
backblazeCredential,
|
backblazeCredential,
|
||||||
serverDomain,
|
serverDomain,
|
||||||
rootUser,
|
rootUser,
|
||||||
|
@ -256,7 +256,7 @@ enum RecoveryStep {
|
||||||
oldToken,
|
oldToken,
|
||||||
serverProviderToken,
|
serverProviderToken,
|
||||||
serverSelection,
|
serverSelection,
|
||||||
cloudflareToken,
|
dnsProviderToken,
|
||||||
backblazeToken,
|
backblazeToken,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -278,7 +278,7 @@ class ServerInstallationRecovery extends ServerInstallationState {
|
||||||
required this.recoveryCapabilities,
|
required this.recoveryCapabilities,
|
||||||
super.providerApiToken,
|
super.providerApiToken,
|
||||||
super.serverTypeIdentificator,
|
super.serverTypeIdentificator,
|
||||||
super.cloudFlareKey,
|
super.dnsApiToken,
|
||||||
super.backblazeCredential,
|
super.backblazeCredential,
|
||||||
super.serverDomain,
|
super.serverDomain,
|
||||||
super.rootUser,
|
super.rootUser,
|
||||||
|
@ -295,7 +295,7 @@ class ServerInstallationRecovery extends ServerInstallationState {
|
||||||
List<Object?> get props => [
|
List<Object?> get props => [
|
||||||
providerApiToken,
|
providerApiToken,
|
||||||
serverTypeIdentificator,
|
serverTypeIdentificator,
|
||||||
cloudFlareKey,
|
dnsApiToken,
|
||||||
backblazeCredential,
|
backblazeCredential,
|
||||||
serverDomain,
|
serverDomain,
|
||||||
rootUser,
|
rootUser,
|
||||||
|
@ -308,7 +308,7 @@ class ServerInstallationRecovery extends ServerInstallationState {
|
||||||
ServerInstallationRecovery copyWith({
|
ServerInstallationRecovery copyWith({
|
||||||
final String? providerApiToken,
|
final String? providerApiToken,
|
||||||
final String? serverTypeIdentificator,
|
final String? serverTypeIdentificator,
|
||||||
final String? cloudFlareKey,
|
final String? dnsApiToken,
|
||||||
final BackblazeCredential? backblazeCredential,
|
final BackblazeCredential? backblazeCredential,
|
||||||
final ServerDomain? serverDomain,
|
final ServerDomain? serverDomain,
|
||||||
final User? rootUser,
|
final User? rootUser,
|
||||||
|
@ -320,7 +320,7 @@ class ServerInstallationRecovery extends ServerInstallationState {
|
||||||
providerApiToken: providerApiToken ?? this.providerApiToken,
|
providerApiToken: providerApiToken ?? this.providerApiToken,
|
||||||
serverTypeIdentificator:
|
serverTypeIdentificator:
|
||||||
serverTypeIdentificator ?? this.serverTypeIdentificator,
|
serverTypeIdentificator ?? this.serverTypeIdentificator,
|
||||||
cloudFlareKey: cloudFlareKey ?? this.cloudFlareKey,
|
dnsApiToken: dnsApiToken ?? this.dnsApiToken,
|
||||||
backblazeCredential: backblazeCredential ?? this.backblazeCredential,
|
backblazeCredential: backblazeCredential ?? this.backblazeCredential,
|
||||||
serverDomain: serverDomain ?? this.serverDomain,
|
serverDomain: serverDomain ?? this.serverDomain,
|
||||||
rootUser: rootUser ?? this.rootUser,
|
rootUser: rootUser ?? this.rootUser,
|
||||||
|
@ -332,7 +332,7 @@ class ServerInstallationRecovery extends ServerInstallationState {
|
||||||
ServerInstallationFinished finish() => ServerInstallationFinished(
|
ServerInstallationFinished finish() => ServerInstallationFinished(
|
||||||
providerApiToken: providerApiToken!,
|
providerApiToken: providerApiToken!,
|
||||||
serverTypeIdentificator: serverTypeIdentificator ?? '',
|
serverTypeIdentificator: serverTypeIdentificator ?? '',
|
||||||
cloudFlareKey: cloudFlareKey!,
|
dnsApiToken: dnsApiToken!,
|
||||||
backblazeCredential: backblazeCredential!,
|
backblazeCredential: backblazeCredential!,
|
||||||
serverDomain: serverDomain!,
|
serverDomain: serverDomain!,
|
||||||
rootUser: rootUser!,
|
rootUser: rootUser!,
|
||||||
|
|
|
@ -12,7 +12,7 @@ class ApiConfigModel {
|
||||||
String? get serverProviderKey => _serverProviderKey;
|
String? get serverProviderKey => _serverProviderKey;
|
||||||
String? get serverLocation => _serverLocation;
|
String? get serverLocation => _serverLocation;
|
||||||
String? get serverType => _serverType;
|
String? get serverType => _serverType;
|
||||||
String? get cloudFlareKey => _cloudFlareKey;
|
String? get dnsProviderKey => _dnsProviderKey;
|
||||||
ServerProvider? get serverProvider => _serverProvider;
|
ServerProvider? get serverProvider => _serverProvider;
|
||||||
BackblazeCredential? get backblazeCredential => _backblazeCredential;
|
BackblazeCredential? get backblazeCredential => _backblazeCredential;
|
||||||
ServerDomain? get serverDomain => _serverDomain;
|
ServerDomain? get serverDomain => _serverDomain;
|
||||||
|
@ -20,7 +20,7 @@ class ApiConfigModel {
|
||||||
|
|
||||||
String? _serverProviderKey;
|
String? _serverProviderKey;
|
||||||
String? _serverLocation;
|
String? _serverLocation;
|
||||||
String? _cloudFlareKey;
|
String? _dnsProviderKey;
|
||||||
String? _serverType;
|
String? _serverType;
|
||||||
ServerProvider? _serverProvider;
|
ServerProvider? _serverProvider;
|
||||||
ServerHostingDetails? _serverDetails;
|
ServerHostingDetails? _serverDetails;
|
||||||
|
@ -38,9 +38,9 @@ class ApiConfigModel {
|
||||||
_serverProviderKey = value;
|
_serverProviderKey = value;
|
||||||
}
|
}
|
||||||
|
|
||||||
Future<void> storeCloudFlareKey(final String value) async {
|
Future<void> storeDnsProviderKey(final String value) async {
|
||||||
await _box.put(BNames.cloudFlareKey, value);
|
await _box.put(BNames.cloudFlareKey, value);
|
||||||
_cloudFlareKey = value;
|
_dnsProviderKey = value;
|
||||||
}
|
}
|
||||||
|
|
||||||
Future<void> storeServerTypeIdentifier(final String typeIdentifier) async {
|
Future<void> storeServerTypeIdentifier(final String typeIdentifier) async {
|
||||||
|
@ -76,7 +76,7 @@ class ApiConfigModel {
|
||||||
void clear() {
|
void clear() {
|
||||||
_serverProviderKey = null;
|
_serverProviderKey = null;
|
||||||
_serverLocation = null;
|
_serverLocation = null;
|
||||||
_cloudFlareKey = null;
|
_dnsProviderKey = null;
|
||||||
_backblazeCredential = null;
|
_backblazeCredential = null;
|
||||||
_serverDomain = null;
|
_serverDomain = null;
|
||||||
_serverDetails = null;
|
_serverDetails = null;
|
||||||
|
@ -88,7 +88,7 @@ class ApiConfigModel {
|
||||||
void init() {
|
void init() {
|
||||||
_serverProviderKey = _box.get(BNames.hetznerKey);
|
_serverProviderKey = _box.get(BNames.hetznerKey);
|
||||||
_serverLocation = _box.get(BNames.serverLocation);
|
_serverLocation = _box.get(BNames.serverLocation);
|
||||||
_cloudFlareKey = _box.get(BNames.cloudFlareKey);
|
_dnsProviderKey = _box.get(BNames.cloudFlareKey);
|
||||||
_backblazeCredential = _box.get(BNames.backblazeCredential);
|
_backblazeCredential = _box.get(BNames.backblazeCredential);
|
||||||
_serverDomain = _box.get(BNames.serverDomain);
|
_serverDomain = _box.get(BNames.serverDomain);
|
||||||
_serverDetails = _box.get(BNames.serverDetails);
|
_serverDetails = _box.get(BNames.serverDetails);
|
||||||
|
|
|
@ -29,4 +29,6 @@ enum DnsProvider {
|
||||||
unknown,
|
unknown,
|
||||||
@HiveField(1)
|
@HiveField(1)
|
||||||
cloudflare,
|
cloudflare,
|
||||||
|
@HiveField(2)
|
||||||
|
digitalOcean,
|
||||||
}
|
}
|
||||||
|
|
|
@ -53,7 +53,7 @@ class RecoveryRouting extends StatelessWidget {
|
||||||
case RecoveryStep.serverSelection:
|
case RecoveryStep.serverSelection:
|
||||||
currentPage = const RecoveryConfirmServer();
|
currentPage = const RecoveryConfirmServer();
|
||||||
break;
|
break;
|
||||||
case RecoveryStep.cloudflareToken:
|
case RecoveryStep.dnsProviderToken:
|
||||||
currentPage = const RecoveryConfirmCloudflare();
|
currentPage = const RecoveryConfirmCloudflare();
|
||||||
break;
|
break;
|
||||||
case RecoveryStep.backblazeToken:
|
case RecoveryStep.backblazeToken:
|
||||||
|
|
Loading…
Reference in a new issue