-
Notifications
You must be signed in to change notification settings - Fork 2k
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
feat(parametermanager): add global and regional samples for kms_key field #4059
Draft
vatsal-vora-crestdata
wants to merge
4
commits into
GoogleCloudPlatform:main
Choose a base branch
from
vatsal-vora-crestdata:parametermanager-kms_key-samples
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.
Draft
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
08aef70
feat(parametermanager): add global and regional samples for kms_key f…
vatsal-vora-crestdata 152c32c
fix(parametermanager): update package.json file
vatsal-vora-crestdata 4c1b788
fix(parametermanager): update test cases
vatsal-vora-crestdata f8c0035
fix(parametermanager): update testcases for kms_key field
vatsal-vora-crestdata 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 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,64 @@ | ||
// 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'; | ||
|
||
/** | ||
* Creates 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 created. | ||
* @param {string} parameterId - The ID of the parameter to create. This ID must be unique within the project. | ||
* @param {string} kmsKey - The ID of the KMS key to be used for encryption. | ||
*/ | ||
async function main( | ||
projectId = 'my-project', | ||
parameterId = 'my-parameter', | ||
kmsKey = 'projects/my-project/locations/global/keyRings/my-key-ring/cryptoKeys/my-encryption-key' | ||
) { | ||
// [START parametermanager_create_param_with_kms_key] | ||
/** | ||
* TODO(developer): Uncomment these variables before running the sample. | ||
*/ | ||
// const projectId = 'YOUR_PROJECT_ID'; | ||
// const parameterId = 'YOUR_PARAMETER_ID'; | ||
// const kmsKey = 'YOUR_KMS_KEY' | ||
|
||
// Imports the Parameter Manager library | ||
const {ParameterManagerClient} = require('@google-cloud/parametermanager'); | ||
|
||
// Instantiates a client | ||
const client = new ParameterManagerClient(); | ||
|
||
async function createParamWithKmsKey() { | ||
const parent = client.locationPath(projectId, 'global'); | ||
const request = { | ||
parent: parent, | ||
parameterId: parameterId, | ||
parameter: { | ||
kmsKey: kmsKey, | ||
}, | ||
}; | ||
|
||
const [parameter] = await client.createParameter(request); | ||
console.log( | ||
`Created parameter ${parameter.name} with kms_key ${parameter.kmsKey}` | ||
); | ||
} | ||
|
||
await createParamWithKmsKey(); | ||
// [END parametermanager_create_param_with_kms_key] | ||
} | ||
|
||
const args = process.argv.slice(2); | ||
main(...args).catch(console.error); |
This file contains 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.3.0" | ||
}, | ||
"devDependencies": { | ||
"@google-cloud/kms": "^4.0.0", | ||
"c8": "^10.1.3", | ||
"chai": "^4.5.0", | ||
"mocha": "^11.1.0", | ||
"uuid": "^11.0.5" | ||
} | ||
} |
72 changes: 72 additions & 0 deletions
72
parametermanager/regional_samples/createRegionalParamWithKmsKey.js
This file contains 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'; | ||
|
||
/** | ||
* Creates a regional parameter with kms_key using the Parameter Manager SDK. | ||
* | ||
* @param {string} projectId - The Google Cloud project ID where the parameter is to be created. | ||
* @param {string} locationId - The ID of the region where parameter is to be created. | ||
* @param {string} parameterId - The ID of the parameter to create. This ID must be unique within the project. | ||
* @param {string} kmsKey - The ID of the KMS key to be used for encryption. | ||
*/ | ||
async function main( | ||
projectId = 'my-project', | ||
locationId = 'us-central1', | ||
parameterId = 'my-parameter', | ||
kmsKey = 'projects/my-project/locations/us-central1/keyRings/my-key-ring/cryptoKeys/my-encryption-key' | ||
) { | ||
// [START parametermanager_create_regional_param_with_kms_key] | ||
/** | ||
* TODO(developer): Uncomment these variables before running the sample. | ||
*/ | ||
// const projectId = 'YOUR_PROJECT_ID'; | ||
// const locationId = 'YOUR_LOCATION_ID'; | ||
// const parameterId = 'YOUR_PARAMETER_ID'; | ||
// const kmsKey = 'YOUR_KMS_KEY' | ||
|
||
// Imports the Parameter Manager library | ||
const {ParameterManagerClient} = require('@google-cloud/parametermanager'); | ||
|
||
// Adding the endpoint to call the regional parameter manager server | ||
const options = { | ||
apiEndpoint: `parametermanager.${locationId}.rep.googleapis.com`, | ||
}; | ||
|
||
// Instantiates a client with regional endpoint | ||
const client = new ParameterManagerClient(options); | ||
|
||
async function createRegionalParamWithKmsKey() { | ||
const parent = client.locationPath(projectId, locationId); | ||
const request = { | ||
parent: parent, | ||
parameterId: parameterId, | ||
parameter: { | ||
kmsKey: kmsKey, | ||
}, | ||
}; | ||
|
||
const [parameter] = await client.createParameter(request); | ||
console.log( | ||
`Created regional parameter ${parameter.name} with kms_key ${parameter.kmsKey}` | ||
); | ||
} | ||
|
||
await createRegionalParamWithKmsKey(); | ||
// [END parametermanager_create_regional_param_with_kms_key] | ||
} | ||
|
||
const args = process.argv.slice(2); | ||
main(...args).catch(console.error); |
68 changes: 68 additions & 0 deletions
68
parametermanager/regional_samples/removeRegionalParamKmsKey.js
This file contains 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,68 @@ | ||
// 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'; | ||
|
||
/** | ||
* Removes a kms_key for regional parameter using the Parameter Manager SDK. | ||
* | ||
* @param {string} projectId - The Google Cloud project ID where the parameter is to be updated. | ||
* @param {string} locationId - The ID of the region where parameter is to be updated. | ||
* @param {string} parameterId - The ID of the parameter to update. This ID must be unique within the project. | ||
*/ | ||
async function main( | ||
projectId = 'my-project', | ||
locationId = 'us-central1', | ||
parameterId = 'my-parameter' | ||
) { | ||
// [START parametermanager_remove_regional_param_kms_key] | ||
/** | ||
* TODO(developer): Uncomment these variables before running the sample. | ||
*/ | ||
// const projectId = 'YOUR_PROJECT_ID'; | ||
// const locationId = 'YOUR_LOCATION_ID'; | ||
// const parameterId = 'YOUR_PARAMETER_ID'; | ||
|
||
// Imports the Parameter Manager library | ||
const {ParameterManagerClient} = require('@google-cloud/parametermanager'); | ||
|
||
// Adding the endpoint to call the regional parameter manager server | ||
const options = { | ||
apiEndpoint: `parametermanager.${locationId}.rep.googleapis.com`, | ||
}; | ||
|
||
// Instantiates a client with regional endpoint | ||
const client = new ParameterManagerClient(options); | ||
|
||
async function removeRegionalParamKmsKey() { | ||
const name = client.parameterPath(projectId, locationId, parameterId); | ||
const request = { | ||
parameter: { | ||
name: name, | ||
}, | ||
updateMask: { | ||
paths: ['kms_key'], | ||
}, | ||
}; | ||
|
||
const [parameter] = await client.updateParameter(request); | ||
console.log(`Removed kms_key for regional parameter ${parameter.name}`); | ||
} | ||
|
||
await removeRegionalParamKmsKey(); | ||
// [END parametermanager_remove_regional_param_kms_key] | ||
} | ||
|
||
const args = process.argv.slice(2); | ||
main(...args).catch(console.error); |
74 changes: 74 additions & 0 deletions
74
parametermanager/regional_samples/updateRegionalParamKmsKey.js
This file contains 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,74 @@ | ||
// 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'; | ||
|
||
/** | ||
* Updates a regional 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} locationId - The ID of the region where parameter is to be updated. | ||
* @param {string} parameterId - The ID of the parameter to update. This ID must be unique within the project. | ||
* @param {string} kmsKey - The ID of the KMS key to be used for encryption. | ||
*/ | ||
async function main( | ||
projectId = 'my-project', | ||
locationId = 'us-central1', | ||
parameterId = 'my-parameter', | ||
kmsKey = 'projects/my-project/locations/us-central1/keyRings/my-key-ring/cryptoKeys/my-encryption-key' | ||
) { | ||
// [START parametermanager_update_regional_param_kms_key] | ||
/** | ||
* TODO(developer): Uncomment these variables before running the sample. | ||
*/ | ||
// const projectId = 'YOUR_PROJECT_ID'; | ||
// const locationId = 'YOUR_LOCATION_ID'; | ||
// const parameterId = 'YOUR_PARAMETER_ID'; | ||
// const kmsKey = 'YOUR_KMS_KEY' | ||
|
||
// Imports the Parameter Manager library | ||
const {ParameterManagerClient} = require('@google-cloud/parametermanager'); | ||
|
||
// Adding the endpoint to call the regional parameter manager server | ||
const options = { | ||
apiEndpoint: `parametermanager.${locationId}.rep.googleapis.com`, | ||
}; | ||
|
||
// Instantiates a client with regional endpoint | ||
const client = new ParameterManagerClient(options); | ||
|
||
async function updateRegionalParamKmsKey() { | ||
const name = client.parameterPath(projectId, locationId, parameterId); | ||
const request = { | ||
parameter: { | ||
name: name, | ||
kmsKey: kmsKey, | ||
}, | ||
Comment on lines
+53
to
+57
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. |
||
updateMask: { | ||
paths: ['kms_key'], | ||
}, | ||
}; | ||
|
||
const [parameter] = await client.updateParameter(request); | ||
console.log( | ||
`Updated regional parameter ${parameter.name} with kms_key ${parameter.kmsKey}` | ||
); | ||
} | ||
|
||
await updateRegionalParamKmsKey(); | ||
// [END parametermanager_update_regional_param_kms_key] | ||
} | ||
|
||
const args = process.argv.slice(2); | ||
main(...args).catch(console.error); |
This file contains 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,57 @@ | ||
// 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'; | ||
|
||
/** | ||
* Removes a kms_key for global parameter 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. | ||
*/ | ||
async function main(projectId = 'my-project', parameterId = 'my-parameter') { | ||
// [START parametermanager_remove_param_kms_key] | ||
/** | ||
* TODO(developer): Uncomment these variables before running the sample. | ||
*/ | ||
// const projectId = 'YOUR_PROJECT_ID'; | ||
// const parameterId = 'YOUR_PARAMETER_ID'; | ||
|
||
// Imports the Parameter Manager library | ||
const {ParameterManagerClient} = require('@google-cloud/parametermanager'); | ||
|
||
// Instantiates a client | ||
const client = new ParameterManagerClient(); | ||
|
||
async function removeParamKmsKey() { | ||
const name = client.parameterPath(projectId, 'global', parameterId); | ||
const request = { | ||
parameter: { | ||
name: name, | ||
}, | ||
Comment on lines
+39
to
+42
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. |
||
updateMask: { | ||
paths: ['kms_key'], | ||
}, | ||
}; | ||
|
||
const [parameter] = await client.updateParameter(request); | ||
console.log(`Removed kms_key for parameter ${parameter.name}`); | ||
} | ||
|
||
await removeParamKmsKey(); | ||
// [END parametermanager_remove_param_kms_key] | ||
} | ||
|
||
const args = process.argv.slice(2); | ||
main(...args).catch(console.error); |
This file contains 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,17 @@ | ||
# 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. | ||
|
||
--- | ||
env: | ||
mocha: true |
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.
The
request
object only contains thename
in the parameter field. It might be clearer to directly pass the name to theclient.updateParameter
function, if the API allows it.