Skip to content

feat(parametermanager): add templates, tags and checksum samples - #2337

Open
suvidha-malaviya wants to merge 1 commit into
GoogleCloudPlatform:mainfrom
suvidha-malaviya:feat/parametermanager-templates-tags-checksum-php
Open

suvidha-malaviya wants to merge 1 commit into
GoogleCloudPlatform:mainfrom
suvidha-malaviya:feat/parametermanager-templates-tags-checksum-php

Conversation

@suvidha-malaviya

Copy link
Copy Markdown
Contributor

Templates (global and regional):

  • create_param_template / create_regional_param_template: creates a template in YAML or JSON format
  • create_param_template_version / create_regional_param_template_version: creates a template version with {{.variableName}} placeholders
  • list_param_templates / list_regional_param_templates: lists the templates
  • get_param_template / get_regional_param_template: gets a template
  • list_param_template_versions / list_regional_param_template_versions: lists the versions of a template
  • get_param_template_version / get_regional_param_template_version: gets a template version
  • update_param_template_labels / update_regional_param_template_labels: adds or updates a label on a template
  • disable_param_template_version / enable_param_template_version (and the regional variants): disables or enables a template version
  • delete_param_template_version / delete_param_template (and the regional variants): deletes a template version or a template
  • render_param_template_version / render_regional_param_template_version: renders a template version using the values of a parameter version
  • template_quickstart / regional_template_quickstart: creates a template, a template version, a parameter and a parameter version, then renders the template version

Tags (global and regional):

  • create_param_with_tags / create_regional_param_with_tags: creates a parameter with a tag (create-only)
  • bind_tags_to_param / bind_tags_to_regional_param: creates a parameter, then binds an existing tag value to it through Resource Manager
  • get_param_tags / get_regional_param_tags: gets the tag bindings of a parameter

Checksum (global and regional):

  • create_param_version_with_checksum / create_regional_param_version_with_checksum: creates a parameter version with a client-computed CRC32C checksum
  • get_param_version_verify_checksum / get_regional_param_version_verify_checksum: gets a parameter version and verifies its payload checksum

Bumps google/cloud-parametermanager to ^0.7.0 (the version with templates, tags and checksum support) and adds google/cloud-resource-manager ^1.2 for tag bindings.

Additional test-project requirements:

  • Resource Manager API enabled (cloudresourcemanager.googleapis.com), in addition to Parameter Manager
  • A pre-provisioned tag key and tag value, referenced via the PARAMETER_MANAGER_TAG_KEY / PARAMETER_MANAGER_TAG_VALUE env vars (for example tagKeys/1234567890 and tagValues/1234567890). The tag tests are skipped when these are unset.
  • The identity running the tests needs Tag User on the tag value, in addition to the Parameter Manager permissions already required

Add global and regional samples for Parameter Manager templates, tags and checksum, with tests. Bump google/cloud-parametermanager to ^0.7.0 and add google/cloud-resource-manager for tag bindings.
@product-auto-label product-auto-label Bot added api: parametermanager samples Issues that are directly related to samples. labels Oct 14, 2026

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

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Code Review

This pull request introduces comprehensive PHP code samples and integration tests for Google Cloud Parameter Manager, covering both global and regional operations for parameters, templates, template versions, tag bindings, and checksum verification. The code review feedback is highly constructive, highlighting several opportunities for defensive programming. Specifically, the reviewer recommends adding null checks before calling getData() on payloads to prevent potential fatal errors, and converting format strings to uppercase to ensure robust enum value lookups.

Comment on lines +58 to +61
$payload = $parameterVersion->getPayload();
if (hexdec(hash('crc32c', $payload->getData())) !== $payload->getDataCrc32C()) {
throw new \UnexpectedValueException(sprintf('Checksum mismatch for %s: data corrupted', $parameterVersion->getName()));
}

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

medium

Defensive programming: The $payload variable can be null if the payload is not set or not returned. Accessing getData() on a null reference will cause a fatal error. A null check should be added before verifying the checksum.

    $payload = $parameterVersion->getPayload();
    if ($payload === null) {
        throw new \UnexpectedValueException(sprintf('No payload found for %s', $parameterVersion->getName()));
    }
    if (hexdec(hash('crc32c', $payload->getData())) !== $payload->getDataCrc32C()) {
        throw new \UnexpectedValueException(sprintf('Checksum mismatch for %s: data corrupted', $parameterVersion->getName()));
    }

Comment on lines +59 to +62
$parameterVersion = $client->getParameterVersion($request);

// Verify the payload checksum.
$payload = $parameterVersion->getPayload();

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

medium

Defensive programming: The $payload variable can be null if the payload is not set or not returned. Accessing getData() on a null reference will cause a fatal error. A null check should be added before verifying the checksum.

    $payload = $parameterVersion->getPayload();
    if ($payload === null) {
        throw new \UnexpectedValueException(sprintf('No payload found for %s', $parameterVersion->getName()));
    }
    if (hexdec(hash('crc32c', $payload->getData())) !== $payload->getDataCrc32C()) {
        throw new \UnexpectedValueException(sprintf('Checksum mismatch for %s: data corrupted', $parameterVersion->getName()));
    }

Comment on lines +55 to +56
printf('Got template version %s' . PHP_EOL, $templateVersion->getName());
printf('Payload: %s' . PHP_EOL, $templateVersion->getPayload()->getData());

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

medium

Defensive programming: The $templateVersion->getPayload() call can return null if the payload is not set. Accessing getData() on a null reference will cause a fatal error. A null check should be added before accessing the payload data.

    printf('Got template version %s' . PHP_EOL, $templateVersion->getName());
    $payload = $templateVersion->getPayload();
    printf('Payload: %s' . PHP_EOL, $payload ? $payload->getData() : '');

Comment on lines +59 to +60
printf('Got regional template version %s' . PHP_EOL, $templateVersion->getName());
printf('Payload: %s' . PHP_EOL, $templateVersion->getPayload()->getData());

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

medium

Defensive programming: The $templateVersion->getPayload() call can return null if the payload is not set. Accessing getData() on a null reference will cause a fatal error. A null check should be added before accessing the payload data.

    printf('Got regional template version %s' . PHP_EOL, $templateVersion->getName());
    $payload = $templateVersion->getPayload();
    printf('Payload: %s' . PHP_EOL, $payload ? $payload->getData() : '');

Comment on lines +61 to +62
printf('Template payload: %s' . PHP_EOL, $response->getPayload()->getData());
printf('Rendered payload: %s' . PHP_EOL, $response->getRenderedPayload());

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

medium

Defensive programming: The $response->getPayload() call can return null if the payload is not set. Accessing getData() on a null reference will cause a fatal error. A null check should be added before accessing the payload data.

    $payload = $response->getPayload();
    printf('Template payload: %s' . PHP_EOL, $payload ? $payload->getData() : '');
    printf('Rendered payload: %s' . PHP_EOL, $response->getRenderedPayload());

Comment on lines +65 to +66
printf('Template payload: %s' . PHP_EOL, $response->getPayload()->getData());
printf('Rendered payload: %s' . PHP_EOL, $response->getRenderedPayload());

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

medium

Defensive programming: The $response->getPayload() call can return null if the payload is not set. Accessing getData() on a null reference will cause a fatal error. A null check should be added before accessing the payload data.

    $payload = $response->getPayload();
    printf('Template payload: %s' . PHP_EOL, $payload ? $payload->getData() : '');
    printf('Rendered payload: %s' . PHP_EOL, $response->getRenderedPayload());

Comment on lines +50 to +51
$template = (new Template())
->setFormat(TemplateFormat::value('TEMPLATE_FORMAT_' . $format));

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

medium

Robustness: If $format is passed in lowercase or mixed case (e.g., 'json'), TemplateFormat::value() will return null or throw an exception because the enum values are uppercase. Converting $format to uppercase ensures the function is robust against different input casings.

    $template = (new Template())
        ->setFormat(TemplateFormat::value('TEMPLATE_FORMAT_' . strtoupper($format)));

Comment on lines +54 to +55
$template = (new Template())
->setFormat(TemplateFormat::value('TEMPLATE_FORMAT_' . $format));

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

medium

Robustness: If $format is passed in lowercase or mixed case (e.g., 'json'), TemplateFormat::value() will return null or throw an exception because the enum values are uppercase. Converting $format to uppercase ensures the function is robust against different input casings.

    $template = (new Template())
        ->setFormat(TemplateFormat::value('TEMPLATE_FORMAT_' . strtoupper($format)));

@suvidha-malaviya
suvidha-malaviya marked this pull request as ready for review October 14, 2026 12:13
@suvidha-malaviya
suvidha-malaviya requested review from a team as code owners October 14, 2026 12:13
@snippet-bot

snippet-bot Bot commented Oct 14, 2026

Copy link
Copy Markdown

Here is the summary of changes.

You are about to add 36 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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

api: parametermanager samples Issues that are directly related to samples.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants