@microagi/alchemy-gcp 0.9.0 → 0.10.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +28 -0
- package/lib/Providers.d.ts.map +1 -1
- package/lib/Providers.js +3 -1
- package/lib/Providers.js.map +1 -1
- package/lib/Storage/StorageBucketIamMember.d.ts +66 -0
- package/lib/Storage/StorageBucketIamMember.d.ts.map +1 -0
- package/lib/Storage/StorageBucketIamMember.js +130 -0
- package/lib/Storage/StorageBucketIamMember.js.map +1 -0
- package/lib/Storage/index.d.ts +2 -0
- package/lib/Storage/index.d.ts.map +1 -1
- package/lib/Storage/index.js +1 -0
- package/lib/Storage/index.js.map +1 -1
- package/package.json +1 -1
- package/src/Providers.ts +6 -0
- package/src/Storage/StorageBucketIamMember.ts +244 -0
- package/src/Storage/index.ts +8 -0
package/CHANGELOG.md
CHANGED
|
@@ -4,6 +4,34 @@ All notable changes to `@microagi/alchemy-gcp`. The format follows
|
|
|
4
4
|
[Keep a Changelog](https://keepachangelog.com/en/1.1.0/); this package
|
|
5
5
|
adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
|
6
6
|
|
|
7
|
+
## 0.10.0 — 2026-07-02
|
|
8
|
+
|
|
9
|
+
### Added
|
|
10
|
+
|
|
11
|
+
- **`GCP.StorageBucketIamMember`** — standalone resource managing a
|
|
12
|
+
single `(bucket, role, member)` IAM entry on an **existing** GCS
|
|
13
|
+
bucket by raw name (a bucket the stack does not create, adopt, or
|
|
14
|
+
delete). Unlike the `storageBucketIamMember` binding helper — which
|
|
15
|
+
requires a stack-owned `StorageBucket` target and is additive-only —
|
|
16
|
+
this resource **revokes the member on delete** (dropping the binding
|
|
17
|
+
if emptied), so grants disappear when the declaring resource leaves
|
|
18
|
+
the stack. Member-scoped read-modify-write preserves all foreign
|
|
19
|
+
roles/members verbatim; the get→set cycle retries with backoff for
|
|
20
|
+
etag races; a missing bucket fails fast as `ConfigError`. `diff`
|
|
21
|
+
replaces on any change to the triple (persisted `output` checked
|
|
22
|
+
first, `||`-fallback so empty persisted fields are never treated as
|
|
23
|
+
a prior identity); `read` reports member absence as drift so the
|
|
24
|
+
engine re-grants. First consumer: research-infra's collab-reconciler
|
|
25
|
+
per-group bucket read grants.
|
|
26
|
+
|
|
27
|
+
## 0.9.0 — 2026-06-30
|
|
28
|
+
|
|
29
|
+
### Added
|
|
30
|
+
|
|
31
|
+
- **`GCP.HelmRelease`** — Alchemy resource for managing Helm chart
|
|
32
|
+
releases on GKE clusters (#8). _(Entry backfilled — 0.9.0 shipped
|
|
33
|
+
without a changelog entry.)_
|
|
34
|
+
|
|
7
35
|
## 0.8.0 — 2026-06-17
|
|
8
36
|
|
|
9
37
|
### Added
|
package/lib/Providers.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Providers.d.ts","sourceRoot":"","sources":["../src/Providers.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,QAAQ,MAAM,kBAAkB,CAAC;AAC7C,OAAO,KAAK,KAAK,MAAM,cAAc,CAAC;;
|
|
1
|
+
{"version":3,"file":"Providers.d.ts","sourceRoot":"","sources":["../src/Providers.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,QAAQ,MAAM,kBAAkB,CAAC;AAC7C,OAAO,KAAK,KAAK,MAAM,cAAc,CAAC;;AAmEtC,qBAAa,SAAU,SAAQ,cAA+C;CAAG;AAEjF,MAAM,MAAM,oBAAoB,GAAG,KAAK,CAAC,QAAQ,CAAC,UAAU,CAAC,OAAO,SAAS,CAAC,CAAC,CAAC;AAEhF;;;;;;;;;;;;;;GAcG;AACH,eAAO,MAAM,SAAS,gaAuEnB,CAAC"}
|
package/lib/Providers.js
CHANGED
|
@@ -24,6 +24,7 @@ import { Job, JobProvider } from "./Run/Job.js";
|
|
|
24
24
|
import { Service, ServiceProvider } from "./Run/Service.js";
|
|
25
25
|
import { PsaConnection, PsaConnectionProvider, } from "./ServiceNetworking/PsaConnection.js";
|
|
26
26
|
import { StorageBucket, StorageBucketProvider, } from "./Storage/Bucket.js";
|
|
27
|
+
import { StorageBucketIamMember, StorageBucketIamMemberProvider, } from "./Storage/StorageBucketIamMember.js";
|
|
27
28
|
import { ApiEnable, ApiEnableProvider } from "./ServiceUsage/ApiEnable.js";
|
|
28
29
|
import { SqlDatabase, SqlDatabaseProvider } from "./Sqladmin/Database.js";
|
|
29
30
|
import { SqlInstance, SqlInstanceProvider } from "./Sqladmin/Instance.js";
|
|
@@ -61,6 +62,7 @@ export const providers = () => Layer.effect(Providers, Provider.collection([
|
|
|
61
62
|
PsaConnection,
|
|
62
63
|
ManagedLustreInstance,
|
|
63
64
|
StorageBucket,
|
|
65
|
+
StorageBucketIamMember,
|
|
64
66
|
Service,
|
|
65
67
|
Job,
|
|
66
68
|
SqlInstance,
|
|
@@ -72,7 +74,7 @@ export const providers = () => Layer.effect(Providers, Provider.collection([
|
|
|
72
74
|
KubernetesSecret,
|
|
73
75
|
KubernetesManifest,
|
|
74
76
|
HelmRelease,
|
|
75
|
-
])).pipe(Layer.provide(Layer.mergeAll(ProjectProvider(), ClusterProvider(), NodePoolProvider(), ApiEnableProvider(), NetworkProvider(), SubnetworkProvider(), FirewallProvider(), AddressProvider(), ForwardingRuleProvider(), GlobalAddressProvider(), SharedVpcHostProvider(), SharedVpcServiceProjectProvider(), PsaConnectionProvider(), ManagedLustreInstanceProvider(), StorageBucketProvider(), ServiceProvider(), JobProvider(), SqlInstanceProvider(), SqlDatabaseProvider(), SqlUserProvider(), ArtifactRegistryRepositoryProvider(), ServiceAccountProvider(), ServiceAccountKeyProvider(), KubernetesSecretProvider(), KubernetesManifestProvider(), HelmReleaseProvider())), Layer.provideMerge(fromAuthProvider()), Layer.provideMerge(GCPAuth),
|
|
77
|
+
])).pipe(Layer.provide(Layer.mergeAll(ProjectProvider(), ClusterProvider(), NodePoolProvider(), ApiEnableProvider(), NetworkProvider(), SubnetworkProvider(), FirewallProvider(), AddressProvider(), ForwardingRuleProvider(), GlobalAddressProvider(), SharedVpcHostProvider(), SharedVpcServiceProjectProvider(), PsaConnectionProvider(), ManagedLustreInstanceProvider(), StorageBucketProvider(), StorageBucketIamMemberProvider(), ServiceProvider(), JobProvider(), SqlInstanceProvider(), SqlDatabaseProvider(), SqlUserProvider(), ArtifactRegistryRepositoryProvider(), ServiceAccountProvider(), ServiceAccountKeyProvider(), KubernetesSecretProvider(), KubernetesManifestProvider(), HelmReleaseProvider())), Layer.provideMerge(fromAuthProvider()), Layer.provideMerge(GCPAuth),
|
|
76
78
|
// Auth/config failures (missing ADC, malformed profile) become
|
|
77
79
|
// unrecoverable defects rather than typed errors — mirrors
|
|
78
80
|
// `AWS/Providers.ts` and `Cloudflare/Providers.ts`. Resource lifecycle
|
package/lib/Providers.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Providers.js","sourceRoot":"","sources":["../src/Providers.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,QAAQ,MAAM,kBAAkB,CAAC;AAC7C,OAAO,KAAK,KAAK,MAAM,cAAc,CAAC;AACtC,OAAO,EACL,0BAA0B,EAC1B,kCAAkC,GACnC,MAAM,kCAAkC,CAAC;AAC1C,OAAO,EAAE,OAAO,EAAE,MAAM,wBAAwB,CAAC;AACjD,OAAO,EAAE,gBAAgB,EAAE,MAAM,uBAAuB,CAAC;AACzD,OAAO,EAAE,OAAO,EAAE,eAAe,EAAE,MAAM,mCAAmC,CAAC;AAC7E,OAAO,EAAE,OAAO,EAAE,eAAe,EAAE,MAAM,sBAAsB,CAAC;AAChE,OAAO,EAAE,QAAQ,EAAE,gBAAgB,EAAE,MAAM,uBAAuB,CAAC;AACnE,OAAO,EACL,cAAc,EACd,sBAAsB,GACvB,MAAM,6BAA6B,CAAC;AACrC,OAAO,EAAE,aAAa,EAAE,qBAAqB,EAAE,MAAM,4BAA4B,CAAC;AAClF,OAAO,EAAE,OAAO,EAAE,eAAe,EAAE,MAA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Ac;IACd,aAAa;IACb,aAAa;IACb,uBAAuB;IACvB,aAAa;IACb,qBAAqB;IACrB,aAAa;IACb,sBAAsB;IACtB,OAAO;IACP,GAAG;IACH,WAAW;IACX,WAAW;IACX,OAAO;IACP,0BAA0B;IAC1B,cAAc;IACd,iBAAiB;IACjB,gBAAgB;IAChB,kBAAkB;IAClB,WAAW;CACZ,CAAC,CACH,CAAC,IAAI,CACJ,KAAK,CAAC,OAAO,CACX,KAAK,CAAC,QAAQ,CACZ,eAAe,EAAE,EACjB,eAAe,EAAE,EACjB,gBAAgB,EAAE,EAClB,iBAAiB,EAAE,EACnB,eAAe,EAAE,EACjB,kBAAkB,EAAE,EACpB,gBAAgB,EAAE,EAClB,eAAe,EAAE,EACjB,sBAAsB,EAAE,EACxB,qBAAqB,EAAE,EACvB,qBAAqB,EAAE,EACvB,+BAA+B,EAAE,EACjC,qBAAqB,EAAE,EACvB,6BAA6B,EAAE,EAC/B,qBAAqB,EAAE,EACvB,8BAA8B,EAAE,EAChC,eAAe,EAAE,EACjB,WAAW,EAAE,EACb,mBAAmB,EAAE,EACrB,mBAAmB,EAAE,EACrB,eAAe,EAAE,EACjB,kCAAkC,EAAE,EACpC,sBAAsB,EAAE,EACxB,yBAAyB,EAAE,EAC3B,wBAAwB,EAAE,EAC1B,0BAA0B,EAAE,EAC5B,mBAAmB,EAAE,CACtB,CACF,EACD,KAAK,CAAC,YAAY,CAAC,gBAAgB,EAAE,CAAC,EACtC,KAAK,CAAC,YAAY,CAAC,OAAO,CAAC;AAC3B,+DAA+D;AAC/D,2DAA2D;AAC3D,uEAAuE;AACvE,0DAA0D;AAC1D,KAAK,CAAC,KAAK,CACZ,CAAC"}
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
import { Resource } from "alchemy";
|
|
2
|
+
import * as Provider from "alchemy/Provider";
|
|
3
|
+
import type * as GCP from "../Providers.ts";
|
|
4
|
+
/**
|
|
5
|
+
* A single `(role, member)` IAM binding entry on an **existing** GCS
|
|
6
|
+
* bucket that this stack does not manage. Contrast with
|
|
7
|
+
* {@link storageBucketIamMember}, the target-side binding helper: that
|
|
8
|
+
* one requires a stack-owned {@link StorageBucket} and is additive-only
|
|
9
|
+
* (bindings written into the bucket's binding bag are merged on
|
|
10
|
+
* reconcile but never pruned). This standalone resource takes the raw
|
|
11
|
+
* bucket name, adds the member on reconcile, and — the part the helper
|
|
12
|
+
* cannot do — **removes it again on delete**, so grants revoke when the
|
|
13
|
+
* declaring resource leaves the stack.
|
|
14
|
+
*
|
|
15
|
+
* Identity is the `(bucket, role, member)` triple; all three are
|
|
16
|
+
* immutable — changing any replaces (the old triple is revoked, the new
|
|
17
|
+
* one granted).
|
|
18
|
+
*
|
|
19
|
+
* The read-modify-write on the shared bucket policy is member-scoped:
|
|
20
|
+
* exactly one member is added/removed, every foreign role and member is
|
|
21
|
+
* preserved verbatim, and the whole cycle retries with backoff so
|
|
22
|
+
* concurrent writers on the same bucket compose safely (GCS rejects a
|
|
23
|
+
* stale-etag set with `Conflict`/`PreconditionFailed`).
|
|
24
|
+
*
|
|
25
|
+
* There is nothing GCP-side to carry alchemy ownership labels on an IAM
|
|
26
|
+
* binding, so `read` has no `Unowned` adoption gate — presence of the
|
|
27
|
+
* exact member under the exact role IS the resource.
|
|
28
|
+
*
|
|
29
|
+
* @section Granting on an unmanaged bucket
|
|
30
|
+
* @example Read access for a collaborator group's namespace identity
|
|
31
|
+
* ```typescript
|
|
32
|
+
* yield* GCP.StorageBucketIamMember("SrlPackagingRead", {
|
|
33
|
+
* bucket: "srl_200hr_packaging",
|
|
34
|
+
* role: "roles/storage.objectViewer",
|
|
35
|
+
* member:
|
|
36
|
+
* "principal://iam.googleapis.com/projects/864268824536/locations/global/workloadIdentityPools/micro-research-cluster-a.svc.id.goog/subject/ns/collab-srl/sa/default",
|
|
37
|
+
* });
|
|
38
|
+
* ```
|
|
39
|
+
*/
|
|
40
|
+
export type StorageBucketIamMemberProps = {
|
|
41
|
+
/**
|
|
42
|
+
* Name of the (pre-existing) GCS bucket to grant on. The bucket is
|
|
43
|
+
* NOT created, adopted, or deleted by this resource. Immutable —
|
|
44
|
+
* replace.
|
|
45
|
+
*/
|
|
46
|
+
bucket: string;
|
|
47
|
+
/** IAM role, e.g. `roles/storage.objectViewer`. Immutable — replace. */
|
|
48
|
+
role: string;
|
|
49
|
+
/**
|
|
50
|
+
* IAM member string (`serviceAccount:…`, `principal://…`,
|
|
51
|
+
* `group:…`, …). Immutable — replace.
|
|
52
|
+
*/
|
|
53
|
+
member: string;
|
|
54
|
+
};
|
|
55
|
+
export type StorageBucketIamMemberAttributes = {
|
|
56
|
+
/** Bucket name, threaded through from props. */
|
|
57
|
+
bucket: string;
|
|
58
|
+
/** IAM role, threaded through from props. */
|
|
59
|
+
role: string;
|
|
60
|
+
/** IAM member, threaded through from props. */
|
|
61
|
+
member: string;
|
|
62
|
+
};
|
|
63
|
+
export type StorageBucketIamMember = Resource<"GCP.StorageBucketIamMember", StorageBucketIamMemberProps, StorageBucketIamMemberAttributes, never, GCP.Providers>;
|
|
64
|
+
export declare const StorageBucketIamMember: import("alchemy").ResourceClass<StorageBucketIamMember>;
|
|
65
|
+
export declare const StorageBucketIamMemberProvider: () => import("effect/Layer").Layer<Provider.Provider<StorageBucketIamMember>, never, import("@distilled.cloud/gcp").Credentials | import("effect/unstable/http/HttpClient").HttpClient>;
|
|
66
|
+
//# sourceMappingURL=StorageBucketIamMember.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"StorageBucketIamMember.d.ts","sourceRoot":"","sources":["../../src/Storage/StorageBucketIamMember.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,QAAQ,EAAE,MAAM,SAAS,CAAC;AAEnC,OAAO,KAAK,QAAQ,MAAM,kBAAkB,CAAC;AAI7C,OAAO,KAAK,KAAK,GAAG,MAAM,iBAAiB,CAAC;AAE5C;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAmCG;AACH,MAAM,MAAM,2BAA2B,GAAG;IACxC;;;;OAIG;IACH,MAAM,EAAE,MAAM,CAAC;IACf,wEAAwE;IACxE,IAAI,EAAE,MAAM,CAAC;IACb;;;OAGG;IACH,MAAM,EAAE,MAAM,CAAC;CAChB,CAAC;AAEF,MAAM,MAAM,gCAAgC,GAAG;IAC7C,gDAAgD;IAChD,MAAM,EAAE,MAAM,CAAC;IACf,6CAA6C;IAC7C,IAAI,EAAE,MAAM,CAAC;IACb,+CAA+C;IAC/C,MAAM,EAAE,MAAM,CAAC;CAChB,CAAC;AAEF,MAAM,MAAM,sBAAsB,GAAG,QAAQ,CAC3C,4BAA4B,EAC5B,2BAA2B,EAC3B,gCAAgC,EAChC,KAAK,EACL,GAAG,CAAC,SAAS,CACd,CAAC;AAEF,eAAO,MAAM,sBAAsB,yDAElC,CAAC;AAEF,eAAO,MAAM,8BAA8B,yLAgKxC,CAAC"}
|
|
@@ -0,0 +1,130 @@
|
|
|
1
|
+
import { ConfigError } from "@distilled.cloud/gcp";
|
|
2
|
+
import * as storage from "@distilled.cloud/gcp/storage-v1";
|
|
3
|
+
import { Resource } from "alchemy";
|
|
4
|
+
import { isResolved } from "alchemy/Diff";
|
|
5
|
+
import * as Provider from "alchemy/Provider";
|
|
6
|
+
import * as Duration from "effect/Duration";
|
|
7
|
+
import * as Effect from "effect/Effect";
|
|
8
|
+
import * as Schedule from "effect/Schedule";
|
|
9
|
+
export const StorageBucketIamMember = Resource("GCP.StorageBucketIamMember");
|
|
10
|
+
export const StorageBucketIamMemberProvider = () => Provider.effect(StorageBucketIamMember, Effect.gen(function* () {
|
|
11
|
+
const getIamPolicyBuckets = yield* storage.getIamPolicyBuckets;
|
|
12
|
+
const setIamPolicyBuckets = yield* storage.setIamPolicyBuckets;
|
|
13
|
+
// Same backoff as StorageBucket's syncIam: the get→set cycle races
|
|
14
|
+
// other writers on the bucket policy (including sibling instances
|
|
15
|
+
// of this resource); a stale etag fails the set, the retry re-reads.
|
|
16
|
+
// ConfigError (bucket doesn't exist) is a terminal misconfiguration
|
|
17
|
+
// — fail fast instead of burning the ~8-minute backoff on it.
|
|
18
|
+
const etagRetry = (eff) => eff.pipe(Effect.retry({
|
|
19
|
+
while: (e) => e?._tag !== "ConfigError",
|
|
20
|
+
schedule: Schedule.exponential(Duration.seconds(2)).pipe(Schedule.both(Schedule.recurs(8))),
|
|
21
|
+
}));
|
|
22
|
+
// Membership check scoped to the unconditional binding for `role`
|
|
23
|
+
// — conditional bindings are someone else's and never touched.
|
|
24
|
+
const hasMember = (policy, role, member) => (policy.bindings ?? []).some((b) => b.role === role && !b.condition && (b.members ?? []).includes(member));
|
|
25
|
+
return {
|
|
26
|
+
// Identity IS the triple; all three are static strings.
|
|
27
|
+
stables: ["bucket", "role", "member"],
|
|
28
|
+
diff: Effect.fn(function* ({ news, olds = {}, output }) {
|
|
29
|
+
if (!isResolved(news))
|
|
30
|
+
return undefined;
|
|
31
|
+
// Prior identity from persisted attributes first, then olds —
|
|
32
|
+
// mirrors Bucket.ts (`output?.name || olds.name`). `||`, not
|
|
33
|
+
// `??`: an empty string in a partially-persisted attribute is
|
|
34
|
+
// NOT a prior identity — treating it as one would force a
|
|
35
|
+
// spurious replace whose delete targets the wrong (empty)
|
|
36
|
+
// identity. If only `output` survives (e.g. props were lost),
|
|
37
|
+
// a changed triple must still replace, or the old member is
|
|
38
|
+
// never revoked.
|
|
39
|
+
const priorBucket = output?.bucket || olds.bucket;
|
|
40
|
+
const priorRole = output?.role || olds.role;
|
|
41
|
+
const priorMember = output?.member || olds.member;
|
|
42
|
+
if ((priorBucket && priorBucket !== news.bucket) ||
|
|
43
|
+
(priorRole && priorRole !== news.role) ||
|
|
44
|
+
(priorMember && priorMember !== news.member)) {
|
|
45
|
+
return { action: "replace" };
|
|
46
|
+
}
|
|
47
|
+
return undefined;
|
|
48
|
+
}),
|
|
49
|
+
reconcile: Effect.fn(function* ({ news }) {
|
|
50
|
+
yield* etagRetry(Effect.gen(function* () {
|
|
51
|
+
const current = yield* getIamPolicyBuckets({
|
|
52
|
+
bucket: news.bucket,
|
|
53
|
+
optionsRequestedPolicyVersion: 3,
|
|
54
|
+
}).pipe(Effect.catchTag("NotFound", () => Effect.fail(new ConfigError({
|
|
55
|
+
message: `Bucket ${news.bucket} does not exist — StorageBucketIamMember grants on pre-existing buckets only.`,
|
|
56
|
+
}))));
|
|
57
|
+
if (hasMember(current, news.role, news.member))
|
|
58
|
+
return;
|
|
59
|
+
const bindings = (current.bindings ?? []).map((b) => ({
|
|
60
|
+
...b,
|
|
61
|
+
members: [...(b.members ?? [])],
|
|
62
|
+
}));
|
|
63
|
+
const existing = bindings.find((b) => b.role === news.role && !b.condition);
|
|
64
|
+
if (existing) {
|
|
65
|
+
existing.members = [...(existing.members ?? []), news.member];
|
|
66
|
+
}
|
|
67
|
+
else {
|
|
68
|
+
bindings.push({ role: news.role, members: [news.member] });
|
|
69
|
+
}
|
|
70
|
+
yield* setIamPolicyBuckets({
|
|
71
|
+
bucket: news.bucket,
|
|
72
|
+
body: { ...current, bindings, version: 3 },
|
|
73
|
+
});
|
|
74
|
+
}));
|
|
75
|
+
return { bucket: news.bucket, role: news.role, member: news.member };
|
|
76
|
+
}),
|
|
77
|
+
delete: Effect.fn(function* ({ output }) {
|
|
78
|
+
// Partially-persisted attributes (empty fields) name no real
|
|
79
|
+
// grant — nothing to revoke, and getIamPolicy("") would 4xx.
|
|
80
|
+
if (!output.bucket || !output.role || !output.member)
|
|
81
|
+
return;
|
|
82
|
+
yield* etagRetry(Effect.gen(function* () {
|
|
83
|
+
const current = yield* getIamPolicyBuckets({
|
|
84
|
+
bucket: output.bucket,
|
|
85
|
+
optionsRequestedPolicyVersion: 3,
|
|
86
|
+
}).pipe(
|
|
87
|
+
// Bucket gone (or unreadable because gone) — the grant
|
|
88
|
+
// went with it; idempotent success.
|
|
89
|
+
Effect.catchTag("NotFound", () => Effect.succeed(undefined)));
|
|
90
|
+
if (!current || !hasMember(current, output.role, output.member)) {
|
|
91
|
+
return;
|
|
92
|
+
}
|
|
93
|
+
// Remove exactly our member from the unconditional binding;
|
|
94
|
+
// drop the binding entirely if that empties it (GCS rejects
|
|
95
|
+
// bindings with zero members).
|
|
96
|
+
const bindings = (current.bindings ?? [])
|
|
97
|
+
.map((b) => b.role === output.role && !b.condition
|
|
98
|
+
? {
|
|
99
|
+
...b,
|
|
100
|
+
members: (b.members ?? []).filter((m) => m !== output.member),
|
|
101
|
+
}
|
|
102
|
+
: { ...b, members: [...(b.members ?? [])] })
|
|
103
|
+
.filter((b) => (b.members?.length ?? 0) > 0);
|
|
104
|
+
yield* setIamPolicyBuckets({
|
|
105
|
+
bucket: output.bucket,
|
|
106
|
+
body: { ...current, bindings, version: 3 },
|
|
107
|
+
}).pipe(Effect.catchTag("NotFound", () => Effect.void));
|
|
108
|
+
}));
|
|
109
|
+
}),
|
|
110
|
+
read: Effect.fn(function* ({ output, olds }) {
|
|
111
|
+
const bucket = output?.bucket ?? olds?.bucket;
|
|
112
|
+
const role = output?.role ?? olds?.role;
|
|
113
|
+
const member = output?.member ?? olds?.member;
|
|
114
|
+
if (!bucket || !role || !member)
|
|
115
|
+
return undefined;
|
|
116
|
+
const current = yield* getIamPolicyBuckets({
|
|
117
|
+
bucket,
|
|
118
|
+
optionsRequestedPolicyVersion: 3,
|
|
119
|
+
}).pipe(Effect.catchTag("NotFound", () => Effect.succeed(undefined)), Effect.catchTag("Forbidden", () => Effect.succeed(undefined)));
|
|
120
|
+
if (!current)
|
|
121
|
+
return undefined;
|
|
122
|
+
// Absent member → undefined: the engine treats that as drift
|
|
123
|
+
// and the next plan re-grants.
|
|
124
|
+
if (!hasMember(current, role, member))
|
|
125
|
+
return undefined;
|
|
126
|
+
return { bucket, role, member };
|
|
127
|
+
}),
|
|
128
|
+
};
|
|
129
|
+
}));
|
|
130
|
+
//# sourceMappingURL=StorageBucketIamMember.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"StorageBucketIamMember.js","sourceRoot":"","sources":["../../src/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C;YACxC,MAAM,MAAM,GAAG,MAAM,EAAE,MAAM,IAAI,IAAI,EAAE,MAAM,CAAC;YAC9C,IAAI,CAAC,MAAM,IAAI,CAAC,IAAI,IAAI,CAAC,MAAM;gBAAE,OAAO,SAAS,CAAC;YAClD,MAAM,OAAO,GAAG,KAAK,CAAC,CAAC,mBAAmB,CAAC;gBACzC,MAAM;gBACN,6BAA6B,EAAE,CAAC;aACjC,CAAC,CAAC,IAAI,CACL,MAAM,CAAC,QAAQ,CAAC,UAAU,EAAE,GAAG,EAAE,CAC/B,MAAM,CAAC,OAAO,CAAC,SAAuC,CAAC,CACxD,EACD,MAAM,CAAC,QAAQ,CAAC,WAAW,EAAE,GAAG,EAAE,CAChC,MAAM,CAAC,OAAO,CAAC,SAAuC,CAAC,CACxD,CACF,CAAC;YACF,IAAI,CAAC,OAAO;gBAAE,OAAO,SAAS,CAAC;YAC/B,6DAA6D;YAC7D,+BAA+B;YAC/B,IAAI,CAAC,SAAS,CAAC,OAAO,EAAE,IAAI,EAAE,MAAM,CAAC;gBAAE,OAAO,SAAS,CAAC;YACxD,OAAO,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,EAAE,CAAC;QAClC,CAAC,CAAC;KACH,CAAC;AACJ,CAAC,CAAC,CACH,CAAC"}
|
package/lib/Storage/index.d.ts
CHANGED
|
@@ -1,4 +1,6 @@
|
|
|
1
1
|
export { StorageBucket, StorageBucketProvider, } from "./Bucket.ts";
|
|
2
2
|
export type { StorageBucketProps, StorageBucketIamBinding, StorageBucketBindingContract, } from "./Bucket.ts";
|
|
3
3
|
export * from "./BucketIamMember.ts";
|
|
4
|
+
export { StorageBucketIamMember, StorageBucketIamMemberProvider, } from "./StorageBucketIamMember.ts";
|
|
5
|
+
export type { StorageBucketIamMemberProps, StorageBucketIamMemberAttributes, } from "./StorageBucketIamMember.ts";
|
|
4
6
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/Storage/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,aAAa,EACb,qBAAqB,GACtB,MAAM,aAAa,CAAC;AACrB,YAAY,EACV,kBAAkB,EAClB,uBAAuB,EACvB,4BAA4B,GAC7B,MAAM,aAAa,CAAC;AACrB,cAAc,sBAAsB,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/Storage/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,aAAa,EACb,qBAAqB,GACtB,MAAM,aAAa,CAAC;AACrB,YAAY,EACV,kBAAkB,EAClB,uBAAuB,EACvB,4BAA4B,GAC7B,MAAM,aAAa,CAAC;AACrB,cAAc,sBAAsB,CAAC;AACrC,OAAO,EACL,sBAAsB,EACtB,8BAA8B,GAC/B,MAAM,6BAA6B,CAAC;AACrC,YAAY,EACV,2BAA2B,EAC3B,gCAAgC,GACjC,MAAM,6BAA6B,CAAC"}
|
package/lib/Storage/index.js
CHANGED
package/lib/Storage/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/Storage/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,aAAa,EACb,qBAAqB,GACtB,MAAM,aAAa,CAAC;AAMrB,cAAc,sBAAsB,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/Storage/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,aAAa,EACb,qBAAqB,GACtB,MAAM,aAAa,CAAC;AAMrB,cAAc,sBAAsB,CAAC;AACrC,OAAO,EACL,sBAAsB,EACtB,8BAA8B,GAC/B,MAAM,6BAA6B,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@microagi/alchemy-gcp",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.10.0",
|
|
4
4
|
"description": "GCP provider for Alchemy v2 (Effect-based IaC). Resources for Project, ServiceAccount, Cluster, NodePool, Compute, ManagedLustre, ServiceUsage, ServiceNetworking, Cloud Run (Service + Job + IAM), Cloud SQL (Instance + Database + User with IAM database authn), Artifact Registry (Docker repositories, standard + remote pull-through caches), Kubernetes (typed Secret + generic SSA Manifest + Helm release), with ADC-backed credentials and target-side IAM bindings.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"alchemy",
|
package/src/Providers.ts
CHANGED
|
@@ -57,6 +57,10 @@ import {
|
|
|
57
57
|
StorageBucket,
|
|
58
58
|
StorageBucketProvider,
|
|
59
59
|
} from "./Storage/Bucket.ts";
|
|
60
|
+
import {
|
|
61
|
+
StorageBucketIamMember,
|
|
62
|
+
StorageBucketIamMemberProvider,
|
|
63
|
+
} from "./Storage/StorageBucketIamMember.ts";
|
|
60
64
|
import { ApiEnable, ApiEnableProvider } from "./ServiceUsage/ApiEnable.ts";
|
|
61
65
|
import { SqlDatabase, SqlDatabaseProvider } from "./Sqladmin/Database.ts";
|
|
62
66
|
import { SqlInstance, SqlInstanceProvider } from "./Sqladmin/Instance.ts";
|
|
@@ -100,6 +104,7 @@ export const providers = () =>
|
|
|
100
104
|
PsaConnection,
|
|
101
105
|
ManagedLustreInstance,
|
|
102
106
|
StorageBucket,
|
|
107
|
+
StorageBucketIamMember,
|
|
103
108
|
Service,
|
|
104
109
|
Job,
|
|
105
110
|
SqlInstance,
|
|
@@ -130,6 +135,7 @@ export const providers = () =>
|
|
|
130
135
|
PsaConnectionProvider(),
|
|
131
136
|
ManagedLustreInstanceProvider(),
|
|
132
137
|
StorageBucketProvider(),
|
|
138
|
+
StorageBucketIamMemberProvider(),
|
|
133
139
|
ServiceProvider(),
|
|
134
140
|
JobProvider(),
|
|
135
141
|
SqlInstanceProvider(),
|
|
@@ -0,0 +1,244 @@
|
|
|
1
|
+
import { ConfigError } from "@distilled.cloud/gcp";
|
|
2
|
+
import * as storage from "@distilled.cloud/gcp/storage-v1";
|
|
3
|
+
import { Resource } from "alchemy";
|
|
4
|
+
import { isResolved } from "alchemy/Diff";
|
|
5
|
+
import * as Provider from "alchemy/Provider";
|
|
6
|
+
import * as Duration from "effect/Duration";
|
|
7
|
+
import * as Effect from "effect/Effect";
|
|
8
|
+
import * as Schedule from "effect/Schedule";
|
|
9
|
+
import type * as GCP from "../Providers.ts";
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* A single `(role, member)` IAM binding entry on an **existing** GCS
|
|
13
|
+
* bucket that this stack does not manage. Contrast with
|
|
14
|
+
* {@link storageBucketIamMember}, the target-side binding helper: that
|
|
15
|
+
* one requires a stack-owned {@link StorageBucket} and is additive-only
|
|
16
|
+
* (bindings written into the bucket's binding bag are merged on
|
|
17
|
+
* reconcile but never pruned). This standalone resource takes the raw
|
|
18
|
+
* bucket name, adds the member on reconcile, and — the part the helper
|
|
19
|
+
* cannot do — **removes it again on delete**, so grants revoke when the
|
|
20
|
+
* declaring resource leaves the stack.
|
|
21
|
+
*
|
|
22
|
+
* Identity is the `(bucket, role, member)` triple; all three are
|
|
23
|
+
* immutable — changing any replaces (the old triple is revoked, the new
|
|
24
|
+
* one granted).
|
|
25
|
+
*
|
|
26
|
+
* The read-modify-write on the shared bucket policy is member-scoped:
|
|
27
|
+
* exactly one member is added/removed, every foreign role and member is
|
|
28
|
+
* preserved verbatim, and the whole cycle retries with backoff so
|
|
29
|
+
* concurrent writers on the same bucket compose safely (GCS rejects a
|
|
30
|
+
* stale-etag set with `Conflict`/`PreconditionFailed`).
|
|
31
|
+
*
|
|
32
|
+
* There is nothing GCP-side to carry alchemy ownership labels on an IAM
|
|
33
|
+
* binding, so `read` has no `Unowned` adoption gate — presence of the
|
|
34
|
+
* exact member under the exact role IS the resource.
|
|
35
|
+
*
|
|
36
|
+
* @section Granting on an unmanaged bucket
|
|
37
|
+
* @example Read access for a collaborator group's namespace identity
|
|
38
|
+
* ```typescript
|
|
39
|
+
* yield* GCP.StorageBucketIamMember("SrlPackagingRead", {
|
|
40
|
+
* bucket: "srl_200hr_packaging",
|
|
41
|
+
* role: "roles/storage.objectViewer",
|
|
42
|
+
* member:
|
|
43
|
+
* "principal://iam.googleapis.com/projects/864268824536/locations/global/workloadIdentityPools/micro-research-cluster-a.svc.id.goog/subject/ns/collab-srl/sa/default",
|
|
44
|
+
* });
|
|
45
|
+
* ```
|
|
46
|
+
*/
|
|
47
|
+
export type StorageBucketIamMemberProps = {
|
|
48
|
+
/**
|
|
49
|
+
* Name of the (pre-existing) GCS bucket to grant on. The bucket is
|
|
50
|
+
* NOT created, adopted, or deleted by this resource. Immutable —
|
|
51
|
+
* replace.
|
|
52
|
+
*/
|
|
53
|
+
bucket: string;
|
|
54
|
+
/** IAM role, e.g. `roles/storage.objectViewer`. Immutable — replace. */
|
|
55
|
+
role: string;
|
|
56
|
+
/**
|
|
57
|
+
* IAM member string (`serviceAccount:…`, `principal://…`,
|
|
58
|
+
* `group:…`, …). Immutable — replace.
|
|
59
|
+
*/
|
|
60
|
+
member: string;
|
|
61
|
+
};
|
|
62
|
+
|
|
63
|
+
export type StorageBucketIamMemberAttributes = {
|
|
64
|
+
/** Bucket name, threaded through from props. */
|
|
65
|
+
bucket: string;
|
|
66
|
+
/** IAM role, threaded through from props. */
|
|
67
|
+
role: string;
|
|
68
|
+
/** IAM member, threaded through from props. */
|
|
69
|
+
member: string;
|
|
70
|
+
};
|
|
71
|
+
|
|
72
|
+
export type StorageBucketIamMember = Resource<
|
|
73
|
+
"GCP.StorageBucketIamMember",
|
|
74
|
+
StorageBucketIamMemberProps,
|
|
75
|
+
StorageBucketIamMemberAttributes,
|
|
76
|
+
never,
|
|
77
|
+
GCP.Providers
|
|
78
|
+
>;
|
|
79
|
+
|
|
80
|
+
export const StorageBucketIamMember = Resource<StorageBucketIamMember>(
|
|
81
|
+
"GCP.StorageBucketIamMember",
|
|
82
|
+
);
|
|
83
|
+
|
|
84
|
+
export const StorageBucketIamMemberProvider = () =>
|
|
85
|
+
Provider.effect(
|
|
86
|
+
StorageBucketIamMember,
|
|
87
|
+
Effect.gen(function* () {
|
|
88
|
+
const getIamPolicyBuckets = yield* storage.getIamPolicyBuckets;
|
|
89
|
+
const setIamPolicyBuckets = yield* storage.setIamPolicyBuckets;
|
|
90
|
+
|
|
91
|
+
// Same backoff as StorageBucket's syncIam: the get→set cycle races
|
|
92
|
+
// other writers on the bucket policy (including sibling instances
|
|
93
|
+
// of this resource); a stale etag fails the set, the retry re-reads.
|
|
94
|
+
// ConfigError (bucket doesn't exist) is a terminal misconfiguration
|
|
95
|
+
// — fail fast instead of burning the ~8-minute backoff on it.
|
|
96
|
+
const etagRetry = <A, E, R>(eff: Effect.Effect<A, E, R>) =>
|
|
97
|
+
eff.pipe(
|
|
98
|
+
Effect.retry({
|
|
99
|
+
while: (e) => (e as { _tag?: string })?._tag !== "ConfigError",
|
|
100
|
+
schedule: Schedule.exponential(Duration.seconds(2)).pipe(
|
|
101
|
+
Schedule.both(Schedule.recurs(8)),
|
|
102
|
+
),
|
|
103
|
+
}),
|
|
104
|
+
);
|
|
105
|
+
|
|
106
|
+
// Membership check scoped to the unconditional binding for `role`
|
|
107
|
+
// — conditional bindings are someone else's and never touched.
|
|
108
|
+
const hasMember = (
|
|
109
|
+
policy: storage.Policy,
|
|
110
|
+
role: string,
|
|
111
|
+
member: string,
|
|
112
|
+
) =>
|
|
113
|
+
(policy.bindings ?? []).some(
|
|
114
|
+
(b) => b.role === role && !b.condition && (b.members ?? []).includes(member),
|
|
115
|
+
);
|
|
116
|
+
|
|
117
|
+
return {
|
|
118
|
+
// Identity IS the triple; all three are static strings.
|
|
119
|
+
stables: ["bucket", "role", "member"],
|
|
120
|
+
diff: Effect.fn(function* ({ news, olds = {}, output }) {
|
|
121
|
+
if (!isResolved(news)) return undefined;
|
|
122
|
+
// Prior identity from persisted attributes first, then olds —
|
|
123
|
+
// mirrors Bucket.ts (`output?.name || olds.name`). `||`, not
|
|
124
|
+
// `??`: an empty string in a partially-persisted attribute is
|
|
125
|
+
// NOT a prior identity — treating it as one would force a
|
|
126
|
+
// spurious replace whose delete targets the wrong (empty)
|
|
127
|
+
// identity. If only `output` survives (e.g. props were lost),
|
|
128
|
+
// a changed triple must still replace, or the old member is
|
|
129
|
+
// never revoked.
|
|
130
|
+
const priorBucket = output?.bucket || olds.bucket;
|
|
131
|
+
const priorRole = output?.role || olds.role;
|
|
132
|
+
const priorMember = output?.member || olds.member;
|
|
133
|
+
if (
|
|
134
|
+
(priorBucket && priorBucket !== news.bucket) ||
|
|
135
|
+
(priorRole && priorRole !== news.role) ||
|
|
136
|
+
(priorMember && priorMember !== news.member)
|
|
137
|
+
) {
|
|
138
|
+
return { action: "replace" } as const;
|
|
139
|
+
}
|
|
140
|
+
return undefined;
|
|
141
|
+
}),
|
|
142
|
+
reconcile: Effect.fn(function* ({ news }) {
|
|
143
|
+
yield* etagRetry(
|
|
144
|
+
Effect.gen(function* () {
|
|
145
|
+
const current = yield* getIamPolicyBuckets({
|
|
146
|
+
bucket: news.bucket,
|
|
147
|
+
optionsRequestedPolicyVersion: 3,
|
|
148
|
+
}).pipe(
|
|
149
|
+
Effect.catchTag("NotFound", () =>
|
|
150
|
+
Effect.fail(
|
|
151
|
+
new ConfigError({
|
|
152
|
+
message: `Bucket ${news.bucket} does not exist — StorageBucketIamMember grants on pre-existing buckets only.`,
|
|
153
|
+
}),
|
|
154
|
+
),
|
|
155
|
+
),
|
|
156
|
+
);
|
|
157
|
+
if (hasMember(current, news.role, news.member)) return;
|
|
158
|
+
|
|
159
|
+
const bindings = (current.bindings ?? []).map((b) => ({
|
|
160
|
+
...b,
|
|
161
|
+
members: [...(b.members ?? [])],
|
|
162
|
+
}));
|
|
163
|
+
const existing = bindings.find(
|
|
164
|
+
(b) => b.role === news.role && !b.condition,
|
|
165
|
+
);
|
|
166
|
+
if (existing) {
|
|
167
|
+
existing.members = [...(existing.members ?? []), news.member];
|
|
168
|
+
} else {
|
|
169
|
+
bindings.push({ role: news.role, members: [news.member] });
|
|
170
|
+
}
|
|
171
|
+
yield* setIamPolicyBuckets({
|
|
172
|
+
bucket: news.bucket,
|
|
173
|
+
body: { ...current, bindings, version: 3 },
|
|
174
|
+
});
|
|
175
|
+
}),
|
|
176
|
+
);
|
|
177
|
+
return { bucket: news.bucket, role: news.role, member: news.member };
|
|
178
|
+
}),
|
|
179
|
+
delete: Effect.fn(function* ({ output }) {
|
|
180
|
+
// Partially-persisted attributes (empty fields) name no real
|
|
181
|
+
// grant — nothing to revoke, and getIamPolicy("") would 4xx.
|
|
182
|
+
if (!output.bucket || !output.role || !output.member) return;
|
|
183
|
+
yield* etagRetry(
|
|
184
|
+
Effect.gen(function* () {
|
|
185
|
+
const current = yield* getIamPolicyBuckets({
|
|
186
|
+
bucket: output.bucket,
|
|
187
|
+
optionsRequestedPolicyVersion: 3,
|
|
188
|
+
}).pipe(
|
|
189
|
+
// Bucket gone (or unreadable because gone) — the grant
|
|
190
|
+
// went with it; idempotent success.
|
|
191
|
+
Effect.catchTag("NotFound", () =>
|
|
192
|
+
Effect.succeed(undefined as storage.Policy | undefined),
|
|
193
|
+
),
|
|
194
|
+
);
|
|
195
|
+
if (!current || !hasMember(current, output.role, output.member)) {
|
|
196
|
+
return;
|
|
197
|
+
}
|
|
198
|
+
// Remove exactly our member from the unconditional binding;
|
|
199
|
+
// drop the binding entirely if that empties it (GCS rejects
|
|
200
|
+
// bindings with zero members).
|
|
201
|
+
const bindings = (current.bindings ?? [])
|
|
202
|
+
.map((b) =>
|
|
203
|
+
b.role === output.role && !b.condition
|
|
204
|
+
? {
|
|
205
|
+
...b,
|
|
206
|
+
members: (b.members ?? []).filter(
|
|
207
|
+
(m) => m !== output.member,
|
|
208
|
+
),
|
|
209
|
+
}
|
|
210
|
+
: { ...b, members: [...(b.members ?? [])] },
|
|
211
|
+
)
|
|
212
|
+
.filter((b) => (b.members?.length ?? 0) > 0);
|
|
213
|
+
yield* setIamPolicyBuckets({
|
|
214
|
+
bucket: output.bucket,
|
|
215
|
+
body: { ...current, bindings, version: 3 },
|
|
216
|
+
}).pipe(Effect.catchTag("NotFound", () => Effect.void));
|
|
217
|
+
}),
|
|
218
|
+
);
|
|
219
|
+
}),
|
|
220
|
+
read: Effect.fn(function* ({ output, olds }) {
|
|
221
|
+
const bucket = output?.bucket ?? olds?.bucket;
|
|
222
|
+
const role = output?.role ?? olds?.role;
|
|
223
|
+
const member = output?.member ?? olds?.member;
|
|
224
|
+
if (!bucket || !role || !member) return undefined;
|
|
225
|
+
const current = yield* getIamPolicyBuckets({
|
|
226
|
+
bucket,
|
|
227
|
+
optionsRequestedPolicyVersion: 3,
|
|
228
|
+
}).pipe(
|
|
229
|
+
Effect.catchTag("NotFound", () =>
|
|
230
|
+
Effect.succeed(undefined as storage.Policy | undefined),
|
|
231
|
+
),
|
|
232
|
+
Effect.catchTag("Forbidden", () =>
|
|
233
|
+
Effect.succeed(undefined as storage.Policy | undefined),
|
|
234
|
+
),
|
|
235
|
+
);
|
|
236
|
+
if (!current) return undefined;
|
|
237
|
+
// Absent member → undefined: the engine treats that as drift
|
|
238
|
+
// and the next plan re-grants.
|
|
239
|
+
if (!hasMember(current, role, member)) return undefined;
|
|
240
|
+
return { bucket, role, member };
|
|
241
|
+
}),
|
|
242
|
+
};
|
|
243
|
+
}),
|
|
244
|
+
);
|
package/src/Storage/index.ts
CHANGED
|
@@ -8,3 +8,11 @@ export type {
|
|
|
8
8
|
StorageBucketBindingContract,
|
|
9
9
|
} from "./Bucket.ts";
|
|
10
10
|
export * from "./BucketIamMember.ts";
|
|
11
|
+
export {
|
|
12
|
+
StorageBucketIamMember,
|
|
13
|
+
StorageBucketIamMemberProvider,
|
|
14
|
+
} from "./StorageBucketIamMember.ts";
|
|
15
|
+
export type {
|
|
16
|
+
StorageBucketIamMemberProps,
|
|
17
|
+
StorageBucketIamMemberAttributes,
|
|
18
|
+
} from "./StorageBucketIamMember.ts";
|