mirror of
https://git.selfprivacy.org/kherel/selfprivacy.org.app.git
synced 2024-11-10 10:53:12 +00:00
fix(recovery): Implement server type id requesting on recovery finish
This commit is contained in:
parent
51f5bb9f31
commit
80f28463ec
|
@ -721,12 +721,15 @@ class ServerInstallationCubit extends Cubit<ServerInstallationState> {
|
||||||
await repository.saveIsServerResetedSecondTime(true);
|
await repository.saveIsServerResetedSecondTime(true);
|
||||||
await repository.saveHasFinalChecked(true);
|
await repository.saveHasFinalChecked(true);
|
||||||
await repository.saveIsRecoveringServer(false);
|
await repository.saveIsRecoveringServer(false);
|
||||||
|
final serverInfo = await ProvidersController.currentServerProvider!
|
||||||
|
.getServerInfo(state.serverDetails!.id);
|
||||||
final User mainUser = await repository.getMainUser();
|
final User mainUser = await repository.getMainUser();
|
||||||
await repository.saveRootUser(mainUser);
|
await repository.saveRootUser(mainUser);
|
||||||
final ServerInstallationRecovery updatedState =
|
final ServerInstallationRecovery updatedState =
|
||||||
(state as ServerInstallationRecovery).copyWith(
|
(state as ServerInstallationRecovery).copyWith(
|
||||||
backblazeCredential: backblazeCredential,
|
backblazeCredential: backblazeCredential,
|
||||||
rootUser: mainUser,
|
rootUser: mainUser,
|
||||||
|
serverTypeIdentificator: serverInfo.data?.serverTypeId ?? '',
|
||||||
);
|
);
|
||||||
emit(updatedState.finish());
|
emit(updatedState.finish());
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,12 +3,14 @@ class ServerBasicInfo {
|
||||||
required this.id,
|
required this.id,
|
||||||
required this.name,
|
required this.name,
|
||||||
required this.reverseDns,
|
required this.reverseDns,
|
||||||
|
required this.serverTypeId,
|
||||||
required this.ip,
|
required this.ip,
|
||||||
required this.created,
|
required this.created,
|
||||||
});
|
});
|
||||||
final int id;
|
final int id;
|
||||||
final String name;
|
final String name;
|
||||||
final String reverseDns;
|
final String reverseDns;
|
||||||
|
final String serverTypeId;
|
||||||
final String ip;
|
final String ip;
|
||||||
final DateTime created;
|
final DateTime created;
|
||||||
}
|
}
|
||||||
|
@ -22,6 +24,7 @@ class ServerBasicInfoWithValidators extends ServerBasicInfo {
|
||||||
id: serverBasicInfo.id,
|
id: serverBasicInfo.id,
|
||||||
name: serverBasicInfo.name,
|
name: serverBasicInfo.name,
|
||||||
reverseDns: serverBasicInfo.reverseDns,
|
reverseDns: serverBasicInfo.reverseDns,
|
||||||
|
serverTypeId: serverBasicInfo.serverTypeId,
|
||||||
ip: serverBasicInfo.ip,
|
ip: serverBasicInfo.ip,
|
||||||
created: serverBasicInfo.created,
|
created: serverBasicInfo.created,
|
||||||
isIpValid: isIpValid,
|
isIpValid: isIpValid,
|
||||||
|
@ -32,6 +35,7 @@ class ServerBasicInfoWithValidators extends ServerBasicInfo {
|
||||||
required super.id,
|
required super.id,
|
||||||
required super.name,
|
required super.name,
|
||||||
required super.reverseDns,
|
required super.reverseDns,
|
||||||
|
required super.serverTypeId,
|
||||||
required super.ip,
|
required super.ip,
|
||||||
required super.created,
|
required super.created,
|
||||||
required this.isIpValid,
|
required this.isIpValid,
|
||||||
|
|
|
@ -81,6 +81,7 @@ class DigitalOceanServerProvider extends ServerProvider {
|
||||||
created: DateTime.now(),
|
created: DateTime.now(),
|
||||||
ip: ipv4,
|
ip: ipv4,
|
||||||
name: server['name'],
|
name: server['name'],
|
||||||
|
serverTypeId: server['region']['slug'],
|
||||||
);
|
);
|
||||||
},
|
},
|
||||||
).toList();
|
).toList();
|
||||||
|
@ -88,6 +89,57 @@ class DigitalOceanServerProvider extends ServerProvider {
|
||||||
return GenericResult(success: true, data: servers);
|
return GenericResult(success: true, data: servers);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
Future<GenericResult<ServerBasicInfo?>> getServerInfo(
|
||||||
|
final int serverId,
|
||||||
|
) async {
|
||||||
|
ServerBasicInfo? server;
|
||||||
|
final result = await _adapter.api().getServers();
|
||||||
|
if (result.data.isEmpty || !result.success) {
|
||||||
|
return GenericResult(
|
||||||
|
success: result.success,
|
||||||
|
data: server,
|
||||||
|
code: result.code,
|
||||||
|
message: result.message,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
final rawServers = result.data;
|
||||||
|
for (final rawServer in rawServers) {
|
||||||
|
String? ipv4;
|
||||||
|
if (rawServer['networks']['v4'].isNotEmpty) {
|
||||||
|
for (final v4 in rawServer['networks']['v4']) {
|
||||||
|
if (v4['type'].toString() == 'public') {
|
||||||
|
ipv4 = v4['ip_address'].toString();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
server = ServerBasicInfo(
|
||||||
|
id: rawServer['id'],
|
||||||
|
reverseDns: rawServer['name'],
|
||||||
|
created: DateTime.now(),
|
||||||
|
ip: ipv4!,
|
||||||
|
name: rawServer['name'],
|
||||||
|
serverTypeId: rawServer['region']['slug'],
|
||||||
|
);
|
||||||
|
} catch (e) {
|
||||||
|
print(e);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (server == null) {
|
||||||
|
return GenericResult(
|
||||||
|
success: false,
|
||||||
|
data: server,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
return GenericResult(success: true, data: server);
|
||||||
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Future<GenericResult<CallbackDialogueBranching?>> launchInstallation(
|
Future<GenericResult<CallbackDialogueBranching?>> launchInstallation(
|
||||||
final LaunchInstallationData installationData,
|
final LaunchInstallationData installationData,
|
||||||
|
|
|
@ -77,6 +77,7 @@ class HetznerServerProvider extends ServerProvider {
|
||||||
ip: hetznerServer.publicNet.ipv4!.ip,
|
ip: hetznerServer.publicNet.ipv4!.ip,
|
||||||
reverseDns: hetznerServer.publicNet.ipv4!.reverseDns,
|
reverseDns: hetznerServer.publicNet.ipv4!.reverseDns,
|
||||||
created: hetznerServer.created,
|
created: hetznerServer.created,
|
||||||
|
serverTypeId: hetznerServer.name,
|
||||||
);
|
);
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
continue;
|
continue;
|
||||||
|
@ -88,6 +89,53 @@ class HetznerServerProvider extends ServerProvider {
|
||||||
return GenericResult(success: true, data: servers);
|
return GenericResult(success: true, data: servers);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
Future<GenericResult<ServerBasicInfo?>> getServerInfo(
|
||||||
|
final int serverId,
|
||||||
|
) async {
|
||||||
|
ServerBasicInfo? server;
|
||||||
|
final result = await _adapter.api().getServers();
|
||||||
|
if (result.data.isEmpty || !result.success) {
|
||||||
|
return GenericResult(
|
||||||
|
success: result.success,
|
||||||
|
data: server,
|
||||||
|
code: result.code,
|
||||||
|
message: result.message,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
final List<HetznerServerInfo> hetznerServers = result.data;
|
||||||
|
for (final hetznerServer in hetznerServers) {
|
||||||
|
if (hetznerServer.publicNet.ipv4 == null ||
|
||||||
|
hetznerServer.id != serverId) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
server = ServerBasicInfo(
|
||||||
|
id: hetznerServer.id,
|
||||||
|
name: hetznerServer.name,
|
||||||
|
ip: hetznerServer.publicNet.ipv4!.ip,
|
||||||
|
reverseDns: hetznerServer.publicNet.ipv4!.reverseDns,
|
||||||
|
created: hetznerServer.created,
|
||||||
|
serverTypeId: hetznerServer.serverType.name,
|
||||||
|
);
|
||||||
|
} catch (e) {
|
||||||
|
print(e);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (server == null) {
|
||||||
|
return GenericResult(
|
||||||
|
success: false,
|
||||||
|
data: server,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
return GenericResult(success: true, data: server);
|
||||||
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Future<GenericResult<CallbackDialogueBranching?>> launchInstallation(
|
Future<GenericResult<CallbackDialogueBranching?>> launchInstallation(
|
||||||
final LaunchInstallationData installationData,
|
final LaunchInstallationData installationData,
|
||||||
|
|
|
@ -24,6 +24,13 @@ abstract class ServerProvider {
|
||||||
/// Only with public IPv4 addresses.
|
/// Only with public IPv4 addresses.
|
||||||
Future<GenericResult<List<ServerBasicInfo>>> getServers();
|
Future<GenericResult<List<ServerBasicInfo>>> getServers();
|
||||||
|
|
||||||
|
/// Returns actual [ServerBasicInfo] of the
|
||||||
|
/// requested server entry assigned
|
||||||
|
/// to the authorized user.
|
||||||
|
///
|
||||||
|
/// Only with public IPv4 address.
|
||||||
|
Future<GenericResult<ServerBasicInfo?>> getServerInfo(final int serverId);
|
||||||
|
|
||||||
/// Tries to launch installation of SelfPrivacy on
|
/// Tries to launch installation of SelfPrivacy on
|
||||||
/// the requested server entry for the authorized account.
|
/// the requested server entry for the authorized account.
|
||||||
/// Depending on a server provider, the algorithm
|
/// Depending on a server provider, the algorithm
|
||||||
|
|
Loading…
Reference in a new issue