-
Notifications
You must be signed in to change notification settings - Fork 1.8k
feat(parametermanager): Added samples for creating parameter and versions #5230
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): Added samples for creating parameter and versions #5230
Conversation
|
Here is the summary of changes. You are about to add 5 region tags.
This comment is generated by snippet-bot.
|
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.
Hello @vatsal-vora-crestdata, 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 parameters and parameter versions using the Parameter Manager SDK. It includes samples for both global and regional parameters, covering scenarios such as creating parameters with structured and unstructured data, adding parameter versions, and creating parameter secret references. The changes include adding new files for each sample and updating the go.work file to include the new parametermanager module.
Highlights
- New samples: Adds samples for creating parameters with structured and unstructured data.
- Parameter versions: Introduces samples for adding parameter versions (structured, unstructured).
- Secret references: Includes a sample for creating a parameter with a secret reference.
- Regional support: Adds regional samples for creating parameter and parameter versions.
Changelog
Click here to see the changelog
- go.work
- Added the
parametermanagermodule to the workspace.
- Added the
- parametermanager/README.md
- Created a README file with prerequisites and instructions for using the samples, including enabling the API, setting environment variables, and granting permissions.
- parametermanager/create_param.go
- Added a sample for creating a new parameter with the format type 'unformatted'.
- parametermanager/create_param_version.go
- Added a sample for creating a new version of a parameter with an unformatted payload.
- parametermanager/create_param_version_with_secret.go
- Added a sample for creating a new version of a parameter with a JSON payload that has a secret reference.
- parametermanager/create_structured_param.go
- Added a sample for creating a new parameter with a specified format (UNFORMATTED, YAML, JSON).
- parametermanager/create_structured_param_version.go
- Added a sample for creating a new version of a parameter with a JSON payload.
- parametermanager/doc.go
- Added package documentation for the
parametermanagerpackage.
- Added package documentation for the
- parametermanager/go.mod
- Created a go module file for the
parametermanagerpackage and added dependencies.
- Created a go module file for the
- parametermanager/go.sum
- Created a go sum file for the
parametermanagerpackage.
- Created a go sum file for the
- parametermanager/parametermanager_test.go
- Added tests for the new samples.
- parametermanager/regional_samples/create_regional_param.go
- Added a sample for creating a regional parameter with the format type 'unformatted'.
- parametermanager/regional_samples/create_regional_param_version.go
- Added a sample for creating a new version of a regional parameter with an unformatted payload.
- parametermanager/regional_samples/create_regional_param_version_with_secret.go
- Added a sample for creating a new version of a regional parameter with a JSON payload that has a secret reference.
- parametermanager/regional_samples/create_structured_regional_param.go
- Added a sample for creating a new regional parameter with a specified format (UNFORMATTED, YAML, JSON).
- parametermanager/regional_samples/create_structured_regional_param_version.go
- Added a sample for creating a new version of a regional parameter with a JSON payload.
- parametermanager/regional_samples/regional_parametermanager_test.go
- Added tests for the new regional samples.
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.
In clouds of GCP, parameters reside,
Guiding apps with versions side by side,
Secrets linked, a reference so neat,
Configuration's dance, oh so complete!
Footnotes
-
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. ↩
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.
Code Review
The pull request introduces samples for creating parameters and parameter versions using the Parameter Manager SDK. The code includes both global and regional samples, covering structured and unstructured data, as well as secret references. The samples appear well-structured and follow the documentation links provided. However, a few areas could benefit from minor improvements.
Merge Readiness
The pull request appears to be in good shape for merging, but I recommend addressing the medium severity issue before merging. I am unable to directly approve this pull request, and recommend that others review and approve this code before merging.
| // createParam creates a new parameter with the format type "unformatted" in Parameter Manager. | ||
| // | ||
| // w: The io.Writer object used to write the output. | ||
| // projectID: The ID of the project where the parameter is located. | ||
| // parameterID: The ID of the parameter to be created. | ||
| // | ||
| // The function returns an error if the parameter creation fails. |
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 comment mentions that the parameter type is "unformatted". However, the code doesn't explicitly set the format to UNFORMATTED. It might be helpful to clarify this in the comment or explicitly set the format in the code for better readability.
Consider adding a comment to the Parameter struct to indicate that the default format is UNFORMATTED if no format is specified.
Parameter: ¶metermanagerpb.Parameter{
Format: parametermanagerpb.ParameterFormat_UNFORMATTED, // Explicitly set the format to UNFORMATTED
},| // format: The format type of the parameter (UNFORMATTED, YAML, JSON). | ||
| // | ||
| // The function returns an error if the parameter creation fails. | ||
| func createStructuredParam(w io.Writer, projectID, parameterID string, format parametermanagerpb.ParameterFormat) error { |
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.
Consider adding input validation to check if the provided format is a valid parametermanagerpb.ParameterFormat. This can prevent unexpected behavior if an invalid format is passed.
| func createStructuredParam(w io.Writer, projectID, parameterID string, format parametermanagerpb.ParameterFormat) error { | |
| func createStructuredParam(w io.Writer, projectID, parameterID string, format parametermanagerpb.ParameterFormat) error { | |
| if format < parametermanagerpb.ParameterFormat_UNFORMATTED || format > parametermanagerpb.ParameterFormat_FORMAT_UNSPECIFIED { | |
| return fmt.Errorf("invalid parameter format: %v", format) | |
| } |
| // Construct the name of the create parameter version. | ||
| parent := fmt.Sprintf("projects/%s/locations/global/parameters/%s", projectID, parameterID) | ||
|
|
||
| payload := []byte(fmt.Sprintf(`{"username": "test-user","password": "__REF__(//secretmanager.googleapis.com/%s)"}`, secretID)) |
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.
Consider adding validation to check if the secretID is empty before constructing the payload. An empty secretID could lead to an invalid secret reference.
if secretID == "" {
return fmt.Errorf("secretID cannot be empty")
}
payload := []byte(fmt.Sprintf(`{"username": "test-user","password": "__REF__(//secretmanager.googleapis.com/%s)"}`, secretID))|
Is it possible to split this PR into < 500 loc as mentioned earlier by telpirion We still need approvals from GoogleCloudPlatform/go-samples-reviewers or GoogleCloudPlatform/cloud-samples-infra that's why I'm suggesting it Nevertheless the changes look good to me |
@arpangoswami Thanks for the review, I have further divided the mentioned PRs into smaller parts by separating regional samples into new PRs. So Now Each MRs contain only 5-6 files with each containing ~100 loc |
|
Please split this PR into two and (re-) open when ready. |
|
@arpangoswami, @telpirion Divided this PR in smaller PRs: #5247 , #5248 . |
Description
Created samples for creating parameter and parameter version using Parameter Manager SDK
Sample List (global):
Added required Tests for the same.
Checklist
go test -v ./..(see Testing)gofmt(see Formatting)go vet(see Formatting)GOLANG_REGIONAL_SAMPLES_LOCATIONvariable to be set