Repository navigation
feat(parametermanager): add templates, tags and checksum samples - #14629
suvidha-malaviya wants to merge 6 commits into
Conversation
Add global and regional Python samples and tests for Parameter Manager templates (create, get, list, update labels, enable/disable, delete, render, quickstart), creating a parameter with tags, and CRC32C checksum create/verify. Bump google-cloud-parametermanager to 0.4.3.
There was a problem hiding this comment.
Code Review
This pull request introduces a comprehensive set of Python snippets and integration tests for Google Cloud Parameter Manager templates, covering both global and regional resource management. The feedback highlights critical runtime bugs in the template rendering snippets and tests where non-existent attributes (payload and parameter_version) are accessed on the RenderTemplateVersionResponse object. Additionally, it suggests optimizing the template label update snippets by removing redundant get_template API calls, as update_template already returns the updated resource.
| # Print the template payload and the rendered payload. | ||
| print(f"Template payload: {response.payload.data.decode('utf-8')}") | ||
| print(f"Rendered payload: {response.rendered_payload.decode('utf-8')}") |
There was a problem hiding this comment.
The RenderTemplateVersionResponse object returned by render_template_version only contains the rendered_payload field. It does not contain a payload attribute, so attempting to access response.payload will raise an AttributeError at runtime. We should remove the print statement for the template payload.
| # Print the template payload and the rendered payload. | |
| print(f"Template payload: {response.payload.data.decode('utf-8')}") | |
| print(f"Rendered payload: {response.rendered_payload.decode('utf-8')}") | |
| # Print the rendered payload. | |
| print(f"Rendered payload: {response.rendered_payload.decode('utf-8')}") |
There was a problem hiding this comment.
We have payload field in RenderTemplateVersionResponse
| # Print the template payload and the rendered payload. | ||
| print(f"Template payload: {response.payload.data.decode('utf-8')}") | ||
| print(f"Rendered regional payload: {response.rendered_payload.decode('utf-8')}") |
There was a problem hiding this comment.
The RenderTemplateVersionResponse object returned by render_template_version only contains the rendered_payload field. It does not contain a payload attribute, so attempting to access response.payload will raise an AttributeError at runtime. We should remove the print statement for the template payload.
| # Print the template payload and the rendered payload. | |
| print(f"Template payload: {response.payload.data.decode('utf-8')}") | |
| print(f"Rendered regional payload: {response.rendered_payload.decode('utf-8')}") | |
| # Print the rendered payload. | |
| print(f"Rendered regional payload: {response.rendered_payload.decode('utf-8')}") |
| assert response.payload.data == payload | ||
| assert param_id in response.parameter_version | ||
| assert json.loads(response.rendered_payload.decode("utf-8")) == values |
There was a problem hiding this comment.
The RenderTemplateVersionResponse object returned by render_param_template_version only contains the rendered_payload field. It does not contain payload or parameter_version attributes, so these assertions will raise an AttributeError at runtime. We should remove them and only assert on the rendered_payload.
| assert response.payload.data == payload | |
| assert param_id in response.parameter_version | |
| assert json.loads(response.rendered_payload.decode("utf-8")) == values | |
| assert json.loads(response.rendered_payload.decode("utf-8")) == values |
| assert response.payload.data == payload | ||
| assert param_id in response.parameter_version | ||
| assert json.loads(response.rendered_payload.decode("utf-8")) == values |
There was a problem hiding this comment.
The RenderTemplateVersionResponse object returned by render_regional_param_template_version only contains the rendered_payload field. It does not contain payload or parameter_version attributes, so these assertions will raise an AttributeError at runtime. We should remove them and only assert on the rendered_payload.
| assert response.payload.data == payload | |
| assert param_id in response.parameter_version | |
| assert json.loads(response.rendered_payload.decode("utf-8")) == values | |
| assert json.loads(response.rendered_payload.decode("utf-8")) == values |
| client.update_template(request=request) | ||
|
|
||
| # The update response does not include the labels, so get the template | ||
| # again to read the stored labels. | ||
| response = client.get_template(request={"name": name}) |
There was a problem hiding this comment.
The update_template method already returns the updated Template object, including its labels. There is no need to make an extra get_template API call to retrieve the updated labels, which saves a network round-trip.
| client.update_template(request=request) | |
| # The update response does not include the labels, so get the template | |
| # again to read the stored labels. | |
| response = client.get_template(request={"name": name}) | |
| response = client.update_template(request=request) |
| client.update_template(request=request) | ||
|
|
||
| # The update response does not include the labels, so get the template | ||
| # again to read the stored labels. | ||
| response = client.get_template(request={"name": name}) |
There was a problem hiding this comment.
The update_template method already returns the updated Template object, including its labels. There is no need to make an extra get_template API call to retrieve the updated labels, which saves a network round-trip.
| client.update_template(request=request) | |
| # The update response does not include the labels, so get the template | |
| # again to read the stored labels. | |
| response = client.get_template(request={"name": name}) | |
| response = client.update_template(request=request) |
Add global and regional samples that bind a tag value to a parameter through Resource Manager and read the tags of a parameter as tag bindings, with tests.
31fd7ae to
12b5773
Compare
19a741f to
654a76e
Compare
Description
Adds Python samples and tests for Parameter Manager templates, tags and checksums, for both global and regional parameters.
Parameter.tagsis input-only and is not returned by Parameter Manager)Bumps google-cloud-parametermanager to 0.4.3, adds google-crc32c, and updates the test requirements (protobuf 6 compatible secret-manager/kms, plus resource-manager for tag binding checks).
Checklist
nox -s py-3.10(see Test Environment Setup)nox -s lint(see Test Environment Setup)-
PARAMETER_MANAGER_TAG_KEY/PARAMETER_MANAGER_TAG_VALUE— an existing Resource Manager tag key and value (tagKeys/<id>,tagValues/<id>). The tag tests are skipped if they are unset.- The test identity needs permission to attach that tag value (e.g.
roles/resourcemanager.tagUser).