| 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] |