-
Notifications
You must be signed in to change notification settings - Fork 2k
feat(parametermanager): Added samples for kms_key field in parameter manager #4071
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
6
commits into
GoogleCloudPlatform:main
Choose a base branch
from
durgesh-ninave-crest: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.
Open
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
d3676ec
feat(parametermanager): Added samples for kms_key field in parameter …
durgesh-ninave-crest 56cc295
Merge branch 'main' into parametermanager-kms_key-samples
durgesh-ninave-crest a77accd
fix(parametermanager): update code samples and testcases
durgesh-ninave-crest 5bdd1c2
Merge branch 'main' into parametermanager-kms_key-samples
durgesh-ninave-crest c0ed3f5
fix(parametermanager): update testcase and function arguments
durgesh-ninave-crest 1726b8b
Merge branch 'main' into parametermanager-kms_key-samples
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,71 @@ | ||
// 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, parameterId, kmsKey) { | ||
// [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}` | ||
); | ||
return parameter; | ||
} | ||
|
||
return await createParamWithKmsKey(); | ||
// [END parametermanager_create_param_with_kms_key] | ||
} | ||
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
78 changes: 78 additions & 0 deletions
78
parametermanager/regional_samples/createRegionalParamWithKmsKey.js
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,78 @@ | ||
// 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, locationId, parameterId, kmsKey) { | ||
// [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}` | ||
); | ||
return parameter; | ||
} | ||
|
||
return await createRegionalParamWithKmsKey(); | ||
// [END parametermanager_create_regional_param_with_kms_key] | ||
} | ||
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; | ||
}); | ||
} |
75 changes: 75 additions & 0 deletions
75
parametermanager/regional_samples/removeRegionalParamKmsKey.js
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,75 @@ | ||
// 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, locationId, parameterId) { | ||
// [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}`); | ||
return parameter; | ||
} | ||
|
||
return await removeRegionalParamKmsKey(); | ||
// [END parametermanager_remove_regional_param_kms_key] | ||
} | ||
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; | ||
}); | ||
} |
80 changes: 80 additions & 0 deletions
80
parametermanager/regional_samples/updateRegionalParamKmsKey.js
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,80 @@ | ||
// 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, locationId, parameterId, kmsKey) { | ||
// [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, | ||
}, | ||
updateMask: { | ||
paths: ['kms_key'], | ||
}, | ||
}; | ||
|
||
const [parameter] = await client.updateParameter(request); | ||
console.log( | ||
`Updated regional parameter ${parameter.name} with kms_key ${parameter.kmsKey}` | ||
); | ||
return parameter; | ||
} | ||
|
||
return await updateRegionalParamKmsKey(); | ||
// [END parametermanager_update_regional_param_kms_key] | ||
} | ||
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,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 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. | ||
*/ | ||
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. |
||
async function main(projectId, parameterId) { | ||
// [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, | ||
}, | ||
updateMask: { | ||
paths: ['kms_key'], | ||
}, | ||
}; | ||
|
||
const [parameter] = await client.updateParameter(request); | ||
console.log(`Removed kms_key for parameter ${parameter.name}`); | ||
return parameter; | ||
} | ||
|
||
return await removeParamKmsKey(); | ||
// [END parametermanager_remove_param_kms_key] | ||
} | ||
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; | ||
}); | ||
} |
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 function description mentions that the parameter ID must be unique within the project, but it should also specify that it must be unique within the region.