Remove a lot and start from scratch
Signed-off-by: Nikolai Rodionov <nrodionov@eos-uptrade.de>
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
import 'package:grpc/grpc_web.dart';
|
||||
import 'package:softplayer_dart_proto/main.dart';
|
||||
import 'package:softplayer_dart_proto/src/accounts/v1/accounts_v1.pb.dart';
|
||||
import 'package:softplayer_dart_proto/src/accounts/v1/accounts_v1.pbgrpc.dart';
|
||||
|
||||
class AccountLocalData {
|
||||
AccountLocalData({
|
||||
@@ -12,36 +13,18 @@ class AccountLocalData {
|
||||
|
||||
class AccountsGrpc {
|
||||
final GrpcWebClientChannel channel;
|
||||
late AccountsClient accountsStub;
|
||||
late AccountsServiceClient accountsStub;
|
||||
AccountsGrpc({
|
||||
required this.channel,
|
||||
});
|
||||
|
||||
void init() {
|
||||
accountsStub = AccountsClient(channel);
|
||||
}
|
||||
|
||||
Future<AccountLocalData> signIn(
|
||||
String username, String email, String password) async {
|
||||
final request = AccountWithPassword(
|
||||
data: AccountData(
|
||||
name: username,
|
||||
email: email,
|
||||
),
|
||||
password: AccountPassword(
|
||||
password: password,
|
||||
));
|
||||
try {
|
||||
final response = await accountsStub.signIn(request);
|
||||
return AccountLocalData(uuid: response.id.id, token: response.token);
|
||||
} catch (e) {
|
||||
rethrow;
|
||||
}
|
||||
accountsStub = AccountsServiceClient(channel);
|
||||
}
|
||||
|
||||
Future<AccountLocalData> signUp(
|
||||
String username, String email, String password) async {
|
||||
final request = AccountWithPassword(
|
||||
final request = SignUpRequest(
|
||||
data: AccountData(
|
||||
name: username,
|
||||
email: email,
|
||||
@@ -51,36 +34,7 @@ class AccountsGrpc {
|
||||
));
|
||||
try {
|
||||
final response = await accountsStub.signUp(request);
|
||||
return AccountLocalData(uuid: response.id.id, token: response.token);
|
||||
} catch (e) {
|
||||
rethrow;
|
||||
}
|
||||
}
|
||||
|
||||
Future<Empty> resetPassword(String username, String email) async {
|
||||
final request = AccountData(
|
||||
name: username,
|
||||
email: email,
|
||||
);
|
||||
try {
|
||||
final response = await accountsStub.resetPassword(request);
|
||||
return response;
|
||||
} catch (e) {
|
||||
rethrow;
|
||||
}
|
||||
}
|
||||
|
||||
Future<Empty> newPassword(
|
||||
String username, String code, String newPassword) async {
|
||||
final request = AccountWithPasswordAndCode(
|
||||
data: AccountData(
|
||||
name: username,
|
||||
),
|
||||
code: code,
|
||||
password: AccountPassword(password: newPassword));
|
||||
try {
|
||||
final response = await accountsStub.newPassword(request);
|
||||
return response;
|
||||
return AccountLocalData(uuid: "test", token: "test");
|
||||
} catch (e) {
|
||||
rethrow;
|
||||
}
|
||||
|
||||
@@ -1,106 +0,0 @@
|
||||
import 'package:softplayer_dart_proto/main.dart';
|
||||
import 'package:softplayer_web/api/grpc/creds.dart';
|
||||
|
||||
class EnvironmentLocalData {
|
||||
EnvironmentLocalData(
|
||||
{required this.serverType,
|
||||
required this.serverLocation,
|
||||
required this.provider,
|
||||
required this.name,
|
||||
required this.description,
|
||||
this.uuid});
|
||||
|
||||
final String name;
|
||||
final String description;
|
||||
final String provider;
|
||||
final String serverType;
|
||||
final String serverLocation;
|
||||
String? uuid;
|
||||
}
|
||||
|
||||
class EnvironmentsGrpc {
|
||||
// final GrpcWebClientChannel channel;
|
||||
final EnvironmentsClient envStub;
|
||||
|
||||
// Init the grpc channel for environments
|
||||
EnvironmentsGrpc(channel) : envStub = EnvironmentsClient(channel);
|
||||
|
||||
// Get environments from the API
|
||||
Future<EnvironmentLocalData> get(String uuid, SoftplayerCreds creds) async {
|
||||
final request = GetOptions(
|
||||
id: EnvironmentId(uuid: uuid),
|
||||
ownerId: OwnerId(uuid: creds.uuid),
|
||||
token: Token(token: creds.token),
|
||||
);
|
||||
|
||||
try {
|
||||
final response = await envStub.get(request);
|
||||
return EnvironmentLocalData(
|
||||
uuid: uuid,
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
||||
Future<EnvironmentLocalData> create(
|
||||
EnvironmentLocalData data, SoftplayerCreds creds) async {
|
||||
print(data);
|
||||
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(
|
||||
uuid: response.id.uuid,
|
||||
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(
|
||||
ownerId: OwnerId(uuid: creds.uuid),
|
||||
token: Token(token: creds.token),
|
||||
),
|
||||
)) {
|
||||
envs.add(EnvironmentLocalData(
|
||||
uuid: feature.id.uuid,
|
||||
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) {
|
||||
rethrow;
|
||||
}
|
||||
yield envs;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user