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

Function main

kms/iamGetPolicy.js:17–67  ·  view source on GitHub ↗
(
  projectId = 'my-project',
  locationId = 'us-east1',
  keyRingId = 'my-key-ring',
  keyId = 'my-key'
)

Source from the content-addressed store, hash-verified

15'use strict';
16
17async function main(
18 projectId = 'my-project',
19 locationId = 'us-east1',
20 keyRingId = 'my-key-ring',
21 keyId = 'my-key'
22) {
23 // [START kms_iam_get_policy]
24 //
25 // TODO(developer): Uncomment these variables before running the sample.
26 //
27 // const projectId = 'my-project';
28 // const locationId = 'us-east1';
29 // const keyRingId = 'my-key-ring';
30 // const keyId = 'my-key';
31 // const member = 'user:foo@example.com';
32
33 // Imports the Cloud KMS library
34 const {KeyManagementServiceClient} = require('@google-cloud/kms');
35
36 // Instantiates a client
37 const client = new KeyManagementServiceClient();
38
39 // Build the resource name
40 const resourceName = client.cryptoKeyPath(
41 projectId,
42 locationId,
43 keyRingId,
44 keyId
45 );
46
47 // The resource name could also be a key ring.
48 // const resourceName = client.keyRingPath(projectId, locationId, keyRingId);
49
50 async function iamGetPolicy() {
51 const [policy] = await client.getIamPolicy({
52 resource: resourceName,
53 });
54
55 for (const binding of policy.bindings) {
56 console.log(`Role: ${binding.role}`);
57 for (const member of binding.members) {
58 console.log(` - ${member}`);
59 }
60 }
61
62 return policy;
63 }
64
65 return iamGetPolicy();
66 // [END kms_iam_get_policy]
67}
68module.exports.main = main;
69
70/* c8 ignore next 10 */

Callers 1

iamGetPolicy.jsFile · 0.70

Calls 1

iamGetPolicyFunction · 0.85

Tested by

no test coverage detected