Skip to content

feat(parametermanager): Added samples for create, get, list and render global parameter & parameter version #4068

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
wants to merge 6 commits into
base: main
Choose a base branch
from

Conversation

durgesh-ninave-crest
Copy link

Description

Created samples for creating, listing and rendering parameter and parameter version

Samples List (global):

  1. parameter-structured-data
  2. parameter-unstructured-data
  3. add-parameter-version (structured, unstructured)
  4. create-parameter-secret-reference
  5. list-all-parameters
  6. view-parameter-details
  7. list-all-parameters-versions
  8. view-parameter-version-details
  9. render-secret-parameter-version

Checklist

  • I have followed guidelines from CONTRIBUTING.MD and Samples Style Guide
  • Tests pass: npm test (see Testing)
  • Lint pass: npm run lint (see Style)
  • These samples need a new API enabled in testing projects to pass (let us know which ones)
  • These samples need a new/updated env vars in testing projects set to pass (let us know which ones)
  • This pull request is from a branch created directly off of GoogleCloudPlatform/nodejs-docs-samples. Not a fork.
  • This sample adds a new sample directory, and I updated the CODEOWNERS file with the codeowners for this sample
  • This sample adds a new sample directory, and I created GitHub Actions workflow for this sample
  • This sample adds a new Product API, and I updated the Blunderbuss issue/PR auto-assigner with the codeowners for this sample
  • Please merge this PR for me once it is approved

@durgesh-ninave-crest durgesh-ninave-crest requested review from a team as code owners April 9, 2025 07:48
Copy link

snippet-bot bot commented Apr 9, 2025

Here is the summary of changes.

You are about to add 10 region tags.

This comment is generated by snippet-bot.
If you find problems with this result, please file an issue at:
https://github.com/googleapis/repo-automation-bots/issues.
To update this comment, add snippet-bot:force-run label or use the checkbox below:

  • Refresh this comment

@product-auto-label product-auto-label bot added the samples Issues that are directly related to samples. label Apr 9, 2025
Copy link
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hello @durgesh-ninave-crest, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

Summary of Changes

This pull request introduces samples for creating, listing, and rendering parameters and parameter versions using the Parameter Manager SDK. These samples cover various scenarios, including structured and unstructured data, referencing secrets, and managing parameter versions. The changes include the addition of new JavaScript files, each demonstrating a specific functionality of the Parameter Manager API, as well as a package.json file to manage dependencies and tests.

Highlights

  • New Samples: Added samples for creating parameters with structured and unstructured data.
  • Parameter Versions: Introduced samples for creating and managing parameter versions, including referencing secrets.
  • Listing and Rendering: Implemented samples for listing parameters and their versions, as well as rendering parameter versions.
  • Testing: Added a test suite to verify the functionality of the new samples.

Changelog

Click here to see the changelog
  • parametermanager/createParam.js
    • Added a sample for creating a global parameter.
    • Demonstrates the use of ParameterManagerClient to create a parameter.
  • parametermanager/createParamVersion.js
    • Added a sample for creating a parameter version with unstructured data.
    • Shows how to construct a parameter version with a payload.
  • parametermanager/createParamVersionWithSecret.js
    • Added a sample for creating a parameter version with secret references.
    • Demonstrates how to include references to secrets in the parameter version payload.
  • parametermanager/createStructuredParam.js
    • Added a sample for creating a structured parameter.
    • Shows how to specify the format of the parameter (JSON, YAML, etc.).
  • parametermanager/createStructuredParamVersion.js
    • Added a sample for creating a structured parameter version.
    • Demonstrates how to store JSON data in a parameter version.
  • parametermanager/getParam.js
    • Added a sample for retrieving a parameter.
    • Shows how to use ParameterManagerClient to get parameter details.
  • parametermanager/getParamVersion.js
    • Added a sample for retrieving a parameter version.
    • Demonstrates how to get the details of a specific version of a parameter.
  • parametermanager/listParamVersions.js
    • Added a sample for listing parameter versions.
    • Shows how to iterate through all versions of a parameter.
  • parametermanager/listParams.js
    • Added a sample for listing parameters.
    • Demonstrates how to list all parameters in a project.
  • parametermanager/package.json
    • Added dependencies for @google-cloud/parametermanager, @google-cloud/secret-manager, c8, chai, mocha, and uuid.
    • Configured test script to use c8 and mocha.
  • parametermanager/renderParamVersion.js
    • Added a sample for rendering a parameter version.
    • Shows how to retrieve and resolve secret references in a parameter version.
  • parametermanager/test/.eslintrc.yml
    • Added eslint config for test directory.
  • parametermanager/test/parametermanager.test.js
    • Added tests for all the new samples.
    • Tests cover creating, listing, getting, and rendering parameters and parameter versions.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point in your pull request via creating an issue comment (i.e. comment on the pull request page) using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in issue comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist is currently in preview and may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments to provide feedback.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.


A parameter's tale,
Versions spun, secrets unveiled,
Rendered, clear and bright.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

The pull request introduces samples for creating, listing, and rendering parameters and parameter versions using the Google Cloud Parameter Manager SDK. The samples cover various scenarios, including structured and unstructured data, as well as referencing secrets. Overall, the code is well-structured and easy to follow. However, there are a few areas that could be improved for clarity and robustness.

Summary of Findings

  • Missing Error Handling: The samples lack explicit error handling for the API calls. While the .catch(console.error) at the end of the main function will catch some errors, it doesn't provide specific feedback to the user about what went wrong or how to fix it. More robust error handling would improve the user experience.
  • TODO Comments: The TODO(developer) comments suggest that users need to uncomment variables before running the samples. It would be better to provide a mechanism for users to pass these values as command-line arguments or environment variables, making the samples more flexible and easier to use.
  • Inconsistent Parameter Version ID: In createParamVersionWithSecret.js, the parameter version ID is hardcoded as 'v1' in the function definition but is passed as a command-line argument. This inconsistency could lead to confusion. It would be better to either use the command-line argument value as the default or remove the default value from the function definition.

Merge Readiness

The pull request introduces valuable samples for interacting with the Parameter Manager API. However, addressing the identified issues related to error handling and user input would significantly enhance the quality and usability of these samples. I am unable to directly approve this pull request, and recommend that others review and approve this code before merging. At a minimum, the high severity issues should be addressed before merging.


// Parse command line arguments
const args = process.argv.slice(2);
main(...args).catch(console.error);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

high

While this .catch will catch errors, it doesn't provide specific feedback to the user about what went wrong. Consider adding more robust error handling within the main function to provide more informative error messages.

Suggested change
main(...args).catch(console.error);
main(...args).catch(err => {
console.error('ERROR:', err);
process.exitCode = 1; // Exit with a non-zero status code to indicate failure
});

}

const args = process.argv.slice(2);
main(...args).catch(console.error);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

high

While this .catch will catch errors, it doesn't provide specific feedback to the user about what went wrong. Consider adding more robust error handling within the main function to provide more informative error messages.

Suggested change
main(...args).catch(console.error);
main(...args).catch(err => {
console.error('ERROR:', err);
process.exitCode = 1; // Exit with a non-zero status code to indicate failure
});


// Parse command line arguments
const args = process.argv.slice(2);
main(...args).catch(console.error);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

high

While this .catch will catch errors, it doesn't provide specific feedback to the user about what went wrong. Consider adding more robust error handling within the main function to provide more informative error messages.

Suggested change
main(...args).catch(console.error);
main(...args).catch(err => {
console.error('ERROR:', err);
process.exitCode = 1; // Exit with a non-zero status code to indicate failure
});


// Parse command line arguments
const args = process.argv.slice(2);
main(...args).catch(console.error);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

high

While this .catch will catch errors, it doesn't provide specific feedback to the user about what went wrong. Consider adding more robust error handling within the main function to provide more informative error messages.

Suggested change
main(...args).catch(console.error);
main(...args).catch(err => {
console.error('ERROR:', err);
process.exitCode = 1; // Exit with a non-zero status code to indicate failure
});

}

const args = process.argv.slice(2);
main(...args).catch(console.error);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

high

While this .catch will catch errors, it doesn't provide specific feedback to the user about what went wrong. Consider adding more robust error handling within the main function to provide more informative error messages.

Suggested change
main(...args).catch(console.error);
main(...args).catch(err => {
console.error('ERROR:', err);
process.exitCode = 1; // Exit with a non-zero status code to indicate failure
});

Comment on lines +26 to +29
* TODO(developer): Uncomment these variables before running the sample.
*/
// const projectId = 'YOUR_PROJECT_ID';
// const parameterId = 'YOUR_PARAMETER_ID';
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

Consider providing a mechanism for users to pass the projectId and parameterId values as command-line arguments or environment variables instead of relying on them to uncomment these lines. This would make the sample more flexible and easier to use.

Comment on lines +26 to +28
* TODO(developer): Uncomment these variables before running the sample.
*/
// const projectId = 'my-project';
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

Consider providing a mechanism for users to pass the projectId value as command-line arguments or environment variables instead of relying on them to uncomment these lines. This would make the sample more flexible and easier to use.

Comment on lines +35 to +40
* TODO(developer): Uncomment these variables before running the sample.
*/
// const projectId = 'YOUR_PROJECT_ID';
// const parameterId = 'YOUR_PARAMETER_ID';
// const parameterVersionId = 'YOUR_PARAMETER_VERSION_ID';
// const secretId = 'YOUR_SECRET_ID'; // For example projects/my-project/secrets/application-secret/version/latest
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

Consider providing a mechanism for users to pass the projectId, parameterId, parameterVersionId, and secretId values as command-line arguments or environment variables instead of relying on them to uncomment these lines. This would make the sample more flexible and easier to use.

Comment on lines +33 to +37
* TODO(developer): Uncomment these variables before running the sample.
*/
// const projectId = 'YOUR_PROJECT_ID';
// const parameterId = 'YOUR_PARAMETER_ID';
// const parameterVersionId = 'YOUR_PARAMETER_VERSION_ID';
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

Consider providing a mechanism for users to pass the projectId, parameterId, and parameterVersionId values as command-line arguments or environment variables instead of relying on them to uncomment these lines. This would make the sample more flexible and easier to use.

Comment on lines +33 to +38
* TODO(developer): Uncomment these variables before running the sample.
*/
// const projectId = 'YOUR_PROJECT_ID';
// const parameterId = 'YOUR_PARAMETER_ID';
// const parameterVersionId = 'YOUR_PARAMETER_VERSION_ID';
// const payload = 'This is unstructured data';
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

Consider providing a mechanism for users to pass the projectId, parameterId, parameterVersionId, and payload values as command-line arguments or environment variables instead of relying on them to uncomment these lines. This would make the sample more flexible and easier to use.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
samples Issues that are directly related to samples.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant