mirror of
https://git.selfprivacy.org/kherel/selfprivacy.org.app.git
synced 2025-01-07 00:24:18 +00:00
Merge pull request 'Implement Provider Api Abstractions' (#99) from naiji-dev into develop
Reviewed-on: https://git.selfprivacy.org/kherel/selfprivacy.org.app/pulls/99
This commit is contained in:
commit
8deb240426
12
build.yaml
12
build.yaml
|
@ -1,7 +1,17 @@
|
|||
targets:
|
||||
$default:
|
||||
builders:
|
||||
graphql_codegen:
|
||||
options:
|
||||
scalars:
|
||||
DateTime:
|
||||
type: DateTime
|
||||
fromJsonFunctionName: dateTimeFromJson
|
||||
toJsonFunctionName: dateTimeToJson
|
||||
import: package:selfprivacy/utils/scalars.dart
|
||||
clients:
|
||||
- graphql
|
||||
json_serializable:
|
||||
options:
|
||||
create_factory: true
|
||||
create_to_json: false
|
||||
create_to_json: false
|
||||
|
|
|
@ -0,0 +1,9 @@
|
|||
query GetApiTokensQuery {
|
||||
api {
|
||||
devices {
|
||||
creationDate
|
||||
isCaller
|
||||
name
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,34 @@
|
|||
// GENERATED CODE - DO NOT MODIFY BY HAND
|
||||
|
||||
part of 'get_api_tokens.graphql.dart';
|
||||
|
||||
// **************************************************************************
|
||||
// JsonSerializableGenerator
|
||||
// **************************************************************************
|
||||
|
||||
Query$GetApiTokensQuery _$Query$GetApiTokensQueryFromJson(
|
||||
Map<String, dynamic> json) =>
|
||||
Query$GetApiTokensQuery(
|
||||
api: Query$GetApiTokensQuery$api.fromJson(
|
||||
json['api'] as Map<String, dynamic>),
|
||||
$__typename: json['__typename'] as String,
|
||||
);
|
||||
|
||||
Query$GetApiTokensQuery$api _$Query$GetApiTokensQuery$apiFromJson(
|
||||
Map<String, dynamic> json) =>
|
||||
Query$GetApiTokensQuery$api(
|
||||
devices: (json['devices'] as List<dynamic>)
|
||||
.map((e) => Query$GetApiTokensQuery$api$devices.fromJson(
|
||||
e as Map<String, dynamic>))
|
||||
.toList(),
|
||||
$__typename: json['__typename'] as String,
|
||||
);
|
||||
|
||||
Query$GetApiTokensQuery$api$devices
|
||||
_$Query$GetApiTokensQuery$api$devicesFromJson(Map<String, dynamic> json) =>
|
||||
Query$GetApiTokensQuery$api$devices(
|
||||
creationDate: dateTimeFromJson(json['creationDate']),
|
||||
isCaller: json['isCaller'] as bool,
|
||||
name: json['name'] as String,
|
||||
$__typename: json['__typename'] as String,
|
||||
);
|
|
@ -0,0 +1,5 @@
|
|||
query GetApiVersionQuery {
|
||||
api {
|
||||
version
|
||||
}
|
||||
}
|
|
@ -0,0 +1,22 @@
|
|||
// GENERATED CODE - DO NOT MODIFY BY HAND
|
||||
|
||||
part of 'get_api_version.graphql.dart';
|
||||
|
||||
// **************************************************************************
|
||||
// JsonSerializableGenerator
|
||||
// **************************************************************************
|
||||
|
||||
Query$GetApiVersionQuery _$Query$GetApiVersionQueryFromJson(
|
||||
Map<String, dynamic> json) =>
|
||||
Query$GetApiVersionQuery(
|
||||
api: Query$GetApiVersionQuery$api.fromJson(
|
||||
json['api'] as Map<String, dynamic>),
|
||||
$__typename: json['__typename'] as String,
|
||||
);
|
||||
|
||||
Query$GetApiVersionQuery$api _$Query$GetApiVersionQuery$apiFromJson(
|
||||
Map<String, dynamic> json) =>
|
||||
Query$GetApiVersionQuery$api(
|
||||
version: json['version'] as String,
|
||||
$__typename: json['__typename'] as String,
|
||||
);
|
151
lib/logic/api_maps/graphql_maps/schema/schema.graphql
Normal file
151
lib/logic/api_maps/graphql_maps/schema/schema.graphql
Normal file
|
@ -0,0 +1,151 @@
|
|||
scalar DateTime
|
||||
|
||||
type Alert {
|
||||
severity: Severity!
|
||||
title: String!
|
||||
message: String!
|
||||
timestamp: DateTime
|
||||
}
|
||||
|
||||
type Api {
|
||||
version: String!
|
||||
devices: [ApiDevice!]!
|
||||
recoveryKey: ApiRecoveryKeyStatus!
|
||||
}
|
||||
|
||||
type ApiDevice {
|
||||
name: String!
|
||||
creationDate: DateTime!
|
||||
isCaller: Boolean!
|
||||
}
|
||||
|
||||
type ApiKeyMutationReturn implements MutationReturnInterface {
|
||||
success: Boolean!
|
||||
message: String!
|
||||
code: Int!
|
||||
key: String
|
||||
}
|
||||
|
||||
type ApiRecoveryKeyStatus {
|
||||
exists: Boolean!
|
||||
valid: Boolean!
|
||||
creationDate: DateTime
|
||||
expirationDate: DateTime
|
||||
usesLeft: Int
|
||||
}
|
||||
|
||||
type AutoUpgradeOptions {
|
||||
enable: Boolean!
|
||||
allowReboot: Boolean!
|
||||
}
|
||||
|
||||
type DeviceApiTokenMutationReturn implements MutationReturnInterface {
|
||||
success: Boolean!
|
||||
message: String!
|
||||
code: Int!
|
||||
token: String
|
||||
}
|
||||
|
||||
enum DnsProvider {
|
||||
CLOUDFLARE
|
||||
}
|
||||
|
||||
type DnsRecord {
|
||||
recordType: String!
|
||||
name: String!
|
||||
content: String!
|
||||
ttl: Int!
|
||||
priority: Int
|
||||
}
|
||||
|
||||
type GenericMutationReturn implements MutationReturnInterface {
|
||||
success: Boolean!
|
||||
message: String!
|
||||
code: Int!
|
||||
}
|
||||
|
||||
type Mutation {
|
||||
getNewRecoveryApiKey(limits: RecoveryKeyLimitsInput!): ApiKeyMutationReturn!
|
||||
useRecoveryApiKey(input: UseRecoveryKeyInput!): DeviceApiTokenMutationReturn!
|
||||
refreshDeviceApiToken: DeviceApiTokenMutationReturn!
|
||||
deleteDeviceApiToken(device: String!): GenericMutationReturn!
|
||||
getNewDeviceApiKey: ApiKeyMutationReturn!
|
||||
invalidateNewDeviceApiKey: GenericMutationReturn!
|
||||
authorizeWithNewDeviceApiKey(input: UseNewDeviceKeyInput!): DeviceApiTokenMutationReturn!
|
||||
}
|
||||
|
||||
interface MutationReturnInterface {
|
||||
success: Boolean!
|
||||
message: String!
|
||||
code: Int!
|
||||
}
|
||||
|
||||
type Query {
|
||||
system: System!
|
||||
api: Api!
|
||||
}
|
||||
|
||||
input RecoveryKeyLimitsInput {
|
||||
expirationDate: DateTime
|
||||
uses: Int
|
||||
}
|
||||
|
||||
enum ServerProvider {
|
||||
HETZNER
|
||||
}
|
||||
|
||||
enum Severity {
|
||||
INFO
|
||||
WARNING
|
||||
ERROR
|
||||
CRITICAL
|
||||
SUCCESS
|
||||
}
|
||||
|
||||
type SshSettings {
|
||||
enable: Boolean!
|
||||
passwordAuthentication: Boolean!
|
||||
rootSshKeys: [String!]!
|
||||
}
|
||||
|
||||
type System {
|
||||
status: Alert!
|
||||
domain: SystemDomainInfo!
|
||||
settings: SystemSettings!
|
||||
info: SystemInfo!
|
||||
provider: SystemProviderInfo!
|
||||
busy: Boolean!
|
||||
}
|
||||
|
||||
type SystemDomainInfo {
|
||||
domain: String!
|
||||
hostname: String!
|
||||
provider: DnsProvider!
|
||||
requiredDnsRecords: [DnsRecord!]!
|
||||
}
|
||||
|
||||
type SystemInfo {
|
||||
systemVersion: String!
|
||||
pythonVersion: String!
|
||||
}
|
||||
|
||||
type SystemProviderInfo {
|
||||
provider: ServerProvider!
|
||||
id: String!
|
||||
}
|
||||
|
||||
type SystemSettings {
|
||||
autoUpgrade: AutoUpgradeOptions!
|
||||
ssh: SshSettings!
|
||||
timezone: String!
|
||||
}
|
||||
|
||||
input UseNewDeviceKeyInput {
|
||||
key: String!
|
||||
deviceName: String!
|
||||
}
|
||||
|
||||
input UseRecoveryKeyInput {
|
||||
key: String!
|
||||
deviceName: String!
|
||||
}
|
28
lib/logic/api_maps/graphql_maps/schema/schema.graphql.g.dart
Normal file
28
lib/logic/api_maps/graphql_maps/schema/schema.graphql.g.dart
Normal file
|
@ -0,0 +1,28 @@
|
|||
// GENERATED CODE - DO NOT MODIFY BY HAND
|
||||
|
||||
part of 'schema.graphql.dart';
|
||||
|
||||
// **************************************************************************
|
||||
// JsonSerializableGenerator
|
||||
// **************************************************************************
|
||||
|
||||
Input$RecoveryKeyLimitsInput _$Input$RecoveryKeyLimitsInputFromJson(
|
||||
Map<String, dynamic> json) =>
|
||||
Input$RecoveryKeyLimitsInput(
|
||||
expirationDate: _nullable$dateTimeFromJson(json['expirationDate']),
|
||||
uses: json['uses'] as int?,
|
||||
);
|
||||
|
||||
Input$UseNewDeviceKeyInput _$Input$UseNewDeviceKeyInputFromJson(
|
||||
Map<String, dynamic> json) =>
|
||||
Input$UseNewDeviceKeyInput(
|
||||
key: json['key'] as String,
|
||||
deviceName: json['deviceName'] as String,
|
||||
);
|
||||
|
||||
Input$UseRecoveryKeyInput _$Input$UseRecoveryKeyInputFromJson(
|
||||
Map<String, dynamic> json) =>
|
||||
Input$UseRecoveryKeyInput(
|
||||
key: json['key'] as String,
|
||||
deviceName: json['deviceName'] as String,
|
||||
);
|
39
lib/logic/api_maps/rest_maps/api_factory_creator.dart
Normal file
39
lib/logic/api_maps/rest_maps/api_factory_creator.dart
Normal file
|
@ -0,0 +1,39 @@
|
|||
import 'package:selfprivacy/logic/api_maps/rest_maps/providers/hetzner/hetzner_factory.dart';
|
||||
import 'package:selfprivacy/logic/api_maps/rest_maps/providers/provider_factory.dart';
|
||||
import 'package:selfprivacy/logic/models/hive/server_details.dart';
|
||||
|
||||
class ApiFactoryCreator {
|
||||
static ProviderApiFactory createProviderApiFactory(
|
||||
final ServerProvider provider,
|
||||
) {
|
||||
switch (provider) {
|
||||
case ServerProvider.hetzner:
|
||||
case ServerProvider.unknown: // ?? :)
|
||||
return HetznerApiFactory();
|
||||
}
|
||||
}
|
||||
|
||||
// createDnsApiFactory
|
||||
|
||||
// createStorageApiFactory
|
||||
|
||||
// etc . . .
|
||||
}
|
||||
|
||||
class VolumeApiFactoryCreator {
|
||||
static VolumeProviderApiFactory createVolumeProviderApiFactory(
|
||||
final ServerProvider provider,
|
||||
) {
|
||||
switch (provider) {
|
||||
case ServerProvider.hetzner:
|
||||
case ServerProvider.unknown: // ?? :)
|
||||
return HetznerApiFactory();
|
||||
}
|
||||
}
|
||||
|
||||
// createDnsApiFactory
|
||||
|
||||
// createStorageApiFactory
|
||||
|
||||
// etc . . .
|
||||
}
|
|
@ -2,7 +2,7 @@ import 'dart:io';
|
|||
|
||||
import 'package:dio/dio.dart';
|
||||
import 'package:selfprivacy/config/get_it_config.dart';
|
||||
import 'package:selfprivacy/logic/api_maps/api_map.dart';
|
||||
import 'package:selfprivacy/logic/api_maps/rest_maps/api_map.dart';
|
||||
import 'package:selfprivacy/logic/models/hive/backblaze_credential.dart';
|
||||
|
||||
class BackblazeApiAuth {
|
|
@ -2,7 +2,7 @@ import 'dart:io';
|
|||
|
||||
import 'package:dio/dio.dart';
|
||||
import 'package:selfprivacy/config/get_it_config.dart';
|
||||
import 'package:selfprivacy/logic/api_maps/api_map.dart';
|
||||
import 'package:selfprivacy/logic/api_maps/rest_maps/api_map.dart';
|
||||
import 'package:selfprivacy/logic/models/hive/server_domain.dart';
|
||||
import 'package:selfprivacy/logic/models/json/dns_records.dart';
|
||||
|
|
@ -3,14 +3,17 @@ import 'dart:io';
|
|||
|
||||
import 'package:dio/dio.dart';
|
||||
import 'package:selfprivacy/config/get_it_config.dart';
|
||||
import 'package:selfprivacy/logic/api_maps/api_map.dart';
|
||||
import 'package:selfprivacy/logic/api_maps/rest_maps/providers/volume_provider.dart';
|
||||
import 'package:selfprivacy/logic/api_maps/rest_maps/providers/provider.dart';
|
||||
import 'package:selfprivacy/logic/models/hive/server_domain.dart';
|
||||
import 'package:selfprivacy/logic/models/json/hetzner_server_info.dart';
|
||||
import 'package:selfprivacy/logic/models/hive/server_details.dart';
|
||||
import 'package:selfprivacy/logic/models/hive/user.dart';
|
||||
import 'package:selfprivacy/logic/models/server_basic_info.dart';
|
||||
import 'package:selfprivacy/utils/password_generator.dart';
|
||||
|
||||
class HetznerApi extends ApiMap {
|
||||
HetznerApi({this.hasLogger = false, this.isWithToken = true});
|
||||
class HetznerApi extends ServerProviderApi with VolumeProviderApi {
|
||||
HetznerApi({final this.hasLogger = false, final this.isWithToken = true});
|
||||
@override
|
||||
bool hasLogger;
|
||||
@override
|
||||
|
@ -35,27 +38,43 @@ class HetznerApi extends ApiMap {
|
|||
@override
|
||||
String rootAddress = 'https://api.hetzner.cloud/v1';
|
||||
|
||||
Future<bool> isValid(final String token) async {
|
||||
validateStatus = (final int? status) =>
|
||||
status == HttpStatus.ok || status == HttpStatus.unauthorized;
|
||||
@override
|
||||
Future<bool> isApiTokenValid(final String token) async {
|
||||
bool isValid = false;
|
||||
Response? response;
|
||||
final Dio client = await getClient();
|
||||
final Response response = await client.get(
|
||||
'/servers',
|
||||
options: Options(
|
||||
headers: {'Authorization': 'Bearer $token'},
|
||||
),
|
||||
);
|
||||
close(client);
|
||||
|
||||
if (response.statusCode == HttpStatus.ok) {
|
||||
return true;
|
||||
} else if (response.statusCode == HttpStatus.unauthorized) {
|
||||
return false;
|
||||
} else {
|
||||
throw Exception('code: ${response.statusCode}');
|
||||
try {
|
||||
response = await client.get(
|
||||
'/servers',
|
||||
options: Options(
|
||||
headers: {'Authorization': 'Bearer $token'},
|
||||
),
|
||||
);
|
||||
} catch (e) {
|
||||
print(e);
|
||||
isValid = false;
|
||||
} finally {
|
||||
close(client);
|
||||
}
|
||||
|
||||
if (response != null) {
|
||||
if (response.statusCode == HttpStatus.ok) {
|
||||
isValid = true;
|
||||
} else if (response.statusCode == HttpStatus.unauthorized) {
|
||||
isValid = false;
|
||||
} else {
|
||||
throw Exception('code: ${response.statusCode}');
|
||||
}
|
||||
}
|
||||
|
||||
return isValid;
|
||||
}
|
||||
|
||||
@override
|
||||
RegExp getApiTokenValidation() =>
|
||||
RegExp(r'\s+|[-!$%^&*()@+|~=`{}\[\]:<>?,.\/]');
|
||||
|
||||
@override
|
||||
Future<ServerVolume?> createVolume() async {
|
||||
ServerVolume? volume;
|
||||
|
||||
|
@ -92,6 +111,7 @@ class HetznerApi extends ApiMap {
|
|||
return volume;
|
||||
}
|
||||
|
||||
@override
|
||||
Future<List<ServerVolume>> getVolumes({final String? status}) async {
|
||||
final List<ServerVolume> volumes = [];
|
||||
|
||||
|
@ -127,6 +147,7 @@ class HetznerApi extends ApiMap {
|
|||
return volumes;
|
||||
}
|
||||
|
||||
@override
|
||||
Future<ServerVolume?> getVolume(final int id) async {
|
||||
ServerVolume? volume;
|
||||
|
||||
|
@ -153,7 +174,8 @@ class HetznerApi extends ApiMap {
|
|||
return volume;
|
||||
}
|
||||
|
||||
void deleteVolume(final int id) async {
|
||||
@override
|
||||
Future<void> deleteVolume(final int id) async {
|
||||
final Dio client = await getClient();
|
||||
try {
|
||||
await client.delete('/volumes/$id');
|
||||
|
@ -164,6 +186,7 @@ class HetznerApi extends ApiMap {
|
|||
}
|
||||
}
|
||||
|
||||
@override
|
||||
Future<bool> attachVolume(final int volumeId, final int serverId) async {
|
||||
bool success = false;
|
||||
|
||||
|
@ -187,6 +210,7 @@ class HetznerApi extends ApiMap {
|
|||
return success;
|
||||
}
|
||||
|
||||
@override
|
||||
Future<bool> detachVolume(final int volumeId) async {
|
||||
bool success = false;
|
||||
|
||||
|
@ -204,6 +228,7 @@ class HetznerApi extends ApiMap {
|
|||
return success;
|
||||
}
|
||||
|
||||
@override
|
||||
Future<bool> resizeVolume(final int volumeId, final int sizeGb) async {
|
||||
bool success = false;
|
||||
|
||||
|
@ -226,8 +251,35 @@ class HetznerApi extends ApiMap {
|
|||
return success;
|
||||
}
|
||||
|
||||
@override
|
||||
Future<ServerHostingDetails?> createServer({
|
||||
required final String cloudFlareKey,
|
||||
required final String dnsApiToken,
|
||||
required final User rootUser,
|
||||
required final String domainName,
|
||||
}) async {
|
||||
ServerHostingDetails? details;
|
||||
|
||||
final ServerVolume? newVolume = await createVolume();
|
||||
if (newVolume == null) {
|
||||
return details;
|
||||
}
|
||||
|
||||
details = await createServerWithVolume(
|
||||
dnsApiToken: dnsApiToken,
|
||||
rootUser: rootUser,
|
||||
domainName: domainName,
|
||||
dataBase: newVolume,
|
||||
);
|
||||
|
||||
if (details == null) {
|
||||
deleteVolume(newVolume.id);
|
||||
}
|
||||
|
||||
return details;
|
||||
}
|
||||
|
||||
Future<ServerHostingDetails?> createServerWithVolume({
|
||||
required final String dnsApiToken,
|
||||
required final User rootUser,
|
||||
required final String domainName,
|
||||
required final ServerVolume dataBase,
|
||||
|
@ -250,7 +302,7 @@ class HetznerApi extends ApiMap {
|
|||
/// check the branch name, it could be "development" or "master".
|
||||
///
|
||||
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=$cloudFlareKey DB_PASSWORD=$dbPassword API_TOKEN=$apiToken HOSTNAME=$hostname bash 2>&1 | tee /tmp/infect.log";
|
||||
"#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";
|
||||
print(userdataString);
|
||||
|
||||
final Map<String, Object> data = {
|
||||
|
@ -285,6 +337,7 @@ class HetznerApi extends ApiMap {
|
|||
);
|
||||
} on DioError catch (e) {
|
||||
print(e);
|
||||
deleteVolume(dataBase.id);
|
||||
rethrow;
|
||||
} catch (e) {
|
||||
print(e);
|
||||
|
@ -312,7 +365,8 @@ class HetznerApi extends ApiMap {
|
|||
return hostname;
|
||||
}
|
||||
|
||||
Future<void> deleteSelfprivacyServerAndAllVolumes({
|
||||
@override
|
||||
Future<void> deleteServer({
|
||||
required final String domainName,
|
||||
}) async {
|
||||
final Dio client = await getClient();
|
||||
|
@ -339,22 +393,34 @@ class HetznerApi extends ApiMap {
|
|||
close(client);
|
||||
}
|
||||
|
||||
Future<ServerHostingDetails> reset() async {
|
||||
@override
|
||||
Future<ServerHostingDetails> restart() async {
|
||||
final ServerHostingDetails server = getIt<ApiConfigModel>().serverDetails!;
|
||||
|
||||
final Dio client = await getClient();
|
||||
await client.post('/servers/${server.id}/actions/reset');
|
||||
close(client);
|
||||
try {
|
||||
await client.post('/servers/${server.id}/actions/reset');
|
||||
} catch (e) {
|
||||
print(e);
|
||||
} finally {
|
||||
close(client);
|
||||
}
|
||||
|
||||
return server.copyWith(startTime: DateTime.now());
|
||||
}
|
||||
|
||||
@override
|
||||
Future<ServerHostingDetails> powerOn() async {
|
||||
final ServerHostingDetails server = getIt<ApiConfigModel>().serverDetails!;
|
||||
|
||||
final Dio client = await getClient();
|
||||
await client.post('/servers/${server.id}/actions/poweron');
|
||||
close(client);
|
||||
try {
|
||||
await client.post('/servers/${server.id}/actions/poweron');
|
||||
} catch (e) {
|
||||
print(e);
|
||||
} finally {
|
||||
close(client);
|
||||
}
|
||||
|
||||
return server.copyWith(startTime: DateTime.now());
|
||||
}
|
||||
|
@ -391,31 +457,50 @@ class HetznerApi extends ApiMap {
|
|||
return HetznerServerInfo.fromJson(response.data!['server']);
|
||||
}
|
||||
|
||||
Future<List<HetznerServerInfo>> getServers() async {
|
||||
final Dio client = await getClient();
|
||||
final Response response = await client.get('/servers');
|
||||
close(client);
|
||||
|
||||
return (response.data!['servers'] as List)
|
||||
// ignore: unnecessary_lambdas
|
||||
.map((final e) => HetznerServerInfo.fromJson(e))
|
||||
.toList();
|
||||
}
|
||||
|
||||
Future<void> createReverseDns({
|
||||
required final String ip4,
|
||||
required final String domainName,
|
||||
}) async {
|
||||
final ServerHostingDetails? hetznerServer =
|
||||
getIt<ApiConfigModel>().serverDetails;
|
||||
@override
|
||||
Future<List<ServerBasicInfo>> getServers() async {
|
||||
List<ServerBasicInfo> servers = [];
|
||||
|
||||
final Dio client = await getClient();
|
||||
try {
|
||||
final Response response = await client.get('/servers');
|
||||
servers = (response.data!['servers'] as List)
|
||||
.map(
|
||||
(final e) => HetznerServerInfo.fromJson(e),
|
||||
)
|
||||
.toList()
|
||||
.map(
|
||||
(final HetznerServerInfo server) => ServerBasicInfo(
|
||||
id: server.id,
|
||||
name: server.name,
|
||||
ip: server.publicNet.ipv4.ip,
|
||||
reverseDns: server.publicNet.ipv4.reverseDns,
|
||||
created: server.created,
|
||||
volumeId: server.volumes.isNotEmpty ? server.volumes[0] : 0,
|
||||
),
|
||||
)
|
||||
.toList();
|
||||
} catch (e) {
|
||||
print(e);
|
||||
} finally {
|
||||
close(client);
|
||||
}
|
||||
|
||||
return servers;
|
||||
}
|
||||
|
||||
@override
|
||||
Future<void> createReverseDns({
|
||||
required final ServerHostingDetails serverDetails,
|
||||
required final ServerDomain domain,
|
||||
}) async {
|
||||
final Dio client = await getClient();
|
||||
try {
|
||||
await client.post(
|
||||
'/servers/${hetznerServer!.id}/actions/change_dns_ptr',
|
||||
'/servers/${serverDetails.id}/actions/change_dns_ptr',
|
||||
data: {
|
||||
'ip': ip4,
|
||||
'dns_ptr': domainName,
|
||||
'ip': serverDetails.ip4,
|
||||
'dns_ptr': domain.domainName,
|
||||
},
|
||||
);
|
||||
} catch (e) {
|
|
@ -0,0 +1,25 @@
|
|||
import 'package:selfprivacy/logic/api_maps/rest_maps/providers/hetzner/hetzner.dart';
|
||||
import 'package:selfprivacy/logic/api_maps/rest_maps/providers/provider.dart';
|
||||
import 'package:selfprivacy/logic/api_maps/rest_maps/providers/provider_factory.dart';
|
||||
import 'package:selfprivacy/logic/api_maps/rest_maps/providers/volume_provider.dart';
|
||||
|
||||
class HetznerApiFactory extends ProviderApiFactory
|
||||
with VolumeProviderApiFactory {
|
||||
@override
|
||||
ServerProviderApi getProvider({
|
||||
final ProviderApiSettings settings = const ProviderApiSettings(),
|
||||
}) =>
|
||||
HetznerApi(
|
||||
hasLogger: settings.hasLogger,
|
||||
isWithToken: settings.isWithToken,
|
||||
);
|
||||
|
||||
@override
|
||||
VolumeProviderApi getVolumeProvider({
|
||||
final ProviderApiSettings settings = const ProviderApiSettings(),
|
||||
}) =>
|
||||
HetznerApi(
|
||||
hasLogger: settings.hasLogger,
|
||||
isWithToken: settings.isWithToken,
|
||||
);
|
||||
}
|
26
lib/logic/api_maps/rest_maps/providers/provider.dart
Normal file
26
lib/logic/api_maps/rest_maps/providers/provider.dart
Normal file
|
@ -0,0 +1,26 @@
|
|||
import 'package:selfprivacy/logic/api_maps/rest_maps/api_map.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';
|
||||
import 'package:selfprivacy/logic/models/server_basic_info.dart';
|
||||
|
||||
abstract class ServerProviderApi extends ApiMap {
|
||||
Future<List<ServerBasicInfo>> getServers();
|
||||
|
||||
Future<ServerHostingDetails> restart();
|
||||
Future<ServerHostingDetails> powerOn();
|
||||
|
||||
Future<void> deleteServer({required final String domainName});
|
||||
Future<ServerHostingDetails?> createServer({
|
||||
required final String dnsApiToken,
|
||||
required final User rootUser,
|
||||
required final String domainName,
|
||||
});
|
||||
Future<void> createReverseDns({
|
||||
required final ServerHostingDetails serverDetails,
|
||||
required final ServerDomain domain,
|
||||
});
|
||||
|
||||
Future<bool> isApiTokenValid(final String token);
|
||||
RegExp getApiTokenValidation();
|
||||
}
|
20
lib/logic/api_maps/rest_maps/providers/provider_factory.dart
Normal file
20
lib/logic/api_maps/rest_maps/providers/provider_factory.dart
Normal file
|
@ -0,0 +1,20 @@
|
|||
import 'package:selfprivacy/logic/api_maps/rest_maps/providers/provider.dart';
|
||||
import 'package:selfprivacy/logic/api_maps/rest_maps/providers/volume_provider.dart';
|
||||
|
||||
class ProviderApiSettings {
|
||||
const ProviderApiSettings({this.hasLogger = false, this.isWithToken = true});
|
||||
final bool hasLogger;
|
||||
final bool isWithToken;
|
||||
}
|
||||
|
||||
abstract class ProviderApiFactory {
|
||||
ServerProviderApi getProvider({
|
||||
final ProviderApiSettings settings = const ProviderApiSettings(),
|
||||
});
|
||||
}
|
||||
|
||||
mixin VolumeProviderApiFactory {
|
||||
VolumeProviderApi getVolumeProvider({
|
||||
final ProviderApiSettings settings = const ProviderApiSettings(),
|
||||
});
|
||||
}
|
12
lib/logic/api_maps/rest_maps/providers/volume_provider.dart
Normal file
12
lib/logic/api_maps/rest_maps/providers/volume_provider.dart
Normal file
|
@ -0,0 +1,12 @@
|
|||
import 'package:selfprivacy/logic/api_maps/rest_maps/api_map.dart';
|
||||
import 'package:selfprivacy/logic/models/hive/server_details.dart';
|
||||
|
||||
mixin VolumeProviderApi on ApiMap {
|
||||
Future<ServerVolume?> createVolume();
|
||||
Future<List<ServerVolume>> getVolumes({final String? status});
|
||||
Future<ServerVolume?> getVolume(final int id);
|
||||
Future<bool> attachVolume(final int volumeId, final int serverId);
|
||||
Future<bool> detachVolume(final int volumeId);
|
||||
Future<bool> resizeVolume(final int volumeId, final int sizeGb);
|
||||
Future<void> deleteVolume(final int id);
|
||||
}
|
|
@ -15,7 +15,7 @@ import 'package:selfprivacy/logic/models/json/device_token.dart';
|
|||
import 'package:selfprivacy/logic/models/json/recovery_token_status.dart';
|
||||
import 'package:selfprivacy/logic/models/timezone_settings.dart';
|
||||
|
||||
import 'package:selfprivacy/logic/api_maps/api_map.dart';
|
||||
import 'package:selfprivacy/logic/api_maps/rest_maps/api_map.dart';
|
||||
|
||||
class ApiResponse<D> {
|
||||
ApiResponse({
|
|
@ -2,8 +2,8 @@ import 'dart:async';
|
|||
|
||||
import 'package:easy_localization/easy_localization.dart';
|
||||
import 'package:selfprivacy/config/get_it_config.dart';
|
||||
import 'package:selfprivacy/logic/api_maps/backblaze.dart';
|
||||
import 'package:selfprivacy/logic/api_maps/server.dart';
|
||||
import 'package:selfprivacy/logic/api_maps/rest_maps/backblaze.dart';
|
||||
import 'package:selfprivacy/logic/api_maps/rest_maps/server.dart';
|
||||
import 'package:selfprivacy/logic/cubit/app_config_dependent/authentication_dependend_cubit.dart';
|
||||
import 'package:selfprivacy/logic/models/hive/backblaze_bucket.dart';
|
||||
import 'package:selfprivacy/logic/models/json/backup.dart';
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
import 'package:selfprivacy/config/get_it_config.dart';
|
||||
import 'package:selfprivacy/logic/api_maps/server.dart';
|
||||
import 'package:selfprivacy/logic/api_maps/rest_maps/server.dart';
|
||||
import 'package:selfprivacy/logic/common_enum/common_enum.dart';
|
||||
import 'package:selfprivacy/logic/cubit/app_config_dependent/authentication_dependend_cubit.dart';
|
||||
import 'package:selfprivacy/logic/models/json/api_token.dart';
|
||||
|
|
|
@ -3,8 +3,8 @@ import 'package:selfprivacy/logic/cubit/app_config_dependent/authentication_depe
|
|||
import 'package:selfprivacy/logic/models/hive/server_domain.dart';
|
||||
import 'package:selfprivacy/logic/models/json/dns_records.dart';
|
||||
|
||||
import 'package:selfprivacy/logic/api_maps/cloudflare.dart';
|
||||
import 'package:selfprivacy/logic/api_maps/server.dart';
|
||||
import 'package:selfprivacy/logic/api_maps/rest_maps/cloudflare.dart';
|
||||
import 'package:selfprivacy/logic/api_maps/rest_maps/server.dart';
|
||||
|
||||
part 'dns_records_state.dart';
|
||||
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
import 'dart:async';
|
||||
import 'package:cubit_form/cubit_form.dart';
|
||||
import 'package:selfprivacy/logic/api_maps/backblaze.dart';
|
||||
import 'package:selfprivacy/logic/api_maps/rest_maps/backblaze.dart';
|
||||
import 'package:selfprivacy/logic/cubit/server_installation/server_installation_cubit.dart';
|
||||
import 'package:selfprivacy/logic/models/hive/backblaze_credential.dart';
|
||||
import 'package:easy_localization/easy_localization.dart';
|
||||
|
|
|
@ -2,7 +2,7 @@ import 'dart:async';
|
|||
|
||||
import 'package:cubit_form/cubit_form.dart';
|
||||
import 'package:easy_localization/easy_localization.dart';
|
||||
import 'package:selfprivacy/logic/api_maps/cloudflare.dart';
|
||||
import 'package:selfprivacy/logic/api_maps/rest_maps/cloudflare.dart';
|
||||
import 'package:selfprivacy/logic/cubit/server_installation/server_installation_cubit.dart';
|
||||
import 'package:selfprivacy/logic/cubit/forms/validations/validations.dart';
|
||||
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
import 'package:cubit_form/cubit_form.dart';
|
||||
import 'package:selfprivacy/logic/api_maps/cloudflare.dart';
|
||||
import 'package:selfprivacy/logic/api_maps/rest_maps/cloudflare.dart';
|
||||
import 'package:selfprivacy/logic/cubit/server_installation/server_installation_cubit.dart';
|
||||
import 'package:selfprivacy/logic/models/hive/server_domain.dart';
|
||||
|
||||
|
|
|
@ -2,13 +2,13 @@ import 'dart:async';
|
|||
|
||||
import 'package:cubit_form/cubit_form.dart';
|
||||
import 'package:easy_localization/easy_localization.dart';
|
||||
import 'package:selfprivacy/logic/api_maps/hetzner.dart';
|
||||
import 'package:selfprivacy/logic/cubit/server_installation/server_installation_cubit.dart';
|
||||
import 'package:selfprivacy/logic/cubit/forms/validations/validations.dart';
|
||||
|
||||
class HetznerFormCubit extends FormCubit {
|
||||
HetznerFormCubit(this.serverInstallationCubit) {
|
||||
final RegExp regExp = RegExp(r'\s+|[-!$%^&*()@+|~=`{}\[\]:<>?,.\/]');
|
||||
class ProviderFormCubit extends FormCubit {
|
||||
ProviderFormCubit(this.serverInstallationCubit) {
|
||||
final RegExp regExp =
|
||||
serverInstallationCubit.getProviderApiTokenValidation();
|
||||
apiKey = FieldCubit(
|
||||
initalValue: '',
|
||||
validations: [
|
||||
|
@ -30,16 +30,15 @@ class HetznerFormCubit extends FormCubit {
|
|||
}
|
||||
|
||||
final ServerInstallationCubit serverInstallationCubit;
|
||||
|
||||
late final FieldCubit<String> apiKey;
|
||||
|
||||
@override
|
||||
FutureOr<bool> asyncValidation() async {
|
||||
late bool isKeyValid;
|
||||
final HetznerApi apiClient = HetznerApi(isWithToken: false);
|
||||
|
||||
try {
|
||||
isKeyValid = await apiClient.isValid(apiKey.state.value);
|
||||
isKeyValid = await serverInstallationCubit
|
||||
.isProviderApiTokenValid(apiKey.state.value);
|
||||
} catch (e) {
|
||||
addError(e);
|
||||
isKeyValid = false;
|
|
@ -2,7 +2,7 @@ import 'dart:async';
|
|||
|
||||
import 'package:cubit_form/cubit_form.dart';
|
||||
import 'package:easy_localization/easy_localization.dart';
|
||||
import 'package:selfprivacy/logic/api_maps/server.dart';
|
||||
import 'package:selfprivacy/logic/api_maps/rest_maps/server.dart';
|
||||
import 'package:selfprivacy/logic/cubit/server_installation/server_installation_cubit.dart';
|
||||
import 'package:selfprivacy/logic/cubit/forms/factories/field_cubit_factory.dart';
|
||||
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
import 'package:selfprivacy/logic/api_maps/hetzner.dart';
|
||||
import 'package:selfprivacy/logic/api_maps/rest_maps/providers/hetzner/hetzner.dart';
|
||||
import 'package:selfprivacy/logic/common_enum/common_enum.dart';
|
||||
import 'package:selfprivacy/logic/models/hetzner_metrics.dart';
|
||||
|
||||
|
|
|
@ -2,7 +2,7 @@ import 'package:easy_localization/easy_localization.dart';
|
|||
import 'package:equatable/equatable.dart';
|
||||
import 'package:flutter_bloc/flutter_bloc.dart';
|
||||
import 'package:selfprivacy/config/get_it_config.dart';
|
||||
import 'package:selfprivacy/logic/api_maps/server.dart';
|
||||
import 'package:selfprivacy/logic/api_maps/rest_maps/server.dart';
|
||||
import 'package:selfprivacy/logic/cubit/services/services_cubit.dart';
|
||||
import 'package:selfprivacy/logic/cubit/users/users_cubit.dart';
|
||||
import 'package:selfprivacy/logic/models/job.dart';
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
import 'package:selfprivacy/logic/api_maps/server.dart';
|
||||
import 'package:selfprivacy/logic/api_maps/rest_maps/server.dart';
|
||||
import 'package:selfprivacy/logic/common_enum/common_enum.dart';
|
||||
import 'package:selfprivacy/logic/cubit/app_config_dependent/authentication_dependend_cubit.dart';
|
||||
import 'package:selfprivacy/logic/models/json/recovery_token_status.dart';
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
import 'package:selfprivacy/logic/api_maps/hetzner.dart';
|
||||
import 'package:selfprivacy/logic/api_maps/server.dart';
|
||||
import 'package:selfprivacy/logic/api_maps/rest_maps/providers/hetzner/hetzner.dart';
|
||||
import 'package:selfprivacy/logic/api_maps/rest_maps/server.dart';
|
||||
import 'package:selfprivacy/logic/models/json/auto_upgrade_settings.dart';
|
||||
import 'package:selfprivacy/logic/models/json/hetzner_server_info.dart';
|
||||
import 'package:selfprivacy/logic/models/timezone_settings.dart';
|
||||
|
|
|
@ -4,6 +4,7 @@ import 'package:flutter_bloc/flutter_bloc.dart';
|
|||
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/providers/provider_factory.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_domain.dart';
|
||||
|
@ -49,13 +50,22 @@ class ServerInstallationCubit extends Cubit<ServerInstallationState> {
|
|||
}
|
||||
}
|
||||
|
||||
RegExp getProviderApiTokenValidation() => repository.serverProviderApiFactory!
|
||||
.getProvider()
|
||||
.getApiTokenValidation();
|
||||
|
||||
Future<bool> isProviderApiTokenValid(final String providerToken) async =>
|
||||
repository.serverProviderApiFactory!
|
||||
.getProvider(settings: const ProviderApiSettings(isWithToken: false))
|
||||
.isApiTokenValid(providerToken);
|
||||
|
||||
void setHetznerKey(final String hetznerKey) async {
|
||||
await repository.saveHetznerKey(hetznerKey);
|
||||
|
||||
if (state is ServerInstallationRecovery) {
|
||||
emit(
|
||||
(state as ServerInstallationRecovery).copyWith(
|
||||
hetznerKey: hetznerKey,
|
||||
providerApiToken: hetznerKey,
|
||||
currentStep: RecoveryStep.serverSelection,
|
||||
),
|
||||
);
|
||||
|
@ -63,7 +73,9 @@ class ServerInstallationCubit extends Cubit<ServerInstallationState> {
|
|||
}
|
||||
|
||||
emit(
|
||||
(state as ServerInstallationNotFinished).copyWith(hetznerKey: hetznerKey),
|
||||
(state as ServerInstallationNotFinished).copyWith(
|
||||
providerApiToken: hetznerKey,
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
|
@ -117,7 +129,7 @@ class ServerInstallationCubit extends Cubit<ServerInstallationState> {
|
|||
|
||||
Future<void> onSuccess(final ServerHostingDetails serverDetails) async {
|
||||
await repository.createDnsRecords(
|
||||
serverDetails.ip4,
|
||||
serverDetails,
|
||||
state.serverDomain!,
|
||||
onCancel: onCancel,
|
||||
);
|
||||
|
@ -164,9 +176,24 @@ class ServerInstallationCubit extends Cubit<ServerInstallationState> {
|
|||
);
|
||||
|
||||
if (matches.values.every((final bool value) => value)) {
|
||||
final ServerHostingDetails server = await repository.startServer(
|
||||
final ServerHostingDetails? server = await repository.startServer(
|
||||
dataState.serverDetails!,
|
||||
);
|
||||
|
||||
if (server == null) {
|
||||
final ServerInstallationNotFinished newState = dataState.copyWith(
|
||||
isLoading: false,
|
||||
dnsMatches: matches,
|
||||
);
|
||||
emit(newState);
|
||||
runDelayed(
|
||||
startServerIfDnsIsOkay,
|
||||
const Duration(seconds: 30),
|
||||
newState,
|
||||
);
|
||||
return;
|
||||
}
|
||||
|
||||
await repository.saveServerDetails(server);
|
||||
await repository.saveIsServerStarted(true);
|
||||
|
||||
|
@ -464,7 +491,7 @@ class ServerInstallationCubit extends Cubit<ServerInstallationState> {
|
|||
final ServerInstallationRecovery dataState =
|
||||
state as ServerInstallationRecovery;
|
||||
final List<ServerBasicInfo> servers =
|
||||
await repository.getServersOnHetznerAccount();
|
||||
await repository.getServersOnProviderAccount();
|
||||
final Iterable<ServerBasicInfoWithValidators> validated = servers.map(
|
||||
(final ServerBasicInfo server) =>
|
||||
ServerBasicInfoWithValidators.fromServerBasicInfo(
|
||||
|
@ -566,7 +593,7 @@ class ServerInstallationCubit extends Cubit<ServerInstallationState> {
|
|||
print('================================');
|
||||
print('ServerInstallationState changed!');
|
||||
print('Current type: ${change.nextState.runtimeType}');
|
||||
print('Hetzner key: ${change.nextState.hetznerKey}');
|
||||
print('Hetzner key: ${change.nextState.providerApiToken}');
|
||||
print('Cloudflare key: ${change.nextState.cloudFlareKey}');
|
||||
print('Domain: ${change.nextState.serverDomain}');
|
||||
print('BackblazeCredential: ${change.nextState.backblazeCredential}');
|
||||
|
@ -599,7 +626,7 @@ class ServerInstallationCubit extends Cubit<ServerInstallationState> {
|
|||
await repository.deleteServerRelatedRecords();
|
||||
emit(
|
||||
ServerInstallationNotFinished(
|
||||
hetznerKey: state.hetznerKey,
|
||||
providerApiToken: state.providerApiToken,
|
||||
serverDomain: state.serverDomain,
|
||||
cloudFlareKey: state.cloudFlareKey,
|
||||
backblazeCredential: state.backblazeCredential,
|
||||
|
|
|
@ -9,16 +9,17 @@ import 'package:hive/hive.dart';
|
|||
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/cloudflare.dart';
|
||||
import 'package:selfprivacy/logic/api_maps/hetzner.dart';
|
||||
import 'package:selfprivacy/logic/api_maps/server.dart';
|
||||
import 'package:selfprivacy/logic/api_maps/rest_maps/api_factory_creator.dart';
|
||||
import 'package:selfprivacy/logic/api_maps/rest_maps/cloudflare.dart';
|
||||
import 'package:selfprivacy/logic/api_maps/rest_maps/providers/provider.dart';
|
||||
import 'package:selfprivacy/logic/api_maps/rest_maps/providers/provider_factory.dart';
|
||||
import 'package:selfprivacy/logic/api_maps/rest_maps/server.dart';
|
||||
import 'package:selfprivacy/logic/common_enum/common_enum.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_domain.dart';
|
||||
import 'package:selfprivacy/logic/models/hive/user.dart';
|
||||
import 'package:selfprivacy/logic/models/json/device_token.dart';
|
||||
import 'package:selfprivacy/logic/models/json/hetzner_server_info.dart';
|
||||
import 'package:selfprivacy/logic/models/message.dart';
|
||||
import 'package:selfprivacy/logic/models/server_basic_info.dart';
|
||||
import 'package:selfprivacy/ui/components/action_button/action_button.dart';
|
||||
|
@ -39,9 +40,13 @@ class ServerAuthorizationException implements Exception {
|
|||
class ServerInstallationRepository {
|
||||
Box box = Hive.box(BNames.serverInstallationBox);
|
||||
Box<User> usersBox = Hive.box(BNames.usersBox);
|
||||
ProviderApiFactory? serverProviderApiFactory =
|
||||
ApiFactoryCreator.createProviderApiFactory(
|
||||
ServerProvider.hetzner, // HARDCODE FOR NOW!!!
|
||||
); // Remove when provider selection is implemented.
|
||||
|
||||
Future<ServerInstallationState> load() async {
|
||||
final String? hetznerToken = getIt<ApiConfigModel>().hetznerKey;
|
||||
final String? providerApiToken = getIt<ApiConfigModel>().hetznerKey;
|
||||
final String? cloudflareToken = getIt<ApiConfigModel>().cloudFlareKey;
|
||||
final ServerDomain? serverDomain = getIt<ApiConfigModel>().serverDomain;
|
||||
final BackblazeCredential? backblazeCredential =
|
||||
|
@ -49,9 +54,14 @@ class ServerInstallationRepository {
|
|||
final ServerHostingDetails? serverDetails =
|
||||
getIt<ApiConfigModel>().serverDetails;
|
||||
|
||||
if (serverDetails != null) {
|
||||
serverProviderApiFactory =
|
||||
ApiFactoryCreator.createProviderApiFactory(serverDetails.provider);
|
||||
}
|
||||
|
||||
if (box.get(BNames.hasFinalChecked, defaultValue: false)) {
|
||||
return ServerInstallationFinished(
|
||||
hetznerKey: hetznerToken!,
|
||||
providerApiToken: providerApiToken!,
|
||||
cloudFlareKey: cloudflareToken!,
|
||||
serverDomain: serverDomain!,
|
||||
backblazeCredential: backblazeCredential!,
|
||||
|
@ -68,14 +78,14 @@ class ServerInstallationRepository {
|
|||
if (box.get(BNames.isRecoveringServer, defaultValue: false) &&
|
||||
serverDomain != null) {
|
||||
return ServerInstallationRecovery(
|
||||
hetznerKey: hetznerToken,
|
||||
providerApiToken: providerApiToken,
|
||||
cloudFlareKey: cloudflareToken,
|
||||
serverDomain: serverDomain,
|
||||
backblazeCredential: backblazeCredential,
|
||||
serverDetails: serverDetails,
|
||||
rootUser: box.get(BNames.rootUser),
|
||||
currentStep: _getCurrentRecoveryStep(
|
||||
hetznerToken,
|
||||
providerApiToken,
|
||||
cloudflareToken,
|
||||
serverDomain,
|
||||
serverDetails,
|
||||
|
@ -85,7 +95,7 @@ class ServerInstallationRepository {
|
|||
}
|
||||
|
||||
return ServerInstallationNotFinished(
|
||||
hetznerKey: hetznerToken,
|
||||
providerApiToken: providerApiToken,
|
||||
cloudFlareKey: cloudflareToken,
|
||||
serverDomain: serverDomain,
|
||||
backblazeCredential: backblazeCredential,
|
||||
|
@ -127,11 +137,13 @@ class ServerInstallationRepository {
|
|||
usersBox.clear();
|
||||
}
|
||||
|
||||
Future<ServerHostingDetails> startServer(
|
||||
Future<ServerHostingDetails?> startServer(
|
||||
final ServerHostingDetails hetznerServer,
|
||||
) async {
|
||||
final HetznerApi hetznerApi = HetznerApi();
|
||||
final ServerHostingDetails serverDetails = await hetznerApi.powerOn();
|
||||
ServerHostingDetails? serverDetails;
|
||||
|
||||
final ServerProviderApi api = serverProviderApiFactory!.getProvider();
|
||||
serverDetails = await api.powerOn();
|
||||
|
||||
return serverDetails;
|
||||
}
|
||||
|
@ -208,23 +220,12 @@ class ServerInstallationRepository {
|
|||
required final Future<void> Function(ServerHostingDetails serverDetails)
|
||||
onSuccess,
|
||||
}) async {
|
||||
final HetznerApi hetznerApi = HetznerApi();
|
||||
late ServerVolume dataBase;
|
||||
|
||||
final ServerProviderApi api = serverProviderApiFactory!.getProvider();
|
||||
try {
|
||||
final ServerVolume? createdVolume = await hetznerApi.createVolume();
|
||||
if (createdVolume == null) {
|
||||
print('Volume is not created!');
|
||||
return;
|
||||
}
|
||||
|
||||
dataBase = createdVolume;
|
||||
|
||||
final ServerHostingDetails? serverDetails = await hetznerApi.createServer(
|
||||
cloudFlareKey: cloudFlareKey,
|
||||
final ServerHostingDetails? serverDetails = await api.createServer(
|
||||
dnsApiToken: cloudFlareKey,
|
||||
rootUser: rootUser,
|
||||
domainName: domainName,
|
||||
dataBase: dataBase,
|
||||
);
|
||||
|
||||
if (serverDetails == null) {
|
||||
|
@ -245,17 +246,16 @@ class ServerInstallationRepository {
|
|||
text: 'basis.delete'.tr(),
|
||||
isRed: true,
|
||||
onPressed: () async {
|
||||
await hetznerApi.deleteSelfprivacyServerAndAllVolumes(
|
||||
await api.deleteServer(
|
||||
domainName: domainName,
|
||||
);
|
||||
|
||||
ServerHostingDetails? serverDetails;
|
||||
try {
|
||||
serverDetails = await hetznerApi.createServer(
|
||||
cloudFlareKey: cloudFlareKey,
|
||||
serverDetails = await api.createServer(
|
||||
dnsApiToken: cloudFlareKey,
|
||||
rootUser: rootUser,
|
||||
domainName: domainName,
|
||||
dataBase: dataBase,
|
||||
);
|
||||
} catch (e) {
|
||||
print(e);
|
||||
|
@ -280,25 +280,25 @@ class ServerInstallationRepository {
|
|||
}
|
||||
}
|
||||
|
||||
Future<void> createDnsRecords(
|
||||
final String ip4,
|
||||
final ServerDomain cloudFlareDomain, {
|
||||
Future<bool> createDnsRecords(
|
||||
final ServerHostingDetails serverDetails,
|
||||
final ServerDomain domain, {
|
||||
required final void Function() onCancel,
|
||||
}) async {
|
||||
final CloudflareApi cloudflareApi = CloudflareApi();
|
||||
final ServerProviderApi serverApi = serverProviderApiFactory!.getProvider();
|
||||
|
||||
await cloudflareApi.removeSimilarRecords(
|
||||
ip4: ip4,
|
||||
cloudFlareDomain: cloudFlareDomain,
|
||||
ip4: serverDetails.ip4,
|
||||
cloudFlareDomain: domain,
|
||||
);
|
||||
|
||||
try {
|
||||
await cloudflareApi.createMultipleDnsRecords(
|
||||
ip4: ip4,
|
||||
cloudFlareDomain: cloudFlareDomain,
|
||||
ip4: serverDetails.ip4,
|
||||
cloudFlareDomain: domain,
|
||||
);
|
||||
} on DioError catch (e) {
|
||||
final HetznerApi hetznerApi = HetznerApi();
|
||||
final NavigationService nav = getIt.get<NavigationService>();
|
||||
nav.showPopUpDialog(
|
||||
BrandAlert(
|
||||
|
@ -311,8 +311,8 @@ class ServerInstallationRepository {
|
|||
text: 'basis.delete'.tr(),
|
||||
isRed: true,
|
||||
onPressed: () async {
|
||||
await hetznerApi.deleteSelfprivacyServerAndAllVolumes(
|
||||
domainName: cloudFlareDomain.domainName,
|
||||
await serverApi.deleteServer(
|
||||
domainName: domain.domainName,
|
||||
);
|
||||
|
||||
onCancel();
|
||||
|
@ -325,12 +325,15 @@ class ServerInstallationRepository {
|
|||
],
|
||||
),
|
||||
);
|
||||
return false;
|
||||
}
|
||||
|
||||
await HetznerApi().createReverseDns(
|
||||
ip4: ip4,
|
||||
domainName: cloudFlareDomain.domainName,
|
||||
await serverApi.createReverseDns(
|
||||
serverDetails: serverDetails,
|
||||
domain: domain,
|
||||
);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
Future<void> createDkimRecord(final ServerDomain cloudFlareDomain) async {
|
||||
|
@ -354,13 +357,13 @@ class ServerInstallationRepository {
|
|||
}
|
||||
|
||||
Future<ServerHostingDetails> restart() async {
|
||||
final HetznerApi hetznerApi = HetznerApi();
|
||||
return hetznerApi.reset();
|
||||
final ServerProviderApi api = serverProviderApiFactory!.getProvider();
|
||||
return api.restart();
|
||||
}
|
||||
|
||||
Future<ServerHostingDetails> powerOn() async {
|
||||
final HetznerApi hetznerApi = HetznerApi();
|
||||
return hetznerApi.powerOn();
|
||||
final ServerProviderApi api = serverProviderApiFactory!.getProvider();
|
||||
return api.powerOn();
|
||||
}
|
||||
|
||||
Future<ServerRecoveryCapabilities> getRecoveryCapabilities(
|
||||
|
@ -595,21 +598,9 @@ class ServerInstallationRepository {
|
|||
}
|
||||
}
|
||||
|
||||
Future<List<ServerBasicInfo>> getServersOnHetznerAccount() async {
|
||||
final HetznerApi hetznerApi = HetznerApi();
|
||||
final List<HetznerServerInfo> servers = await hetznerApi.getServers();
|
||||
return servers
|
||||
.map(
|
||||
(final HetznerServerInfo server) => ServerBasicInfo(
|
||||
id: server.id,
|
||||
name: server.name,
|
||||
ip: server.publicNet.ipv4.ip,
|
||||
reverseDns: server.publicNet.ipv4.reverseDns,
|
||||
created: server.created,
|
||||
volumeId: server.volumes.isNotEmpty ? server.volumes[0] : 0,
|
||||
),
|
||||
)
|
||||
.toList();
|
||||
Future<List<ServerBasicInfo>> getServersOnProviderAccount() async {
|
||||
final ServerProviderApi api = serverProviderApiFactory!.getProvider();
|
||||
return api.getServers();
|
||||
}
|
||||
|
||||
Future<void> saveServerDetails(
|
||||
|
@ -687,10 +678,10 @@ class ServerInstallationRepository {
|
|||
}
|
||||
|
||||
Future<void> deleteServer(final ServerDomain serverDomain) async {
|
||||
final HetznerApi hetznerApi = HetznerApi();
|
||||
final ServerProviderApi api = serverProviderApiFactory!.getProvider();
|
||||
final CloudflareApi cloudFlare = CloudflareApi();
|
||||
|
||||
await hetznerApi.deleteSelfprivacyServerAndAllVolumes(
|
||||
await api.deleteServer(
|
||||
domainName: serverDomain.domainName,
|
||||
);
|
||||
|
||||
|
|
|
@ -2,7 +2,7 @@ part of '../server_installation/server_installation_cubit.dart';
|
|||
|
||||
abstract class ServerInstallationState extends Equatable {
|
||||
const ServerInstallationState({
|
||||
required this.hetznerKey,
|
||||
required this.providerApiToken,
|
||||
required this.cloudFlareKey,
|
||||
required this.backblazeCredential,
|
||||
required this.serverDomain,
|
||||
|
@ -15,7 +15,7 @@ abstract class ServerInstallationState extends Equatable {
|
|||
|
||||
@override
|
||||
List<Object?> get props => [
|
||||
hetznerKey,
|
||||
providerApiToken,
|
||||
cloudFlareKey,
|
||||
backblazeCredential,
|
||||
serverDomain,
|
||||
|
@ -25,7 +25,7 @@ abstract class ServerInstallationState extends Equatable {
|
|||
isServerResetedFirstTime,
|
||||
];
|
||||
|
||||
final String? hetznerKey;
|
||||
final String? providerApiToken;
|
||||
final String? cloudFlareKey;
|
||||
final BackblazeCredential? backblazeCredential;
|
||||
final ServerDomain? serverDomain;
|
||||
|
@ -35,7 +35,7 @@ abstract class ServerInstallationState extends Equatable {
|
|||
final bool isServerResetedFirstTime;
|
||||
final bool isServerResetedSecondTime;
|
||||
|
||||
bool get isHetznerFilled => hetznerKey != null;
|
||||
bool get isProviderFilled => providerApiToken != null;
|
||||
bool get isCloudFlareFilled => cloudFlareKey != null;
|
||||
bool get isBackblazeFilled => backblazeCredential != null;
|
||||
bool get isDomainFilled => serverDomain != null;
|
||||
|
@ -58,7 +58,7 @@ abstract class ServerInstallationState extends Equatable {
|
|||
|
||||
List<bool?> get _fulfilementList {
|
||||
final List<bool> res = [
|
||||
isHetznerFilled,
|
||||
isProviderFilled,
|
||||
isCloudFlareFilled,
|
||||
isBackblazeFilled,
|
||||
isDomainFilled,
|
||||
|
@ -80,7 +80,7 @@ class TimerState extends ServerInstallationNotFinished {
|
|||
this.timerStart,
|
||||
this.duration,
|
||||
}) : super(
|
||||
hetznerKey: dataState.hetznerKey,
|
||||
providerApiToken: dataState.providerApiToken,
|
||||
cloudFlareKey: dataState.cloudFlareKey,
|
||||
backblazeCredential: dataState.backblazeCredential,
|
||||
serverDomain: dataState.serverDomain,
|
||||
|
@ -124,7 +124,7 @@ class ServerInstallationNotFinished extends ServerInstallationState {
|
|||
required final super.isServerResetedSecondTime,
|
||||
required final this.isLoading,
|
||||
required this.dnsMatches,
|
||||
final super.hetznerKey,
|
||||
final super.providerApiToken,
|
||||
final super.cloudFlareKey,
|
||||
final super.backblazeCredential,
|
||||
final super.serverDomain,
|
||||
|
@ -136,7 +136,7 @@ class ServerInstallationNotFinished extends ServerInstallationState {
|
|||
|
||||
@override
|
||||
List<Object?> get props => [
|
||||
hetznerKey,
|
||||
providerApiToken,
|
||||
cloudFlareKey,
|
||||
backblazeCredential,
|
||||
serverDomain,
|
||||
|
@ -149,7 +149,7 @@ class ServerInstallationNotFinished extends ServerInstallationState {
|
|||
];
|
||||
|
||||
ServerInstallationNotFinished copyWith({
|
||||
final String? hetznerKey,
|
||||
final String? providerApiToken,
|
||||
final String? cloudFlareKey,
|
||||
final BackblazeCredential? backblazeCredential,
|
||||
final ServerDomain? serverDomain,
|
||||
|
@ -162,7 +162,7 @@ class ServerInstallationNotFinished extends ServerInstallationState {
|
|||
final Map<String, bool>? dnsMatches,
|
||||
}) =>
|
||||
ServerInstallationNotFinished(
|
||||
hetznerKey: hetznerKey ?? this.hetznerKey,
|
||||
providerApiToken: providerApiToken ?? this.providerApiToken,
|
||||
cloudFlareKey: cloudFlareKey ?? this.cloudFlareKey,
|
||||
backblazeCredential: backblazeCredential ?? this.backblazeCredential,
|
||||
serverDomain: serverDomain ?? this.serverDomain,
|
||||
|
@ -178,7 +178,7 @@ class ServerInstallationNotFinished extends ServerInstallationState {
|
|||
);
|
||||
|
||||
ServerInstallationFinished finish() => ServerInstallationFinished(
|
||||
hetznerKey: hetznerKey!,
|
||||
providerApiToken: providerApiToken!,
|
||||
cloudFlareKey: cloudFlareKey!,
|
||||
backblazeCredential: backblazeCredential!,
|
||||
serverDomain: serverDomain!,
|
||||
|
@ -193,7 +193,7 @@ class ServerInstallationNotFinished extends ServerInstallationState {
|
|||
class ServerInstallationEmpty extends ServerInstallationNotFinished {
|
||||
const ServerInstallationEmpty()
|
||||
: super(
|
||||
hetznerKey: null,
|
||||
providerApiToken: null,
|
||||
cloudFlareKey: null,
|
||||
backblazeCredential: null,
|
||||
serverDomain: null,
|
||||
|
@ -209,7 +209,7 @@ class ServerInstallationEmpty extends ServerInstallationNotFinished {
|
|||
|
||||
class ServerInstallationFinished extends ServerInstallationState {
|
||||
const ServerInstallationFinished({
|
||||
required final String super.hetznerKey,
|
||||
required final String super.providerApiToken,
|
||||
required final String super.cloudFlareKey,
|
||||
required final BackblazeCredential super.backblazeCredential,
|
||||
required final ServerDomain super.serverDomain,
|
||||
|
@ -222,7 +222,7 @@ class ServerInstallationFinished extends ServerInstallationState {
|
|||
|
||||
@override
|
||||
List<Object?> get props => [
|
||||
hetznerKey,
|
||||
providerApiToken,
|
||||
cloudFlareKey,
|
||||
backblazeCredential,
|
||||
serverDomain,
|
||||
|
@ -260,7 +260,7 @@ class ServerInstallationRecovery extends ServerInstallationState {
|
|||
const ServerInstallationRecovery({
|
||||
required this.currentStep,
|
||||
required this.recoveryCapabilities,
|
||||
final super.hetznerKey,
|
||||
final super.providerApiToken,
|
||||
final super.cloudFlareKey,
|
||||
final super.backblazeCredential,
|
||||
final super.serverDomain,
|
||||
|
@ -276,7 +276,7 @@ class ServerInstallationRecovery extends ServerInstallationState {
|
|||
|
||||
@override
|
||||
List<Object?> get props => [
|
||||
hetznerKey,
|
||||
providerApiToken,
|
||||
cloudFlareKey,
|
||||
backblazeCredential,
|
||||
serverDomain,
|
||||
|
@ -288,7 +288,7 @@ class ServerInstallationRecovery extends ServerInstallationState {
|
|||
];
|
||||
|
||||
ServerInstallationRecovery copyWith({
|
||||
final String? hetznerKey,
|
||||
final String? providerApiToken,
|
||||
final String? cloudFlareKey,
|
||||
final BackblazeCredential? backblazeCredential,
|
||||
final ServerDomain? serverDomain,
|
||||
|
@ -298,7 +298,7 @@ class ServerInstallationRecovery extends ServerInstallationState {
|
|||
final ServerRecoveryCapabilities? recoveryCapabilities,
|
||||
}) =>
|
||||
ServerInstallationRecovery(
|
||||
hetznerKey: hetznerKey ?? this.hetznerKey,
|
||||
providerApiToken: providerApiToken ?? this.providerApiToken,
|
||||
cloudFlareKey: cloudFlareKey ?? this.cloudFlareKey,
|
||||
backblazeCredential: backblazeCredential ?? this.backblazeCredential,
|
||||
serverDomain: serverDomain ?? this.serverDomain,
|
||||
|
@ -309,7 +309,7 @@ class ServerInstallationRecovery extends ServerInstallationState {
|
|||
);
|
||||
|
||||
ServerInstallationFinished finish() => ServerInstallationFinished(
|
||||
hetznerKey: hetznerKey!,
|
||||
providerApiToken: providerApiToken!,
|
||||
cloudFlareKey: cloudFlareKey!,
|
||||
backblazeCredential: backblazeCredential!,
|
||||
serverDomain: serverDomain!,
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
import 'package:selfprivacy/logic/api_maps/server.dart';
|
||||
import 'package:selfprivacy/logic/api_maps/rest_maps/server.dart';
|
||||
import 'package:selfprivacy/logic/common_enum/common_enum.dart';
|
||||
import 'package:selfprivacy/logic/cubit/app_config_dependent/authentication_dependend_cubit.dart';
|
||||
|
||||
|
|
|
@ -3,7 +3,7 @@ import 'package:selfprivacy/config/hive_config.dart';
|
|||
import 'package:selfprivacy/logic/cubit/app_config_dependent/authentication_dependend_cubit.dart';
|
||||
import 'package:selfprivacy/logic/models/hive/user.dart';
|
||||
|
||||
import 'package:selfprivacy/logic/api_maps/server.dart';
|
||||
import 'package:selfprivacy/logic/api_maps/rest_maps/server.dart';
|
||||
|
||||
export 'package:provider/provider.dart';
|
||||
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
import 'package:selfprivacy/config/get_it_config.dart';
|
||||
import 'package:selfprivacy/logic/api_maps/hetzner.dart';
|
||||
import 'package:selfprivacy/logic/api_maps/server.dart';
|
||||
import 'package:selfprivacy/logic/api_maps/rest_maps/api_factory_creator.dart';
|
||||
import 'package:selfprivacy/logic/api_maps/rest_maps/providers/provider_factory.dart';
|
||||
import 'package:selfprivacy/logic/common_enum/common_enum.dart';
|
||||
import 'package:selfprivacy/logic/cubit/app_config_dependent/authentication_dependend_cubit.dart';
|
||||
import 'package:selfprivacy/logic/models/hive/server_details.dart';
|
||||
|
@ -12,7 +12,10 @@ class ApiVolumesCubit
|
|||
ApiVolumesCubit(final ServerInstallationCubit serverInstallationCubit)
|
||||
: super(serverInstallationCubit, const ApiVolumesState.initial());
|
||||
|
||||
final ServerApi api = ServerApi();
|
||||
final VolumeProviderApiFactory providerApi =
|
||||
VolumeApiFactoryCreator.createVolumeProviderApiFactory(
|
||||
getIt<ApiConfigModel>().serverDetails!.provider,
|
||||
);
|
||||
|
||||
@override
|
||||
void load() async {
|
||||
|
@ -27,7 +30,8 @@ class ApiVolumesCubit
|
|||
}
|
||||
|
||||
void _refetch() async {
|
||||
final List<ServerVolume> volumes = await HetznerApi().getVolumes();
|
||||
final List<ServerVolume> volumes =
|
||||
await providerApi.getVolumeProvider().getVolumes();
|
||||
if (volumes.isNotEmpty) {
|
||||
emit(ApiVolumesState(volumes, LoadingStatus.success));
|
||||
} else {
|
||||
|
@ -37,29 +41,29 @@ class ApiVolumesCubit
|
|||
|
||||
void attachVolume(final ServerVolume volume) async {
|
||||
final ServerHostingDetails server = getIt<ApiConfigModel>().serverDetails!;
|
||||
HetznerApi().attachVolume(volume.id, server.id);
|
||||
await providerApi.getVolumeProvider().attachVolume(volume.id, server.id);
|
||||
refresh();
|
||||
}
|
||||
|
||||
void detachVolume(final ServerVolume volume) async {
|
||||
HetznerApi().detachVolume(volume.id);
|
||||
await providerApi.getVolumeProvider().detachVolume(volume.id);
|
||||
refresh();
|
||||
}
|
||||
|
||||
void resizeVolume(final ServerVolume volume, final int newSizeGb) {
|
||||
if (volume.sizeByte < newSizeGb) {
|
||||
HetznerApi().resizeVolume(volume.id, newSizeGb);
|
||||
refresh();
|
||||
}
|
||||
void resizeVolume(final ServerVolume volume, final int newSizeGb) async {
|
||||
//if (volume.sizeByte < newSizeGb) {
|
||||
await providerApi.getVolumeProvider().resizeVolume(volume.id, newSizeGb);
|
||||
refresh();
|
||||
//}
|
||||
}
|
||||
|
||||
void createVolume() async {
|
||||
HetznerApi().createVolume();
|
||||
await providerApi.getVolumeProvider().createVolume();
|
||||
refresh();
|
||||
}
|
||||
|
||||
void deleteVolume(final ServerVolume volume) async {
|
||||
HetznerApi().deleteVolume(volume.id);
|
||||
await providerApi.getVolumeProvider().deleteVolume(volume.id);
|
||||
refresh();
|
||||
}
|
||||
|
||||
|
|
|
@ -73,17 +73,23 @@ class ServerVolumeAdapter extends TypeAdapter<ServerVolume> {
|
|||
return ServerVolume(
|
||||
id: fields[1] as int,
|
||||
name: fields[2] as String,
|
||||
sizeByte: fields[3] == null ? 10737418240 : fields[3] as int,
|
||||
serverId: fields[4] as int?,
|
||||
);
|
||||
}
|
||||
|
||||
@override
|
||||
void write(BinaryWriter writer, ServerVolume obj) {
|
||||
writer
|
||||
..writeByte(2)
|
||||
..writeByte(4)
|
||||
..writeByte(1)
|
||||
..write(obj.id)
|
||||
..writeByte(2)
|
||||
..write(obj.name);
|
||||
..write(obj.name)
|
||||
..writeByte(3)
|
||||
..write(obj.sizeByte)
|
||||
..writeByte(4)
|
||||
..write(obj.serverId);
|
||||
}
|
||||
|
||||
@override
|
||||
|
|
|
@ -11,9 +11,9 @@ class UserAdapter extends TypeAdapter<User> {
|
|||
final int typeId = 1;
|
||||
|
||||
@override
|
||||
User read(final BinaryReader reader) {
|
||||
final int numOfFields = reader.readByte();
|
||||
final Map<int, dynamic> fields = <int, dynamic>{
|
||||
User read(BinaryReader reader) {
|
||||
final numOfFields = reader.readByte();
|
||||
final fields = <int, dynamic>{
|
||||
for (int i = 0; i < numOfFields; i++) reader.readByte(): reader.read(),
|
||||
};
|
||||
return User(
|
||||
|
@ -26,7 +26,7 @@ class UserAdapter extends TypeAdapter<User> {
|
|||
}
|
||||
|
||||
@override
|
||||
void write(final BinaryWriter writer, final User obj) {
|
||||
void write(BinaryWriter writer, User obj) {
|
||||
writer
|
||||
..writeByte(5)
|
||||
..writeByte(0)
|
||||
|
@ -45,7 +45,7 @@ class UserAdapter extends TypeAdapter<User> {
|
|||
int get hashCode => typeId.hashCode;
|
||||
|
||||
@override
|
||||
bool operator ==(final Object other) =>
|
||||
bool operator ==(Object other) =>
|
||||
identical(this, other) ||
|
||||
other is UserAdapter &&
|
||||
runtimeType == other.runtimeType &&
|
||||
|
|
|
@ -7,7 +7,7 @@ import 'package:selfprivacy/logic/cubit/forms/factories/field_cubit_factory.dart
|
|||
import 'package:selfprivacy/logic/cubit/forms/setup/initializing/backblaze_form_cubit.dart';
|
||||
import 'package:selfprivacy/logic/cubit/forms/setup/initializing/cloudflare_form_cubit.dart';
|
||||
import 'package:selfprivacy/logic/cubit/forms/setup/initializing/domain_cloudflare.dart';
|
||||
import 'package:selfprivacy/logic/cubit/forms/setup/initializing/hetzner_form_cubit.dart';
|
||||
import 'package:selfprivacy/logic/cubit/forms/setup/initializing/provider_form_cubit.dart';
|
||||
import 'package:selfprivacy/logic/cubit/forms/setup/initializing/root_user_form_cubit.dart';
|
||||
import 'package:selfprivacy/ui/components/brand_bottom_sheet/brand_bottom_sheet.dart';
|
||||
import 'package:selfprivacy/ui/components/brand_button/brand_button.dart';
|
||||
|
@ -21,7 +21,9 @@ import 'package:selfprivacy/ui/pages/setup/recovering/recovery_routing.dart';
|
|||
import 'package:selfprivacy/utils/route_transitions/basic.dart';
|
||||
|
||||
class InitializingPage extends StatelessWidget {
|
||||
const InitializingPage({final super.key});
|
||||
const InitializingPage({
|
||||
final super.key,
|
||||
});
|
||||
|
||||
@override
|
||||
Widget build(final BuildContext context) {
|
||||
|
@ -135,10 +137,12 @@ class InitializingPage extends StatelessWidget {
|
|||
|
||||
Widget _stepHetzner(final ServerInstallationCubit serverInstallationCubit) =>
|
||||
BlocProvider(
|
||||
create: (final context) => HetznerFormCubit(serverInstallationCubit),
|
||||
create: (final context) => ProviderFormCubit(
|
||||
serverInstallationCubit,
|
||||
),
|
||||
child: Builder(
|
||||
builder: (final context) {
|
||||
final formCubitState = context.watch<HetznerFormCubit>().state;
|
||||
final formCubitState = context.watch<ProviderFormCubit>().state;
|
||||
return Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
|
@ -152,7 +156,7 @@ class InitializingPage extends StatelessWidget {
|
|||
BrandText.body2('initializing.2'.tr()),
|
||||
const Spacer(),
|
||||
CubitFormTextField(
|
||||
formFieldCubit: context.read<HetznerFormCubit>().apiKey,
|
||||
formFieldCubit: context.read<ProviderFormCubit>().apiKey,
|
||||
textAlign: TextAlign.center,
|
||||
scrollPadding: const EdgeInsets.only(bottom: 70),
|
||||
decoration: const InputDecoration(
|
||||
|
@ -163,7 +167,7 @@ class InitializingPage extends StatelessWidget {
|
|||
BrandButton.rised(
|
||||
onPressed: formCubitState.isSubmitting
|
||||
? null
|
||||
: () => context.read<HetznerFormCubit>().trySubmit(),
|
||||
: () => context.read<ProviderFormCubit>().trySubmit(),
|
||||
text: 'basis.connect'.tr(),
|
||||
),
|
||||
const SizedBox(height: 10),
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
import 'package:easy_localization/easy_localization.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:selfprivacy/config/brand_theme.dart';
|
||||
import 'package:selfprivacy/logic/cubit/forms/setup/initializing/hetzner_form_cubit.dart';
|
||||
import 'package:selfprivacy/logic/cubit/forms/setup/initializing/provider_form_cubit.dart';
|
||||
import 'package:selfprivacy/ui/components/brand_bottom_sheet/brand_bottom_sheet.dart';
|
||||
import 'package:selfprivacy/ui/components/brand_button/filled_button.dart';
|
||||
import 'package:selfprivacy/ui/components/brand_button/brand_button.dart';
|
||||
|
@ -19,11 +19,11 @@ class RecoveryHetznerConnected extends StatelessWidget {
|
|||
context.watch<ServerInstallationCubit>();
|
||||
|
||||
return BlocProvider(
|
||||
create: (final BuildContext context) => HetznerFormCubit(appConfig),
|
||||
create: (final BuildContext context) => ProviderFormCubit(appConfig),
|
||||
child: Builder(
|
||||
builder: (final BuildContext context) {
|
||||
final FormCubitState formCubitState =
|
||||
context.watch<HetznerFormCubit>().state;
|
||||
context.watch<ProviderFormCubit>().state;
|
||||
|
||||
return BrandHeroScreen(
|
||||
heroTitle: 'recovering.hetzner_connected'.tr(),
|
||||
|
@ -37,7 +37,7 @@ class RecoveryHetznerConnected extends StatelessWidget {
|
|||
},
|
||||
children: [
|
||||
CubitFormTextField(
|
||||
formFieldCubit: context.read<HetznerFormCubit>().apiKey,
|
||||
formFieldCubit: context.read<ProviderFormCubit>().apiKey,
|
||||
decoration: InputDecoration(
|
||||
border: const OutlineInputBorder(),
|
||||
labelText: 'recovering.hetzner_connected_placeholder'.tr(),
|
||||
|
@ -48,7 +48,7 @@ class RecoveryHetznerConnected extends StatelessWidget {
|
|||
title: 'more.continue'.tr(),
|
||||
onPressed: formCubitState.isSubmitting
|
||||
? null
|
||||
: () => context.read<HetznerFormCubit>().trySubmit(),
|
||||
: () => context.read<ProviderFormCubit>().trySubmit(),
|
||||
),
|
||||
const SizedBox(height: 16),
|
||||
BrandButton.text(
|
||||
|
|
9
lib/utils/scalars.dart
Normal file
9
lib/utils/scalars.dart
Normal file
|
@ -0,0 +1,9 @@
|
|||
// ignore_for_file: prefer_final_parameters, prefer_expression_function_bodies
|
||||
|
||||
String dateTimeToJson(DateTime data) {
|
||||
return data.toIso8601String();
|
||||
}
|
||||
|
||||
DateTime dateTimeFromJson(dynamic data) {
|
||||
return DateTime.parse(data as String);
|
||||
}
|
175
pubspec.lock
175
pubspec.lock
|
@ -169,6 +169,48 @@ packages:
|
|||
url: "https://pub.dartlang.org"
|
||||
source: hosted
|
||||
version: "1.16.0"
|
||||
connectivity_plus:
|
||||
dependency: transitive
|
||||
description:
|
||||
name: connectivity_plus
|
||||
url: "https://pub.dartlang.org"
|
||||
source: hosted
|
||||
version: "2.3.5"
|
||||
connectivity_plus_linux:
|
||||
dependency: transitive
|
||||
description:
|
||||
name: connectivity_plus_linux
|
||||
url: "https://pub.dartlang.org"
|
||||
source: hosted
|
||||
version: "1.3.1"
|
||||
connectivity_plus_macos:
|
||||
dependency: transitive
|
||||
description:
|
||||
name: connectivity_plus_macos
|
||||
url: "https://pub.dartlang.org"
|
||||
source: hosted
|
||||
version: "1.2.4"
|
||||
connectivity_plus_platform_interface:
|
||||
dependency: transitive
|
||||
description:
|
||||
name: connectivity_plus_platform_interface
|
||||
url: "https://pub.dartlang.org"
|
||||
source: hosted
|
||||
version: "1.2.1"
|
||||
connectivity_plus_web:
|
||||
dependency: transitive
|
||||
description:
|
||||
name: connectivity_plus_web
|
||||
url: "https://pub.dartlang.org"
|
||||
source: hosted
|
||||
version: "1.2.2"
|
||||
connectivity_plus_windows:
|
||||
dependency: transitive
|
||||
description:
|
||||
name: connectivity_plus_windows
|
||||
url: "https://pub.dartlang.org"
|
||||
source: hosted
|
||||
version: "1.2.2"
|
||||
convert:
|
||||
dependency: transitive
|
||||
description:
|
||||
|
@ -218,6 +260,13 @@ packages:
|
|||
url: "https://pub.dartlang.org"
|
||||
source: hosted
|
||||
version: "2.2.3"
|
||||
dbus:
|
||||
dependency: transitive
|
||||
description:
|
||||
name: dbus
|
||||
url: "https://pub.dartlang.org"
|
||||
source: hosted
|
||||
version: "0.7.3"
|
||||
device_info_plus:
|
||||
dependency: "direct main"
|
||||
description:
|
||||
|
@ -356,6 +405,13 @@ packages:
|
|||
url: "https://pub.dartlang.org"
|
||||
source: hosted
|
||||
version: "8.0.1"
|
||||
flutter_hooks:
|
||||
dependency: transitive
|
||||
description:
|
||||
name: flutter_hooks
|
||||
url: "https://pub.dartlang.org"
|
||||
source: hosted
|
||||
version: "0.18.5+1"
|
||||
flutter_launcher_icons:
|
||||
dependency: "direct dev"
|
||||
description:
|
||||
|
@ -462,6 +518,90 @@ packages:
|
|||
url: "https://pub.dartlang.org"
|
||||
source: hosted
|
||||
version: "2.0.2"
|
||||
gql:
|
||||
dependency: "direct main"
|
||||
description:
|
||||
name: gql
|
||||
url: "https://pub.dartlang.org"
|
||||
source: hosted
|
||||
version: "0.13.1"
|
||||
gql_code_builder:
|
||||
dependency: transitive
|
||||
description:
|
||||
name: gql_code_builder
|
||||
url: "https://pub.dartlang.org"
|
||||
source: hosted
|
||||
version: "0.5.1"
|
||||
gql_dedupe_link:
|
||||
dependency: transitive
|
||||
description:
|
||||
name: gql_dedupe_link
|
||||
url: "https://pub.dartlang.org"
|
||||
source: hosted
|
||||
version: "2.0.2"
|
||||
gql_error_link:
|
||||
dependency: transitive
|
||||
description:
|
||||
name: gql_error_link
|
||||
url: "https://pub.dartlang.org"
|
||||
source: hosted
|
||||
version: "0.2.2"
|
||||
gql_exec:
|
||||
dependency: transitive
|
||||
description:
|
||||
name: gql_exec
|
||||
url: "https://pub.dartlang.org"
|
||||
source: hosted
|
||||
version: "0.4.0"
|
||||
gql_http_link:
|
||||
dependency: transitive
|
||||
description:
|
||||
name: gql_http_link
|
||||
url: "https://pub.dartlang.org"
|
||||
source: hosted
|
||||
version: "0.4.2"
|
||||
gql_link:
|
||||
dependency: transitive
|
||||
description:
|
||||
name: gql_link
|
||||
url: "https://pub.dartlang.org"
|
||||
source: hosted
|
||||
version: "0.4.2"
|
||||
gql_transform_link:
|
||||
dependency: transitive
|
||||
description:
|
||||
name: gql_transform_link
|
||||
url: "https://pub.dartlang.org"
|
||||
source: hosted
|
||||
version: "0.2.2"
|
||||
graphql:
|
||||
dependency: "direct main"
|
||||
description:
|
||||
name: graphql
|
||||
url: "https://pub.dartlang.org"
|
||||
source: hosted
|
||||
version: "5.1.1"
|
||||
graphql_codegen:
|
||||
dependency: "direct main"
|
||||
description:
|
||||
name: graphql_codegen
|
||||
url: "https://pub.dartlang.org"
|
||||
source: hosted
|
||||
version: "0.9.0"
|
||||
graphql_codegen_config:
|
||||
dependency: transitive
|
||||
description:
|
||||
name: graphql_codegen_config
|
||||
url: "https://pub.dartlang.org"
|
||||
source: hosted
|
||||
version: "0.2.6"
|
||||
graphql_flutter:
|
||||
dependency: "direct main"
|
||||
description:
|
||||
name: graphql_flutter
|
||||
url: "https://pub.dartlang.org"
|
||||
source: hosted
|
||||
version: "5.1.0"
|
||||
graphs:
|
||||
dependency: transitive
|
||||
description:
|
||||
|
@ -672,6 +812,13 @@ packages:
|
|||
url: "https://pub.dartlang.org"
|
||||
source: hosted
|
||||
version: "1.0.0"
|
||||
nm:
|
||||
dependency: transitive
|
||||
description:
|
||||
name: nm
|
||||
url: "https://pub.dartlang.org"
|
||||
source: hosted
|
||||
version: "0.5.0"
|
||||
node_preamble:
|
||||
dependency: transitive
|
||||
description:
|
||||
|
@ -679,6 +826,13 @@ packages:
|
|||
url: "https://pub.dartlang.org"
|
||||
source: hosted
|
||||
version: "2.0.1"
|
||||
normalize:
|
||||
dependency: transitive
|
||||
description:
|
||||
name: normalize
|
||||
url: "https://pub.dartlang.org"
|
||||
source: hosted
|
||||
version: "0.6.0+1"
|
||||
package_config:
|
||||
dependency: transitive
|
||||
description:
|
||||
|
@ -826,6 +980,20 @@ packages:
|
|||
url: "https://pub.dartlang.org"
|
||||
source: hosted
|
||||
version: "3.1.0"
|
||||
recase:
|
||||
dependency: transitive
|
||||
description:
|
||||
name: recase
|
||||
url: "https://pub.dartlang.org"
|
||||
source: hosted
|
||||
version: "4.0.0"
|
||||
rxdart:
|
||||
dependency: transitive
|
||||
description:
|
||||
name: rxdart
|
||||
url: "https://pub.dartlang.org"
|
||||
source: hosted
|
||||
version: "0.27.4"
|
||||
share_plus:
|
||||
dependency: "direct main"
|
||||
description:
|
||||
|
@ -1153,6 +1321,13 @@ packages:
|
|||
url: "https://pub.dartlang.org"
|
||||
source: hosted
|
||||
version: "3.0.1"
|
||||
uuid:
|
||||
dependency: transitive
|
||||
description:
|
||||
name: uuid
|
||||
url: "https://pub.dartlang.org"
|
||||
source: hosted
|
||||
version: "3.0.6"
|
||||
vector_math:
|
||||
dependency: transitive
|
||||
description:
|
||||
|
|
|
@ -26,6 +26,10 @@ dependencies:
|
|||
flutter_markdown: ^0.6.9
|
||||
flutter_secure_storage: ^5.0.2
|
||||
get_it: ^7.2.0
|
||||
gql: ^0.13.1
|
||||
graphql: ^5.1.1
|
||||
graphql_codegen: ^0.9.0
|
||||
graphql_flutter: ^5.1.0
|
||||
gtk_theme_fl: ^0.0.1
|
||||
hive: ^2.0.5
|
||||
hive_flutter: ^1.1.0
|
||||
|
|
|
@ -6,11 +6,14 @@
|
|||
|
||||
#include "generated_plugin_registrant.h"
|
||||
|
||||
#include <connectivity_plus_windows/connectivity_plus_windows_plugin.h>
|
||||
#include <flutter_secure_storage_windows/flutter_secure_storage_windows_plugin.h>
|
||||
#include <system_theme/system_theme_plugin.h>
|
||||
#include <url_launcher_windows/url_launcher_windows.h>
|
||||
|
||||
void RegisterPlugins(flutter::PluginRegistry* registry) {
|
||||
ConnectivityPlusWindowsPluginRegisterWithRegistrar(
|
||||
registry->GetRegistrarForPlugin("ConnectivityPlusWindowsPlugin"));
|
||||
FlutterSecureStorageWindowsPluginRegisterWithRegistrar(
|
||||
registry->GetRegistrarForPlugin("FlutterSecureStorageWindowsPlugin"));
|
||||
SystemThemePluginRegisterWithRegistrar(
|
||||
|
|
|
@ -3,6 +3,7 @@
|
|||
#
|
||||
|
||||
list(APPEND FLUTTER_PLUGIN_LIST
|
||||
connectivity_plus_windows
|
||||
flutter_secure_storage_windows
|
||||
system_theme
|
||||
url_launcher_windows
|
||||
|
|
Loading…
Reference in a new issue