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

Function main

secret-manager/iamRevokeAccess.js:17–67  ·  view source on GitHub ↗
(
  name = 'projects/my-project/secrets/my-secret',
  member = 'user:you@example.com'
)

Source from the content-addressed store, hash-verified

15'use strict';
16
17async function main(
18 name = 'projects/my-project/secrets/my-secret',
19 member = 'user:you@example.com'
20) {
21 // [START secretmanager_iam_revoke_access]
22 /**
23 * TODO(developer): Uncomment these variables before running the sample.
24 */
25 // const name = 'projects/my-project/secrets/my-secret';
26 // const member = 'user:you@example.com';
27 //
28 // NOTE: Each member must be prefixed with its type. See the IAM documentation
29 // for more information: https://cloud.google.com/iam/docs/overview.
30
31 // Imports the Secret Manager library
32 const {SecretManagerServiceClient} = require('@google-cloud/secret-manager');
33
34 // Instantiates a client
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]
67}
68
69const args = process.argv.slice(2);
70main(...args).catch(console.error);

Callers 1

iamRevokeAccess.jsFile · 0.70

Calls 1

grantAccessFunction · 0.70

Tested by

no test coverage detected