-
Notifications
You must be signed in to change notification settings - Fork 2k
feat(parametermanager): Added samples for delete, disable, enable parameter version in global & regional #4070
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
durgesh-ninave-crest
wants to merge
5
commits into
GoogleCloudPlatform:main
Choose a base branch
from
durgesh-ninave-crest:parametermanager-all-samples-update-delete
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
6e6820a
feat(parametermanager): Added samples for delete, disable, enable and…
durgesh-ninave-crest bb59279
Merge branch 'main' into parametermanager-all-samples-update-delete
durgesh-ninave-crest ea7ffda
fix(parametermanager): update code samples and testcases
durgesh-ninave-crest e9edd91
Merge branch 'main' into parametermanager-all-samples-update-delete
glasnt dcf7005
fix(parametermanager): update testcases and function arguments
durgesh-ninave-crest File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
// Copyright 2025 Google LLC | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// https://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
'use strict'; | ||
|
||
/** | ||
* Deletes a parameter from the global location of the specified project using the Google Cloud Parameter Manager SDK. | ||
* | ||
* @param {string} projectId - The Google Cloud project ID where the parameter is located. | ||
* @param {string} parameterId - The ID of the parameter to delete. | ||
*/ | ||
async function main(projectId, parameterId) { | ||
// [START parametermanager_delete_param] | ||
/** | ||
* TODO(developer): Uncomment these variables before running the sample. | ||
*/ | ||
// const projectId = 'my-project'; | ||
// const parameterId = 'my-parameter'; | ||
|
||
// Imports the Parameter Manager library | ||
const {ParameterManagerClient} = require('@google-cloud/parametermanager'); | ||
|
||
// Instantiates a client | ||
const client = new ParameterManagerClient(); | ||
|
||
async function deleteParam() { | ||
// Construct the fully qualified parameter name | ||
const name = client.parameterPath(projectId, 'global', parameterId); | ||
|
||
// Delete the parameter | ||
await client.deleteParameter({ | ||
name: name, | ||
}); | ||
|
||
console.log(`Deleted parameter: ${name}`); | ||
return name; | ||
} | ||
|
||
return await deleteParam(); | ||
// [END parametermanager_delete_param] | ||
} | ||
module.exports.main = main; | ||
|
||
/* c8 ignore next 10 */ | ||
if (require.main === module) { | ||
main(...process.argv.slice(2)).catch(err => { | ||
console.error(err.message); | ||
process.exitCode = 1; | ||
}); | ||
process.on('unhandledRejection', err => { | ||
console.error(err.message); | ||
process.exitCode = 1; | ||
}); | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
// Copyright 2025 Google LLC | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// https://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
'use strict'; | ||
|
||
/** | ||
* Deletes a specific version of an existing parameter in the global location | ||
* of the specified project using the Google Cloud Parameter Manager SDK. | ||
* | ||
* @param {string} projectId - The Google Cloud project ID where the parameter is located. | ||
* @param {string} parameterId - The ID of the parameter for which version is to be deleted. | ||
* @param {string} versionId - The version ID of the parameter to delete. | ||
*/ | ||
async function main(projectId, parameterId, versionId) { | ||
// [START parametermanager_delete_param_version] | ||
/** | ||
* TODO(developer): Uncomment these variables before running the sample. | ||
*/ | ||
// const projectId = 'my-project'; | ||
// const parameterId = 'my-parameter'; | ||
// const versionId = 'v1'; | ||
|
||
// Imports the Parameter Manager library | ||
const {ParameterManagerClient} = require('@google-cloud/parametermanager'); | ||
|
||
// Instantiates a client | ||
const client = new ParameterManagerClient(); | ||
|
||
async function deleteParamVersion() { | ||
// Construct the fully qualified parameter version name | ||
const name = client.parameterVersionPath( | ||
projectId, | ||
'global', | ||
parameterId, | ||
versionId | ||
); | ||
|
||
// Delete the parameter version | ||
await client.deleteParameterVersion({ | ||
name: name, | ||
}); | ||
Comment on lines
+50
to
+52
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Consider adding error handling to the try {
await client.deleteParameterVersion({
name: name,
});
} catch (err) {
console.error(`Error deleting parameter version: ${err}`);
throw err; // Re-throw the error to prevent further execution
} |
||
console.log(`Deleted parameter version: ${name}`); | ||
return name; | ||
} | ||
|
||
return await deleteParamVersion(); | ||
// [END parametermanager_delete_param_version] | ||
} | ||
module.exports.main = main; | ||
|
||
/* c8 ignore next 10 */ | ||
if (require.main === module) { | ||
main(...process.argv.slice(2)).catch(err => { | ||
console.error(err.message); | ||
process.exitCode = 1; | ||
}); | ||
process.on('unhandledRejection', err => { | ||
console.error(err.message); | ||
process.exitCode = 1; | ||
}); | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
// Copyright 2025 Google LLC | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// https://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
'use strict'; | ||
|
||
/** | ||
* Disables a specific version of a global parameter in Google Cloud Parameter Manager. | ||
* This function demonstrates how to disable a global parameter version by setting | ||
* its 'disabled' field to true using the Parameter Manager client library. | ||
* | ||
* @param {string} projectId - The Google Cloud project ID where the parameter is located. | ||
* @param {string} parameterId - The ID of the parameter for which version is to be disabled. | ||
* @param {string} versionId - The version ID of the parameter to be disabled. | ||
*/ | ||
async function main(projectId, parameterId, versionId) { | ||
// [START parametermanager_disable_param_version] | ||
/** | ||
* TODO(developer): Uncomment these variables before running the sample. | ||
*/ | ||
// const projectId = 'my-project'; | ||
// const parameterId = 'my-parameter'; | ||
// const versionId = 'v1'; | ||
|
||
// Imports the Parameter Manager library | ||
const {ParameterManagerClient} = require('@google-cloud/parametermanager'); | ||
|
||
// Instantiates a client | ||
const client = new ParameterManagerClient(); | ||
|
||
async function disableParamVersion() { | ||
// Construct the full resource name | ||
const name = client.parameterVersionPath( | ||
projectId, | ||
'global', | ||
parameterId, | ||
versionId | ||
); | ||
|
||
// Construct the request | ||
const request = { | ||
parameterVersion: { | ||
name: name, | ||
disabled: true, | ||
}, | ||
updateMask: { | ||
paths: ['disabled'], | ||
}, | ||
}; | ||
|
||
// Make the API call to update the parameter version | ||
const [parameterVersion] = await client.updateParameterVersion(request); | ||
|
||
console.log( | ||
`Disabled parameter version ${parameterVersion.name} for parameter ${parameterId}` | ||
); | ||
return parameterVersion; | ||
} | ||
|
||
return await disableParamVersion(); | ||
// [END parametermanager_disable_param_version] | ||
} | ||
module.exports.main = main; | ||
|
||
/* c8 ignore next 10 */ | ||
if (require.main === module) { | ||
main(...process.argv.slice(2)).catch(err => { | ||
console.error(err.message); | ||
process.exitCode = 1; | ||
}); | ||
process.on('unhandledRejection', err => { | ||
console.error(err.message); | ||
process.exitCode = 1; | ||
}); | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
// Copyright 2025 Google LLC | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// https://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
'use strict'; | ||
|
||
/** | ||
* Enables a specific version of a parameter in Google Cloud Parameter Manager. | ||
* This function demonstrates how to enable a parameter version by setting | ||
* its 'disabled' field to false using the Parameter Manager client library. | ||
* | ||
* @param {string} projectId - The Google Cloud project ID where the parameter is located. | ||
* @param {string} parameterId - The ID of the parameter for which version is to be enabled. | ||
* @param {string} versionId - The version ID of the parameter to be enabled. | ||
*/ | ||
async function main(projectId, parameterId, versionId) { | ||
// [START parametermanager_enable_param_version] | ||
/** | ||
* TODO(developer): Uncomment these variables before running the sample. | ||
*/ | ||
// const projectId = 'my-project'; | ||
// const parameterId = 'my-parameter'; | ||
// const versionId = 'v1'; | ||
|
||
// Imports the Parameter Manager library | ||
const {ParameterManagerClient} = require('@google-cloud/parametermanager'); | ||
|
||
// Instantiates a client | ||
const client = new ParameterManagerClient(); | ||
|
||
async function enableParamVersion() { | ||
// Construct the full resource name | ||
const name = client.parameterVersionPath( | ||
projectId, | ||
'global', | ||
parameterId, | ||
versionId | ||
); | ||
|
||
// Construct the request | ||
const request = { | ||
parameterVersion: { | ||
name: name, | ||
disabled: false, | ||
}, | ||
updateMask: { | ||
paths: ['disabled'], | ||
}, | ||
}; | ||
|
||
// Make the API call to update the parameter version | ||
const [parameterVersion] = await client.updateParameterVersion(request); | ||
|
||
console.log( | ||
`Enabled parameter version ${parameterVersion.name} for parameter ${parameterId}` | ||
); | ||
return parameterVersion; | ||
} | ||
|
||
return await enableParamVersion(); | ||
// [END parametermanager_enable_param_version] | ||
} | ||
module.exports.main = main; | ||
|
||
/* c8 ignore next 10 */ | ||
if (require.main === module) { | ||
main(...process.argv.slice(2)).catch(err => { | ||
console.error(err.message); | ||
process.exitCode = 1; | ||
}); | ||
process.on('unhandledRejection', err => { | ||
console.error(err.message); | ||
process.exitCode = 1; | ||
}); | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
{ | ||
"name": "nodejs-parameter-manager-samples", | ||
"private": true, | ||
"license": "Apache-2.0", | ||
"files": [ | ||
"*.js" | ||
], | ||
"author": "Google LLC", | ||
"repository": "googleapis/nodejs-parameter-manager", | ||
"engines": { | ||
"node": ">=20" | ||
}, | ||
"scripts": { | ||
"test": "c8 mocha --recursive test/ --timeout=800000" | ||
}, | ||
"directories": { | ||
"test": "test" | ||
}, | ||
"dependencies": { | ||
"@google-cloud/parametermanager": "^0.1.0" | ||
}, | ||
"devDependencies": { | ||
"@google-cloud/secret-manager": "^5.6.0", | ||
"c8": "^10.1.3", | ||
"chai": "^4.5.0", | ||
"mocha": "^11.1.0", | ||
"uuid": "^11.0.5" | ||
} | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Consider adding error handling to the
deleteParameter
call to provide more informative error messages to the user. A simpletry...catch
block would suffice.