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

Function main

parametermanager/createParamWithKmsKey.js:24–58  ·  view source on GitHub ↗

* Creates a global parameter with kms_key using the Parameter Manager SDK. * * @param {string} projectId - The Google Cloud project ID where the parameter is to be created. * @param {string} parameterId - The ID of the parameter to create. This ID must be unique within the project. * @param {str

(projectId, parameterId, kmsKey)

Source from the content-addressed store, hash-verified

22 * @param {string} kmsKey - The ID of the KMS key to be used for encryption.
23 */
24async function main(projectId, parameterId, kmsKey) {
25 // [START parametermanager_create_param_with_kms_key]
26 /**
27 * TODO(developer): Uncomment these variables before running the sample.
28 */
29 // const projectId = 'YOUR_PROJECT_ID';
30 // const parameterId = 'YOUR_PARAMETER_ID';
31 // const kmsKey = 'YOUR_KMS_KEY'
32
33 // Imports the Parameter Manager library
34 const {ParameterManagerClient} = require('@google-cloud/parametermanager');
35
36 // Instantiates a client
37 const client = new ParameterManagerClient();
38
39 async function createParamWithKmsKey() {
40 const parent = client.locationPath(projectId, 'global');
41 const request = {
42 parent: parent,
43 parameterId: parameterId,
44 parameter: {
45 kmsKey: kmsKey,
46 },
47 };
48
49 const [parameter] = await client.createParameter(request);
50 console.log(
51 `Created parameter ${parameter.name} with kms_key ${parameter.kmsKey}`
52 );
53 return parameter;
54 }
55
56 return await createParamWithKmsKey();
57 // [END parametermanager_create_param_with_kms_key]
58}
59module.exports.main = main;
60
61/* c8 ignore next 10 */

Callers 1

Calls 1

createParamWithKmsKeyFunction · 0.85

Tested by

no test coverage detected