MCPcopy Create free account
hub / github.com/GoogleCloudPlatform/nodejs-docs-samples / grantAccess

Function grantAccess

secret-manager/iamRevokeAccess.js:37–63  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

35 const client = new SecretManagerServiceClient();
36
37 async function grantAccess() {
38 // Get the current IAM policy.
39 const [policy] = await client.getIamPolicy({
40 resource: name,
41 });
42
43 // Build a new list of policy bindings with the user excluded.
44 for (const i in policy.bindings) {
45 const binding = policy.bindings[i];
46 if (binding.role !== 'roles/secretmanager.secretAccessor') {
47 continue;
48 }
49
50 const idx = binding.members.indexOf(member);
51 if (idx !== -1) {
52 binding.members.splice(idx, 1);
53 }
54 }
55
56 // Save the updated IAM policy.
57 await client.setIamPolicy({
58 resource: name,
59 policy: policy,
60 });
61
62 console.log(`Updated IAM policy for ${name}`);
63 }
64
65 grantAccess();
66 // [END secretmanager_iam_revoke_access]

Callers 1

mainFunction · 0.70

Calls

no outgoing calls

Tested by

no test coverage detected