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

Function main

parametermanager/createParamVersion.js:25–67  ·  view source on GitHub ↗

* Creates a parameter version globally for unstructured data. * * @param {string} projectId - The Google Cloud project ID where the parameter is to be created * @param {string} parameterId - The ID of the parameter for which the version is to be created. * @param {string} parameterVersionId - Th

(projectId, parameterId, parameterVersionId, payload)

Source from the content-addressed store, hash-verified

23 * @param {string} payload - The unformatted string payload to be stored in the new parameter version.
24 */
25async function main(projectId, parameterId, parameterVersionId, payload) {
26 // [START parametermanager_create_param_version]
27 /**
28 * TODO(developer): Uncomment these variables before running the sample.
29 */
30 // const projectId = 'YOUR_PROJECT_ID';
31 // const parameterId = 'YOUR_PARAMETER_ID';
32 // const parameterVersionId = 'YOUR_PARAMETER_VERSION_ID';
33 // const payload = 'This is unstructured data';
34
35 // Imports the Parameter Manager library
36 const {ParameterManagerClient} = require('@google-cloud/parametermanager');
37
38 // Instantiates a client
39 const client = new ParameterManagerClient();
40
41 async function createParamVersion() {
42 // Construct the parent resource name
43 const parent = client.parameterPath(projectId, 'global', parameterId);
44
45 // Construct the parameter version
46 const parameterVersion = {
47 payload: {
48 data: Buffer.from(payload, 'utf8'),
49 },
50 };
51
52 // Construct the request
53 const request = {
54 parent: parent,
55 parameterVersionId: parameterVersionId,
56 parameterVersion: parameterVersion,
57 };
58
59 // Create the parameter version
60 const [paramVersion] = await client.createParameterVersion(request);
61 console.log(`Created parameter version: ${paramVersion.name}`);
62 return paramVersion;
63 }
64
65 return await createParamVersion();
66 // [END parametermanager_create_param_version]
67}
68module.exports.main = main;
69
70/* c8 ignore next 10 */

Callers 1

Calls 1

createParamVersionFunction · 0.85

Tested by

no test coverage detected