| 49 | // const resourceName = client.keyRingPath(projectId, locationId, keyRingId); |
| 50 | |
| 51 | async function iamRemoveMember() { |
| 52 | // Get the current IAM policy. |
| 53 | const [policy] = await client.getIamPolicy({ |
| 54 | resource: resourceName, |
| 55 | }); |
| 56 | |
| 57 | // Build a new list of policy bindings with the user excluded. |
| 58 | for (const i in policy.bindings) { |
| 59 | const binding = policy.bindings[i]; |
| 60 | if (binding.role !== 'roles/cloudkms.cryptoKeyEncrypterDecrypter') { |
| 61 | continue; |
| 62 | } |
| 63 | |
| 64 | const idx = binding.members.indexOf(member); |
| 65 | if (idx !== -1) { |
| 66 | binding.members.splice(idx, 1); |
| 67 | } |
| 68 | } |
| 69 | |
| 70 | // Save the updated IAM policy. |
| 71 | const [updatedPolicy] = await client.setIamPolicy({ |
| 72 | resource: resourceName, |
| 73 | policy: policy, |
| 74 | }); |
| 75 | |
| 76 | console.log('Updated policy'); |
| 77 | return updatedPolicy; |
| 78 | } |
| 79 | |
| 80 | return iamRemoveMember(); |
| 81 | // [END kms_iam_remove_member] |