Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore(cloud): Clean up #166

Merged
merged 1 commit into from
Aug 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion packages/celest_auth/lib/src/auth_impl.dart
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ final class AuthImpl implements Auth {
return const Unauthenticated();
}
try {
final user = await cloud.users.get('me');
final user = await cloud.users.get('users/me');
initialState = Authenticated(user: user.toCelest());
} on UnauthorizedException {
initialState = const Unauthenticated();
Expand Down
8 changes: 7 additions & 1 deletion packages/celest_cloud/lib/celest_cloud.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,13 @@ export 'package:protobuf/protobuf.dart' show GeneratedMessageGenericExtensions;
export 'src/cloud/authentication/session_state.dart';
export 'src/cloud/cloud.dart';
export 'src/proto.dart'
show Organization, CreateOrganizationMetadata, OperationMetadata;
show
Organization,
Organization_State,
CreateOrganizationMetadata,
OperationMetadata,
Project,
Project_State;
export 'src/proto/celest/cloud/auth/v1alpha1/authentication.pb.dart'
show ClientType;
export 'src/proto/celest/cloud/auth/v1alpha1/users.pb.dart'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import 'dart:convert';

import 'package:celest_cloud/src/cloud/authentication/authentication_protocol.dart';
import 'package:celest_cloud/src/cloud/base/base_protocol.dart';
import 'package:celest_cloud/src/cloud/cloud.dart';
import 'package:celest_cloud/src/proto/celest/cloud/auth/v1alpha1/authentication.pb.dart';
import 'package:http/http.dart' as http;

Expand All @@ -25,7 +26,9 @@ final class AuthenticationProtocolHttp
};
final uri = _baseUri.replace(path: path);
final req = http.Request('POST', uri)
..body = jsonEncode(request.toProto3Json())
..body = jsonEncode(request.toProto3Json(
typeRegistry: CelestCloud.typeRegistry,
))
..headers['content-type'] = 'application/json'
..headers['accept'] = 'application/json';
final res = await _client.send(req);
Expand All @@ -36,15 +39,21 @@ final class AuthenticationProtocolHttp
body: body,
);
}
return Session()..mergeFromProto3Json(jsonDecode(body));
return Session()
..mergeFromProto3Json(
jsonDecode(body),
typeRegistry: CelestCloud.typeRegistry,
);
}

@override
Future<Session> continueSession(ContinueSessionRequest request) async {
final path = '/v1alpha1/auth/sessions/${request.sessionId}:continueSession';
final path = '/v1alpha1/auth/sessions:continueSession';
final uri = _baseUri.replace(path: path);
final req = http.Request('POST', uri)
..body = jsonEncode(request.toProto3Json())
..body = jsonEncode(request.toProto3Json(
typeRegistry: CelestCloud.typeRegistry,
))
..headers['content-type'] = 'application/json'
..headers['accept'] = 'application/json';
final res = await _client.send(req);
Expand All @@ -55,15 +64,21 @@ final class AuthenticationProtocolHttp
body: body,
);
}
return Session()..mergeFromProto3Json(jsonDecode(body));
return Session()
..mergeFromProto3Json(
jsonDecode(body),
typeRegistry: CelestCloud.typeRegistry,
);
}

@override
Future<EndSessionResponse> endSession(EndSessionRequest request) async {
const path = '/v1alpha1/auth:endSession';
const path = '/v1alpha1/auth/sessions:endSession';
final uri = _baseUri.replace(path: path);
final req = http.Request('POST', uri)
..body = jsonEncode(request.toProto3Json())
..body = jsonEncode(request.toProto3Json(
typeRegistry: CelestCloud.typeRegistry,
))
..headers['content-type'] = 'application/json'
..headers['accept'] = 'application/json';
final res = await _client.send(req);
Expand All @@ -74,6 +89,10 @@ final class AuthenticationProtocolHttp
body: body,
);
}
return EndSessionResponse()..mergeFromProto3Json(jsonDecode(body));
return EndSessionResponse()
..mergeFromProto3Json(
jsonDecode(body),
typeRegistry: CelestCloud.typeRegistry,
);
}
}
20 changes: 19 additions & 1 deletion packages/celest_cloud/lib/src/cloud/cloud.dart
Original file line number Diff line number Diff line change
@@ -1,14 +1,16 @@
import 'package:celest_cloud/celest_cloud.dart';
import 'package:celest_cloud/src/cloud/authentication/authentication.dart';
import 'package:celest_cloud/src/cloud/cloud_protocol.dart';
import 'package:celest_cloud/src/cloud/cloud_protocol.grpc.dart';
import 'package:celest_cloud/src/cloud/cloud_protocol.http.dart';
import 'package:celest_cloud/src/cloud/organizations/organizations.dart';
import 'package:celest_cloud/src/cloud/projects/projects.dart';
import 'package:celest_cloud/src/cloud/users/users.dart';
import 'package:celest_cloud/src/proto.dart';
import 'package:celest_core/_internal.dart';
import 'package:http/http.dart' as http;
import 'package:logging/logging.dart';
import 'package:os_detect/os_detect.dart' as os;
import 'package:protobuf/protobuf.dart';

class CelestCloud {
CelestCloud({
Expand Down Expand Up @@ -49,6 +51,16 @@ class CelestCloud {
? ClientType.LINUX
: ClientType.CLIENT_TYPE_UNSPECIFIED;

static final typeRegistry = TypeRegistry([
Empty(),
OperationMetadata(),
Organization(),
CreateOrganizationMetadata(),
Project(),
CreateEnvironmentMetadata(),
DeploymentOperationMetadata(),
]);

final CloudProtocol _protocol;
final ClientType _clientType;
final Logger _logger;
Expand All @@ -69,4 +81,10 @@ class CelestCloud {
protocol: _protocol.users,
logger: _logger,
);

late final Projects projects = Projects(
protocol: _protocol.projects,
operations: _protocol.operations,
logger: _logger,
);
}
2 changes: 2 additions & 0 deletions packages/celest_cloud/lib/src/cloud/cloud_protocol.dart
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
import 'package:celest_cloud/src/cloud/authentication/authentication_protocol.dart';
import 'package:celest_cloud/src/cloud/operations/operations_protocol.dart';
import 'package:celest_cloud/src/cloud/organizations/organizations_protocol.dart';
import 'package:celest_cloud/src/cloud/projects/projects_protocol.dart';
import 'package:celest_cloud/src/cloud/users/users_protocol.dart';

abstract interface class CloudProtocol {
AuthenticationProtocol get authentication;
OrganizationsProtocol get organizations;
OperationsProtocol get operations;
UsersProtocol get users;
ProjectsProtocol get projects;
}
6 changes: 6 additions & 0 deletions packages/celest_cloud/lib/src/cloud/cloud_protocol.grpc.dart
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ import 'package:celest_cloud/src/cloud/operations/operations_protocol.dart';
import 'package:celest_cloud/src/cloud/operations/operations_protocol.grpc.dart';
import 'package:celest_cloud/src/cloud/organizations/organizations_protocol.dart';
import 'package:celest_cloud/src/cloud/organizations/organizations_protocol.grpc.dart';
import 'package:celest_cloud/src/cloud/projects/projects_protocol.dart';
import 'package:celest_cloud/src/cloud/projects/projects_protocol.grpc.dart';
import 'package:celest_cloud/src/cloud/users/users_protocol.dart';
import 'package:celest_cloud/src/cloud/users/users_protocol.grpc.dart';
import 'package:celest_core/_internal.dart';
Expand Down Expand Up @@ -60,4 +62,8 @@ final class CloudProtocolGrpc implements CloudProtocol {
@override
late final UsersProtocol users =
UsersProtocolGrpc(_channel, interceptors: _interceptors);

@override
late final ProjectsProtocol projects =
ProjectsProtocolGrpc(_channel, interceptors: _interceptors);
}
13 changes: 10 additions & 3 deletions packages/celest_cloud/lib/src/cloud/cloud_protocol.http.dart
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
import 'package:celest_cloud/src/cloud/authentication/authentication_protocol.dart';
import 'package:celest_cloud/src/cloud/authentication/authentication_protocol.http.dart';
import 'package:celest_cloud/src/cloud/base/base_http_client.dart';
import 'package:celest_cloud/src/cloud/cloud_protocol.dart';
import 'package:celest_cloud/src/cloud/operations/operations_protocol.dart';
import 'package:celest_cloud/src/cloud/operations/operations_protocol.http.dart';
import 'package:celest_cloud/src/cloud/organizations/organizations_protocol.dart';
import 'package:celest_cloud/src/cloud/organizations/organizations_protocol.http.dart';
import 'package:celest_cloud/src/cloud/projects/projects_protocol.dart';
import 'package:celest_cloud/src/cloud/projects/projects_protocol.http.dart';
import 'package:celest_cloud/src/cloud/users/users_protocol.dart';
import 'package:celest_cloud/src/cloud/users/users_protocol.http.dart';
import 'package:celest_core/_internal.dart';
Expand All @@ -18,8 +19,8 @@ final class CloudProtocolHttp implements CloudProtocol {
required Authenticator authenticator,
http.Client? httpClient,
Logger? logger,
}) : _client = AuthenticatingHttpClient(
client: httpClient ?? http.Client(),
}) : _client = CelestHttpClient(
baseClient: httpClient,
authenticator: authenticator,
logger: logger,
),
Expand Down Expand Up @@ -51,4 +52,10 @@ final class CloudProtocolHttp implements CloudProtocol {
uri: _baseUri,
httpClient: _client,
);

@override
late final ProjectsProtocol projects = ProjectsProtocolHttp(
uri: _baseUri,
httpClient: _client,
);
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import 'dart:convert';

import 'package:celest_cloud/src/cloud/base/base_protocol.dart';
import 'package:celest_cloud/src/cloud/cloud.dart';
import 'package:celest_cloud/src/cloud/operations/operations_protocol.dart';
import 'package:celest_cloud/src/proto.dart';
import 'package:http/http.dart' as http;
Expand All @@ -22,7 +23,9 @@ final class OperationsProtocolHttp
final path = '/v1alpha1/${request.name}:cancel';
final url = _baseUri.replace(path: path);
final req = http.Request('POST', url)
..body = jsonEncode(request.toProto3Json())
..body = jsonEncode(request.toProto3Json(
typeRegistry: CelestCloud.typeRegistry,
))
..headers['content-type'] = 'application/json'
..headers['accept'] = 'application/json';
final res = await _client.send(req);
Expand Down Expand Up @@ -50,12 +53,19 @@ final class OperationsProtocolHttp
body: body,
);
}
return Operation()..mergeFromProto3Json(jsonDecode(body));
return Operation()
..mergeFromProto3Json(
jsonDecode(body),
typeRegistry: CelestCloud.typeRegistry,
);
}

@override
Future<ListOperationsResponse> list(ListOperationsRequest request) async {
const path = '/v1alpha1/operations';
if (request.name == '') {
throw ArgumentError.value(request.name, 'name', 'must not be empty');
}
final path = '/v1alpha1/${request.name}/operations';
final url = _baseUri.replace(
path: path,
queryParameters: {
Expand All @@ -75,6 +85,10 @@ final class OperationsProtocolHttp
body: body,
);
}
return ListOperationsResponse()..mergeFromProto3Json(jsonDecode(body));
return ListOperationsResponse()
..mergeFromProto3Json(
jsonDecode(body),
typeRegistry: CelestCloud.typeRegistry,
);
}
}
Loading
Loading