Some updates
This commit is contained in:
@ -2,13 +2,18 @@ import 'package:softplayer_dart_proto/main.dart';
|
||||
import 'package:softplayer_web/api/grpc/creds.dart';
|
||||
|
||||
class EnvironmentLocalData {
|
||||
EnvironmentLocalData({
|
||||
required this.uuid,
|
||||
required this.token,
|
||||
});
|
||||
EnvironmentLocalData(
|
||||
{required this.serverType,
|
||||
required this.serverLocation,
|
||||
required this.provider,
|
||||
required this.name,
|
||||
required this.description});
|
||||
|
||||
String uuid;
|
||||
String token;
|
||||
final String name;
|
||||
final String description;
|
||||
final String provider;
|
||||
final String serverType;
|
||||
final String serverLocation;
|
||||
}
|
||||
|
||||
class EnvironmentsGrpc {
|
||||
@ -19,23 +24,62 @@ class EnvironmentsGrpc {
|
||||
EnvironmentsGrpc(channel) : envStub = EnvironmentsClient(channel);
|
||||
|
||||
// Get environments from the API
|
||||
Future<EnvironmentFull> get(String name, SoftplayerCreds creds) async {
|
||||
Future<EnvironmentLocalData> get(String name, SoftplayerCreds creds) async {
|
||||
final request = GetOptions(
|
||||
name: EnvironmentName(name: name),
|
||||
metadata: EnvironmentMetadata(name: name),
|
||||
ownerId: OwnerId(uuid: creds.uuid),
|
||||
token: Token(token: creds.token),
|
||||
);
|
||||
|
||||
try {
|
||||
final response = await envStub.get(request);
|
||||
return response;
|
||||
return EnvironmentLocalData(
|
||||
serverType: response.spec.serverType.toString(),
|
||||
serverLocation: response.spec.serverLocation.toString(),
|
||||
provider: response.spec.provider.toString(),
|
||||
name: response.metadata.name,
|
||||
description: response.metadata.description);
|
||||
} catch (e) {
|
||||
rethrow;
|
||||
}
|
||||
}
|
||||
|
||||
Stream<List<EnvironmentFull>> list(SoftplayerCreds creds) async* {
|
||||
List<EnvironmentFull> envs = [];
|
||||
Future<EnvironmentLocalData> create(
|
||||
EnvironmentLocalData data, SoftplayerCreds creds) async {
|
||||
Location.values.forEach((element) => print(element.toString() + " - " + data.serverLocation));
|
||||
print(ServerType.values);
|
||||
|
||||
final request = CreateOptions(
|
||||
metadata:
|
||||
EnvironmentMetadata(description: data.description, name: data.name),
|
||||
spec: EnvironmentSpec(
|
||||
// Currently we do not support other kinds
|
||||
kubernetes: Kubernetes.KUBERNETES_K3S,
|
||||
// Currently we do not support other providers
|
||||
provider: Provider.PROVIDER_HETZNER,
|
||||
serverLocation: Location.values
|
||||
.firstWhere((e) => e.toString() == data.serverLocation),
|
||||
serverType: ServerType.values
|
||||
.firstWhere((e) => e.toString() == data.serverType),
|
||||
),
|
||||
ownerId: OwnerId(uuid: creds.uuid),
|
||||
token: Token(token: creds.token),
|
||||
);
|
||||
try {
|
||||
final response = await envStub.create(request);
|
||||
return EnvironmentLocalData(
|
||||
serverType: response.spec.serverType.toString(),
|
||||
serverLocation: response.spec.serverLocation.toString(),
|
||||
provider: response.spec.provider.toString(),
|
||||
name: response.metadata.name,
|
||||
description: response.metadata.description);
|
||||
} catch (e) {
|
||||
rethrow;
|
||||
}
|
||||
}
|
||||
|
||||
Stream<List<EnvironmentLocalData>> list(SoftplayerCreds creds) async* {
|
||||
List<EnvironmentLocalData> envs = [];
|
||||
try {
|
||||
await for (var feature in envStub.list(
|
||||
ListOptions(
|
||||
@ -43,9 +87,12 @@ class EnvironmentsGrpc {
|
||||
token: Token(token: creds.token),
|
||||
),
|
||||
)) {
|
||||
envs.add(EnvironmentFull(
|
||||
data: feature.data,
|
||||
name: feature.name,
|
||||
envs.add(EnvironmentLocalData(
|
||||
serverType: feature.spec.serverType.toString(),
|
||||
serverLocation: feature.spec.serverLocation.toString(),
|
||||
provider: feature.spec.provider.toString(),
|
||||
name: feature.metadata.name,
|
||||
description: feature.metadata.description,
|
||||
));
|
||||
}
|
||||
} catch (e) {
|
||||
|
Reference in New Issue
Block a user