Skip to content

Commit 375215f

Browse files
feat(parametermanager): Added samples for delete, disable, enable parameter version in global & regional (#4070)
* feat(parametermanager): Added samples for delete, disable, enable and quickstart parameter & parameter version * fix(parametermanager): update code samples and testcases * fix(parametermanager): update testcases and function arguments * Merge branch 'main' into parametermanager-all-samples-update-delete --------- Co-authored-by: Katie McLaughlin <[email protected]>
1 parent f22e9ce commit 375215f

11 files changed

+1077
-8
lines changed

parametermanager/deleteParam.js

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
// Copyright 2025 Google LLC
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// https://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
15+
'use strict';
16+
17+
/**
18+
* Deletes a parameter from the global location of the specified project using the Google Cloud Parameter Manager SDK.
19+
*
20+
* @param {string} projectId - The Google Cloud project ID where the parameter is located.
21+
* @param {string} parameterId - The ID of the parameter to delete.
22+
*/
23+
async function main(projectId, parameterId) {
24+
// [START parametermanager_delete_param]
25+
/**
26+
* TODO(developer): Uncomment these variables before running the sample.
27+
*/
28+
// const projectId = 'my-project';
29+
// const parameterId = 'my-parameter';
30+
31+
// Imports the Parameter Manager library
32+
const {ParameterManagerClient} = require('@google-cloud/parametermanager');
33+
34+
// Instantiates a client
35+
const client = new ParameterManagerClient();
36+
37+
async function deleteParam() {
38+
// Construct the fully qualified parameter name
39+
const name = client.parameterPath(projectId, 'global', parameterId);
40+
41+
// Delete the parameter
42+
await client.deleteParameter({
43+
name: name,
44+
});
45+
46+
console.log(`Deleted parameter: ${name}`);
47+
return name;
48+
}
49+
50+
return await deleteParam();
51+
// [END parametermanager_delete_param]
52+
}
53+
module.exports.main = main;
54+
55+
/* c8 ignore next 10 */
56+
if (require.main === module) {
57+
main(...process.argv.slice(2)).catch(err => {
58+
console.error(err.message);
59+
process.exitCode = 1;
60+
});
61+
process.on('unhandledRejection', err => {
62+
console.error(err.message);
63+
process.exitCode = 1;
64+
});
65+
}
Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
// Copyright 2025 Google LLC
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// https://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
15+
'use strict';
16+
17+
/**
18+
* Deletes a specific version of an existing parameter in the global location
19+
* of the specified project using the Google Cloud Parameter Manager SDK.
20+
*
21+
* @param {string} projectId - The Google Cloud project ID where the parameter is located.
22+
* @param {string} parameterId - The ID of the parameter for which version is to be deleted.
23+
* @param {string} versionId - The version ID of the parameter to delete.
24+
*/
25+
async function main(projectId, parameterId, versionId) {
26+
// [START parametermanager_delete_param_version]
27+
/**
28+
* TODO(developer): Uncomment these variables before running the sample.
29+
*/
30+
// const projectId = 'my-project';
31+
// const parameterId = 'my-parameter';
32+
// const versionId = 'v1';
33+
34+
// Imports the Parameter Manager library
35+
const {ParameterManagerClient} = require('@google-cloud/parametermanager');
36+
37+
// Instantiates a client
38+
const client = new ParameterManagerClient();
39+
40+
async function deleteParamVersion() {
41+
// Construct the fully qualified parameter version name
42+
const name = client.parameterVersionPath(
43+
projectId,
44+
'global',
45+
parameterId,
46+
versionId
47+
);
48+
49+
// Delete the parameter version
50+
await client.deleteParameterVersion({
51+
name: name,
52+
});
53+
console.log(`Deleted parameter version: ${name}`);
54+
return name;
55+
}
56+
57+
return await deleteParamVersion();
58+
// [END parametermanager_delete_param_version]
59+
}
60+
module.exports.main = main;
61+
62+
/* c8 ignore next 10 */
63+
if (require.main === module) {
64+
main(...process.argv.slice(2)).catch(err => {
65+
console.error(err.message);
66+
process.exitCode = 1;
67+
});
68+
process.on('unhandledRejection', err => {
69+
console.error(err.message);
70+
process.exitCode = 1;
71+
});
72+
}
Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
// Copyright 2025 Google LLC
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// https://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
15+
'use strict';
16+
17+
/**
18+
* Disables a specific version of a global parameter in Google Cloud Parameter Manager.
19+
* This function demonstrates how to disable a global parameter version by setting
20+
* its 'disabled' field to true using the Parameter Manager client library.
21+
*
22+
* @param {string} projectId - The Google Cloud project ID where the parameter is located.
23+
* @param {string} parameterId - The ID of the parameter for which version is to be disabled.
24+
* @param {string} versionId - The version ID of the parameter to be disabled.
25+
*/
26+
async function main(projectId, parameterId, versionId) {
27+
// [START parametermanager_disable_param_version]
28+
/**
29+
* TODO(developer): Uncomment these variables before running the sample.
30+
*/
31+
// const projectId = 'my-project';
32+
// const parameterId = 'my-parameter';
33+
// const versionId = 'v1';
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 disableParamVersion() {
42+
// Construct the full resource name
43+
const name = client.parameterVersionPath(
44+
projectId,
45+
'global',
46+
parameterId,
47+
versionId
48+
);
49+
50+
// Construct the request
51+
const request = {
52+
parameterVersion: {
53+
name: name,
54+
disabled: true,
55+
},
56+
updateMask: {
57+
paths: ['disabled'],
58+
},
59+
};
60+
61+
// Make the API call to update the parameter version
62+
const [parameterVersion] = await client.updateParameterVersion(request);
63+
64+
console.log(
65+
`Disabled parameter version ${parameterVersion.name} for parameter ${parameterId}`
66+
);
67+
return parameterVersion;
68+
}
69+
70+
return await disableParamVersion();
71+
// [END parametermanager_disable_param_version]
72+
}
73+
module.exports.main = main;
74+
75+
/* c8 ignore next 10 */
76+
if (require.main === module) {
77+
main(...process.argv.slice(2)).catch(err => {
78+
console.error(err.message);
79+
process.exitCode = 1;
80+
});
81+
process.on('unhandledRejection', err => {
82+
console.error(err.message);
83+
process.exitCode = 1;
84+
});
85+
}
Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
// Copyright 2025 Google LLC
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// https://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
15+
'use strict';
16+
17+
/**
18+
* Enables a specific version of a parameter in Google Cloud Parameter Manager.
19+
* This function demonstrates how to enable a parameter version by setting
20+
* its 'disabled' field to false using the Parameter Manager client library.
21+
*
22+
* @param {string} projectId - The Google Cloud project ID where the parameter is located.
23+
* @param {string} parameterId - The ID of the parameter for which version is to be enabled.
24+
* @param {string} versionId - The version ID of the parameter to be enabled.
25+
*/
26+
async function main(projectId, parameterId, versionId) {
27+
// [START parametermanager_enable_param_version]
28+
/**
29+
* TODO(developer): Uncomment these variables before running the sample.
30+
*/
31+
// const projectId = 'my-project';
32+
// const parameterId = 'my-parameter';
33+
// const versionId = 'v1';
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 enableParamVersion() {
42+
// Construct the full resource name
43+
const name = client.parameterVersionPath(
44+
projectId,
45+
'global',
46+
parameterId,
47+
versionId
48+
);
49+
50+
// Construct the request
51+
const request = {
52+
parameterVersion: {
53+
name: name,
54+
disabled: false,
55+
},
56+
updateMask: {
57+
paths: ['disabled'],
58+
},
59+
};
60+
61+
// Make the API call to update the parameter version
62+
const [parameterVersion] = await client.updateParameterVersion(request);
63+
64+
console.log(
65+
`Enabled parameter version ${parameterVersion.name} for parameter ${parameterId}`
66+
);
67+
return parameterVersion;
68+
}
69+
70+
return await enableParamVersion();
71+
// [END parametermanager_enable_param_version]
72+
}
73+
module.exports.main = main;
74+
75+
/* c8 ignore next 10 */
76+
if (require.main === module) {
77+
main(...process.argv.slice(2)).catch(err => {
78+
console.error(err.message);
79+
process.exitCode = 1;
80+
});
81+
process.on('unhandledRejection', err => {
82+
console.error(err.message);
83+
process.exitCode = 1;
84+
});
85+
}

0 commit comments

Comments
 (0)