57 lines
1.3 KiB
Dart
57 lines
1.3 KiB
Dart
import 'package:softplayer_dart_proto/main.dart';
|
|
import 'package:softplayer_web/api/grpc/creds.dart';
|
|
|
|
class EnvironmentLocalData {
|
|
EnvironmentLocalData({
|
|
required this.uuid,
|
|
required this.token,
|
|
});
|
|
|
|
String uuid;
|
|
String token;
|
|
}
|
|
|
|
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<EnvironmentFull> get(String name, SoftplayerCreds creds) async {
|
|
final request = GetOptions(
|
|
name: EnvironmentName(name: name),
|
|
ownerId: OwnerId(uuid: creds.uuid),
|
|
token: Token(token: creds.token),
|
|
);
|
|
|
|
try {
|
|
final response = await envStub.get(request);
|
|
return response;
|
|
} catch (e) {
|
|
rethrow;
|
|
}
|
|
}
|
|
|
|
Stream<List<EnvironmentFull>> list(SoftplayerCreds creds) async* {
|
|
List<EnvironmentFull> envs = [];
|
|
try {
|
|
await for (var feature in envStub.list(
|
|
ListOptions(
|
|
ownerId: OwnerId(uuid: creds.uuid),
|
|
token: Token(token: creds.token),
|
|
),
|
|
)) {
|
|
envs.add(EnvironmentFull(
|
|
data: feature.data,
|
|
name: feature.name,
|
|
));
|
|
}
|
|
} catch (e) {
|
|
rethrow;
|
|
}
|
|
yield envs;
|
|
}
|
|
}
|