Skip to content

Commit f682a5a

Browse files
authored
feat(cloud_hub): Implement ProjectEnvironments service (#308)
- Implements all but `DeployProjectEnvironment` - Improves E2E test performance by precompiling Cloud Hub - Updates triggers for consistency
1 parent a4a4968 commit f682a5a

21 files changed

+1770
-387
lines changed

.github/workflows/celest_cloud_hub.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,4 +46,4 @@ jobs:
4646
run: dart pub upgrade
4747
- name: Test
4848
working-directory: services/celest_cloud_hub
49-
run: dart test --fail-fast
49+
run: dart test --fail-fast -j1

packages/celest_cloud/lib/src/cloud/project_environments/project_environments.dart

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ final class ProjectEnvironments with BaseService {
113113
);
114114
}
115115

116-
CloudOperation<Empty> delete(
116+
CloudOperation<ProjectEnvironment> delete(
117117
String name, {
118118
String? etag,
119119
bool allowMissing = false,
@@ -133,7 +133,7 @@ final class ProjectEnvironments with BaseService {
133133
yield* operation.stream(
134134
operations: _operations,
135135
logger: logger,
136-
response: Empty(),
136+
response: ProjectEnvironment(),
137137
metadata: OperationMetadata(),
138138
);
139139
}

proto/celest/cloud/v1alpha1/project_environments.proto

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,11 +60,13 @@ service ProjectEnvironments {
6060
}
6161

6262
// Deletes an environment.
63+
//
64+
// TODO: Add UndeleteProjectEnvironment
6365
rpc DeleteProjectEnvironment(DeleteProjectEnvironmentRequest) returns (google.longrunning.Operation) {
6466
option (google.api.http) = { delete: "/v1alpha1/{name=projects/*/environments/*}" };
6567
option (google.api.method_signature) = "name";
6668
option (google.longrunning.operation_info) = {
67-
response_type: "google.protobuf.Empty"
69+
response_type: "ProjectEnvironment"
6870
metadata_type: "OperationMetadata"
6971
};
7072
}
Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,77 +1,83 @@
11
// Users can view project environmentss they are viewers of.
22
@id("cloud.projects.environments.viewer")
33
permit (
4-
principal is Celest::Project::Member,
4+
principal,
55
action in Celest::Action::"view",
66
resource is Celest::Project::Environment
77
)
88
when
99
{
10+
(principal is Celest::Project::Member || principal is Celest::Project::Environment::Member) &&
1011
resource in principal.parent &&
1112
principal.role == Celest::Role::"viewer"
1213
};
1314

1415
// Users can edit project environments they are editors of.
1516
@id("cloud.projects.environments.editor")
1617
permit (
17-
principal is Celest::Project::Member,
18+
principal,
1819
action in Celest::Action::"edit",
1920
resource is Celest::Project::Environment
2021
)
2122
when
2223
{
24+
(principal is Celest::Project::Member || principal is Celest::Project::Environment::Member) &&
2325
resource in principal.parent &&
2426
principal.role == Celest::Role::"editor"
2527
};
2628

2729
// Users can do anything but delete project environments they are admins of.
2830
@id("cloud.projects.environments.admin")
2931
permit (
30-
principal is Celest::Project::Member,
32+
principal,
3133
action in Celest::Action::"admin",
3234
resource is Celest::Project::Environment
3335
)
3436
when
3537
{
38+
(principal is Celest::Project::Member || principal is Celest::Project::Environment::Member) &&
3639
resource in principal.parent &&
3740
principal.role == Celest::Role::"admin"
3841
};
3942

4043
// Users can do anything to environments they are owners of.
4144
@id("cloud.projects.environments.owner")
4245
permit (
43-
principal is Celest::Project::Member,
46+
principal,
4447
action in Celest::Action::"owner",
4548
resource is Celest::Project::Environment
4649
)
4750
when
4851
{
52+
(principal is Celest::Project::Member || principal is Celest::Project::Environment::Member) &&
4953
resource in principal.parent &&
5054
principal.role == Celest::Role::"owner"
5155
};
5256

5357
// Users can create environments in projects they have admin access to.
5458
@id("cloud.projects.environments.creator")
5559
permit (
56-
principal is Celest::Project::Member,
60+
principal,
5761
action == Celest::Action::"create",
5862
resource is Celest::Project::Environment
5963
)
6064
when
6165
{
66+
(principal is Celest::Project::Member || principal is Celest::Project::Environment::Member) &&
6267
resource in principal.parent &&
6368
principal.role in Celest::Role::"admin"
6469
};
6570

6671
// Members can deploy environments in projects they have deploy or admin access to.
6772
@id("cloud.projects.environments.deployer")
6873
permit (
69-
principal is Celest::Project::Member,
70-
action == Celest::Project::Environment::Action::"deploy",
74+
principal,
75+
action == Celest::Action::"deploy",
7176
resource is Celest::Project::Environment
7277
)
7378
when
7479
{
80+
(principal is Celest::Project::Member || principal is Celest::Project::Environment::Member) &&
7581
resource in principal.parent &&
7682
principal.role in Celest::Role::"admin"
7783
};

services/celest_cloud_hub/lib/src/auth/policy_set.g.dart

Lines changed: 13 additions & 7 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

services/celest_cloud_hub/lib/src/database/cloud_hub_database.dart

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,7 @@ final class CloudHubDatabase extends $CloudHubDatabase
9696
// Fail if the action broke foreign keys
9797
final wrongForeignKeys =
9898
await customSelect('PRAGMA foreign_key_check').get();
99+
await _dumpBrokenCedarForeignKeys();
99100
assert(
100101
wrongForeignKeys.isEmpty,
101102
'${wrongForeignKeys.map((e) => e.data)}',

services/celest_cloud_hub/lib/src/database/cloud_hub_database.drift.dart

Lines changed: 75 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -159,18 +159,19 @@ abstract class $CloudHubDatabase extends i0.GeneratedDatabase {
159159
i6.projectsDeleteUserMembershipsTrg,
160160
projectEnvironments,
161161
i6.projectEnvironmentsDeleteUserMembershipsTrg,
162-
i9.projectEnvironmentsTriggerUpdateTime,
162+
i9.projectEnvironmentsParentIdx,
163+
i9.projectEnvironmentsUpdateTimeTrg,
164+
i9.projectEnvironmentsCreateTrg,
165+
i9.projectEnvironmentsSetParentTrg,
166+
i9.projectEnvironmentsDeleteTrg,
163167
projectEnvironmentAsts,
164168
projectEnvironmentAssets,
165169
projectEnvironmentStates,
166170
i8.projectsFkParentIdx,
167-
i8.projectsUpdateTime,
168-
i8.celestCloudProjectsTriggerCreate,
169-
i8.celestCloudProjectsTriggerCreateParent,
170-
i8.celestCloudProjectsTriggerAddParent,
171-
i8.celestCloudProjectsTriggerSetParent,
172-
i8.celestCloudProjectsTriggerRemoveParent,
173-
i8.celestCloudProjectsTriggerDelete,
171+
i8.projectsUpdateTimeTrg,
172+
i8.projectsCreateTrg,
173+
i8.projectsSetParentTrg,
174+
i8.projectsDeleteTrg,
174175
i7.organizationsParentIdx,
175176
i7.organizationsUpdateTime,
176177
i7.organizationsCreate,
@@ -625,6 +626,42 @@ abstract class $CloudHubDatabase extends i0.GeneratedDatabase {
625626
),
626627
result: [i0.TableUpdate('user_memberships', kind: i0.UpdateKind.delete)],
627628
),
629+
i0.WritePropagation(
630+
on: i0.TableUpdateQuery.onTableName(
631+
'cedar_entities',
632+
limitUpdateKind: i0.UpdateKind.delete,
633+
),
634+
result: [
635+
i0.TableUpdate('project_environments', kind: i0.UpdateKind.delete),
636+
],
637+
),
638+
i0.WritePropagation(
639+
on: i0.TableUpdateQuery.onTableName(
640+
'cedar_entities',
641+
limitUpdateKind: i0.UpdateKind.update,
642+
),
643+
result: [
644+
i0.TableUpdate('project_environments', kind: i0.UpdateKind.update),
645+
],
646+
),
647+
i0.WritePropagation(
648+
on: i0.TableUpdateQuery.onTableName(
649+
'projects',
650+
limitUpdateKind: i0.UpdateKind.delete,
651+
),
652+
result: [
653+
i0.TableUpdate('project_environments', kind: i0.UpdateKind.delete),
654+
],
655+
),
656+
i0.WritePropagation(
657+
on: i0.TableUpdateQuery.onTableName(
658+
'projects',
659+
limitUpdateKind: i0.UpdateKind.update,
660+
),
661+
result: [
662+
i0.TableUpdate('project_environments', kind: i0.UpdateKind.update),
663+
],
664+
),
628665
i0.WritePropagation(
629666
on: i0.TableUpdateQuery.onTableName(
630667
'project_environments',
@@ -641,6 +678,35 @@ abstract class $CloudHubDatabase extends i0.GeneratedDatabase {
641678
i0.TableUpdate('project_environments', kind: i0.UpdateKind.update),
642679
],
643680
),
681+
i0.WritePropagation(
682+
on: i0.TableUpdateQuery.onTableName(
683+
'project_environments',
684+
limitUpdateKind: i0.UpdateKind.insert,
685+
),
686+
result: [
687+
i0.TableUpdate('cedar_entities', kind: i0.UpdateKind.insert),
688+
i0.TableUpdate('cedar_relationships', kind: i0.UpdateKind.insert),
689+
],
690+
),
691+
i0.WritePropagation(
692+
on: i0.TableUpdateQuery.onTableName(
693+
'project_environments',
694+
limitUpdateKind: i0.UpdateKind.update,
695+
),
696+
result: [
697+
i0.TableUpdate('cedar_relationships', kind: i0.UpdateKind.update),
698+
],
699+
),
700+
i0.WritePropagation(
701+
on: i0.TableUpdateQuery.onTableName(
702+
'project_environments',
703+
limitUpdateKind: i0.UpdateKind.delete,
704+
),
705+
result: [
706+
i0.TableUpdate('cedar_relationships', kind: i0.UpdateKind.delete),
707+
i0.TableUpdate('cedar_entities', kind: i0.UpdateKind.delete),
708+
],
709+
),
644710
i0.WritePropagation(
645711
on: i0.TableUpdateQuery.onTableName(
646712
'project_environments',
@@ -719,23 +785,8 @@ abstract class $CloudHubDatabase extends i0.GeneratedDatabase {
719785
'projects',
720786
limitUpdateKind: i0.UpdateKind.insert,
721787
),
722-
result: [i0.TableUpdate('cedar_entities', kind: i0.UpdateKind.insert)],
723-
),
724-
i0.WritePropagation(
725-
on: i0.TableUpdateQuery.onTableName(
726-
'projects',
727-
limitUpdateKind: i0.UpdateKind.insert,
728-
),
729-
result: [
730-
i0.TableUpdate('cedar_relationships', kind: i0.UpdateKind.insert),
731-
],
732-
),
733-
i0.WritePropagation(
734-
on: i0.TableUpdateQuery.onTableName(
735-
'projects',
736-
limitUpdateKind: i0.UpdateKind.update,
737-
),
738788
result: [
789+
i0.TableUpdate('cedar_entities', kind: i0.UpdateKind.insert),
739790
i0.TableUpdate('cedar_relationships', kind: i0.UpdateKind.insert),
740791
],
741792
),
@@ -748,15 +799,6 @@ abstract class $CloudHubDatabase extends i0.GeneratedDatabase {
748799
i0.TableUpdate('cedar_relationships', kind: i0.UpdateKind.update),
749800
],
750801
),
751-
i0.WritePropagation(
752-
on: i0.TableUpdateQuery.onTableName(
753-
'projects',
754-
limitUpdateKind: i0.UpdateKind.update,
755-
),
756-
result: [
757-
i0.TableUpdate('cedar_relationships', kind: i0.UpdateKind.delete),
758-
],
759-
),
760802
i0.WritePropagation(
761803
on: i0.TableUpdateQuery.onTableName(
762804
'projects',

0 commit comments

Comments
 (0)