|
| 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 | +} |
0 commit comments