Skip to content

Conversation

@vatsal-vora-crestdata
Copy link
Contributor

@vatsal-vora-crestdata vatsal-vora-crestdata commented Mar 19, 2025

Description

Created samples for creating parameter and parameter version using Parameter Manager SDK

Sample List (global):

  1. parameter-structured-data
  2. parameter-unstructured-data
  3. add-parameter-version (structured, unstructured)
  4. create-parameter-secret-reference

Added required Tests for the same.

Checklist

  • I have followed Contributing Guidelines from CONTRIBUTING.MD
  • Tests pass: go test -v ./.. (see Testing)
  • Code formatted: gofmt (see Formatting)
  • Vetting pass: go vet (see Formatting)
  • These samples need a new API enabled in testing projects to pass (let us know which ones) - This requires Parameter manager API to be enabled
  • These samples need a new/updated env vars in testing projects set to pass (let us know which ones) - For testing regional samples it requires GOLANG_REGIONAL_SAMPLES_LOCATION variable to be set
  • This sample adds a new sample directory, and I updated the CODEOWNERS file with the codeowners 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

@vatsal-vora-crestdata vatsal-vora-crestdata requested review from a team as code owners March 19, 2025 09:47
@snippet-bot
Copy link

snippet-bot bot commented Mar 19, 2025

Here is the summary of changes.

You are about to add 5 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 Mar 19, 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 @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 parametermanager module to the workspace.
  • 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 parametermanager package.
  • parametermanager/go.mod
    • Created a go module file for the parametermanager package and added dependencies.
  • parametermanager/go.sum
    • Created a go sum file for the parametermanager package.
  • 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

  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 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.

Comment on lines +27 to +33
// 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.
Copy link
Contributor

Choose a reason for hiding this comment

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

medium

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:   &parametermanagerpb.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 {
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 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.

Suggested change
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))
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 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))

@arpangoswami
Copy link
Contributor

Is it possible to split this PR into < 500 loc as mentioned earlier by telpirion
Same goes for PR 5227, 5228 and 5229

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

@vatsal-vora-crestdata
Copy link
Contributor Author

vatsal-vora-crestdata commented Mar 20, 2025

Is it possible to split this PR into < 500 loc as mentioned earlier by telpirion Same goes for PR 5227, 5228 and 5229

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

Created #5234, #5233 and #5232 for the regional samples.

@telpirion
Copy link
Collaborator

Please split this PR into two and (re-) open when ready.

@telpirion telpirion marked this pull request as draft March 24, 2025 18:17
@arpangoswami arpangoswami added kokoro:force-run Add this label to force Kokoro to re-run the tests. kokoro:run Add this label to force Kokoro to re-run the tests. labels Apr 3, 2025
@kokoro-team kokoro-team removed kokoro:run Add this label to force Kokoro to re-run the tests. kokoro:force-run Add this label to force Kokoro to re-run the tests. labels Apr 3, 2025
@vatsal-vora-crestdata
Copy link
Contributor Author

@arpangoswami, @telpirion Divided this PR in smaller PRs: #5247 , #5248 .

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.

4 participants