* Updates a global parameter with kms_key using the Parameter Manager SDK. * * @param {string} projectId - The Google Cloud project ID where the parameter is to be updated. * @param {string} parameterId - The ID of the parameter to update. This ID must be unique within the project. * @param {str
(projectId, parameterId, kmsKey)
| 22 | * @param {string} kmsKey - The ID of the KMS key to be used for encryption. |
| 23 | */ |
| 24 | async function main(projectId, parameterId, kmsKey) { |
| 25 | // [START parametermanager_update_param_kms_key] |
| 26 | /** |
| 27 | * TODO(developer): Uncomment these variables before running the sample. |
| 28 | */ |
| 29 | // const projectId = 'YOUR_PROJECT_ID'; |
| 30 | // const parameterId = 'YOUR_PARAMETER_ID'; |
| 31 | // const kmsKey = 'YOUR_KMS_KEY' |
| 32 | |
| 33 | // Imports the Parameter Manager library |
| 34 | const {ParameterManagerClient} = require('@google-cloud/parametermanager'); |
| 35 | |
| 36 | // Instantiates a client |
| 37 | const client = new ParameterManagerClient(); |
| 38 | |
| 39 | async function updateParamKmsKey() { |
| 40 | const name = client.parameterPath(projectId, 'global', parameterId); |
| 41 | const request = { |
| 42 | parameter: { |
| 43 | name: name, |
| 44 | kmsKey: kmsKey, |
| 45 | }, |
| 46 | updateMask: { |
| 47 | paths: ['kms_key'], |
| 48 | }, |
| 49 | }; |
| 50 | |
| 51 | const [parameter] = await client.updateParameter(request); |
| 52 | console.log( |
| 53 | `Updated parameter ${parameter.name} with kms_key ${parameter.kmsKey}` |
| 54 | ); |
| 55 | return parameter; |
| 56 | } |
| 57 | |
| 58 | return await updateParamKmsKey(); |
| 59 | // [END parametermanager_update_param_kms_key] |
| 60 | } |
| 61 | module.exports.main = main; |
| 62 | |
| 63 | /* c8 ignore next 10 */ |
no test coverage detected