-
Notifications
You must be signed in to change notification settings - Fork 2k
feat(parametermanager): Added samples to delete, enable and disable parameter versions in both region and global #4014
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
Changes from all commits
85320f4
42aa1d2
be8d121
58b269b
5a2f981
1aacd58
97d21b6
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
# 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 | ||
# | ||
# http://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. | ||
|
||
name: parametermanager | ||
on: | ||
push: | ||
branches: | ||
- main | ||
paths: | ||
- 'parametermanager/**' | ||
- '.github/workflows/parametermanager.yaml' | ||
pull_request: | ||
types: | ||
- opened | ||
- reopened | ||
- synchronize | ||
- labeled | ||
paths: | ||
- 'parametermanager/**' | ||
- '.github/workflows/parametermanager.yaml' | ||
schedule: | ||
- cron: '0 0 * * 0' | ||
jobs: | ||
test: | ||
# Ref: https://github.com/google-github-actions/auth#usage | ||
permissions: | ||
contents: 'read' | ||
id-token: 'write' | ||
if: github.event.action != 'labeled' || github.event.label.name == 'actions:force-run' | ||
uses: ./.github/workflows/test.yaml | ||
with: | ||
name: 'parametermanager' | ||
path: 'parametermanager' | ||
flakybot: | ||
# Ref: https://github.com/google-github-actions/auth#usage | ||
permissions: | ||
contents: 'read' | ||
id-token: 'write' | ||
if: github.event_name == 'schedule' && always() # always() submits logs even if tests fail | ||
uses: ./.github/workflows/flakybot.yaml | ||
needs: [test] |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
// 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 = 'my-project', parameterId = 'my-parameter') { | ||
// [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, | ||
}); | ||
Comment on lines
+42
to
+44
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. |
||
|
||
console.log(`Deleted parameter: ${name}`); | ||
} | ||
|
||
await deleteParam(); | ||
// [END parametermanager_delete_param] | ||
} | ||
|
||
// The command-line arguments are passed as an array to main() | ||
const args = process.argv.slice(2); | ||
main(...args).catch(console.error); |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
// Copyright 2025 Google LLC | ||
glasnt marked this conversation as resolved.
Show resolved
Hide resolved
|
||
// | ||
// 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 = 'my-project', | ||
parameterId = 'my-parameter', | ||
versionId = 'v1' | ||
) { | ||
// [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
+53
to
+55
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. |
||
}); | ||
|
||
console.log(`Deleted parameter version: ${name}`); | ||
} | ||
|
||
await deleteParamVersion(); | ||
// [END parametermanager_delete_param_version] | ||
} | ||
|
||
// The command-line arguments are passed as an array to main() | ||
const args = process.argv.slice(2); | ||
main(...args).catch(console.error); |
Original file line number | Diff line number | Diff line change | ||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
@@ -0,0 +1,80 @@ | ||||||||||||||||||||
// Copyright 2025 Google LLC | ||||||||||||||||||||
glasnt marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||||||||||||||||
// | ||||||||||||||||||||
// 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 = 'my-project', | ||||||||||||||||||||
parameterId = 'my-parameter', | ||||||||||||||||||||
versionId = 'v1' | ||||||||||||||||||||
) { | ||||||||||||||||||||
// [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 [response] = await client.updateParameterVersion(request); | ||||||||||||||||||||
|
||||||||||||||||||||
Comment on lines
+65
to
+67
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 API call to improve the robustness of the sample.
Suggested change
|
||||||||||||||||||||
console.log( | ||||||||||||||||||||
`Disabled parameter version ${response.name} for parameter ${parameterId}` | ||||||||||||||||||||
); | ||||||||||||||||||||
return response; | ||||||||||||||||||||
} | ||||||||||||||||||||
|
||||||||||||||||||||
await disableParamVersion(); | ||||||||||||||||||||
// [END parametermanager_disable_param_version] | ||||||||||||||||||||
} | ||||||||||||||||||||
|
||||||||||||||||||||
// The command-line arguments are passed as an array to main(). | ||||||||||||||||||||
const args = process.argv.slice(2); | ||||||||||||||||||||
main(...args).catch(console.error); |
Original file line number | Diff line number | Diff line change | ||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
@@ -0,0 +1,80 @@ | ||||||||||||||||||||
// Copyright 2025 Google LLC | ||||||||||||||||||||
glasnt marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||||||||||||||||
// | ||||||||||||||||||||
// 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 = 'my-project', | ||||||||||||||||||||
parameterId = 'my-parameter', | ||||||||||||||||||||
versionId = 'v1' | ||||||||||||||||||||
) { | ||||||||||||||||||||
// [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 [response] = await client.updateParameterVersion(request); | ||||||||||||||||||||
|
||||||||||||||||||||
Comment on lines
+65
to
+67
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 API call to improve the robustness of the sample.
Suggested change
|
||||||||||||||||||||
console.log( | ||||||||||||||||||||
`Enabled parameter version ${response.name} for parameter ${parameterId}` | ||||||||||||||||||||
); | ||||||||||||||||||||
return response; | ||||||||||||||||||||
} | ||||||||||||||||||||
|
||||||||||||||||||||
await enableParamVersion(); | ||||||||||||||||||||
// [END parametermanager_enable_param_version] | ||||||||||||||||||||
} | ||||||||||||||||||||
|
||||||||||||||||||||
// The command-line arguments are passed as an array to main(). | ||||||||||||||||||||
const args = process.argv.slice(2); | ||||||||||||||||||||
main(...args).catch(console.error); |
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" | ||
} | ||
} |
Uh oh!
There was an error while loading. Please reload this page.