Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
57 changes: 57 additions & 0 deletions secretmanager/src/list_regional_secret_versions_with_filter.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
<?php
/*
* Copyright 2026 Google LLC.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

/*
* For instructions on how to run the full sample:
*
* @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/main/secretmanager/README.md
*/

declare(strict_types=1);

namespace Google\Cloud\Samples\SecretManager;

// [START secretmanager_list_regional_secret_versions_with_filter]
use Google\Cloud\SecretManager\V1\Client\SecretManagerServiceClient;
use Google\Cloud\SecretManager\V1\ListSecretVersionsRequest;

/**
* List secret versions in a location using a filter.
*
* @param string $projectId Your Google Cloud project id (e.g. 'my-project')
* @param string $locationId Your secret location (e.g. 'us-central1')
* @param string $secretId Secret id (e.g. 'my-secret')
* @param string $filter Filter string (see Secret Manager filtering docs)
*/
function list_regional_secret_versions_with_filter(string $projectId, string $locationId, string $secretId, string $filter): void
{
$options = ['apiEndpoint' => "secretmanager.$locationId.rep.googleapis.com"];
$client = new SecretManagerServiceClient($options);

$parent = $client->projectLocationSecretName($projectId, $locationId, $secretId);

$request = ListSecretVersionsRequest::build($parent)->setFilter($filter);

foreach ($client->listSecretVersions($request) as $version) {
printf('Found secret version %s' . PHP_EOL, $version->getName());
}
}
// [END secretmanager_list_regional_secret_versions_with_filter]

// The following 2 lines are only needed to execute the samples on the CLI
require_once __DIR__ . '/../../testing/sample_helpers.php';
\Google\Cloud\Samples\execute_sample(__FILE__, __NAMESPACE__, $argv);
56 changes: 56 additions & 0 deletions secretmanager/src/list_regional_secrets_with_filter.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
<?php
/*
* Copyright 2026 Google LLC.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

/*
* For instructions on how to run the full sample:
*
* @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/main/secretmanager/README.md
*/

declare(strict_types=1);

namespace Google\Cloud\Samples\SecretManager;

// [START secretmanager_list_regional_secrets_with_filter]
use Google\Cloud\SecretManager\V1\Client\SecretManagerServiceClient;
use Google\Cloud\SecretManager\V1\ListSecretsRequest;

/**
* List secrets in a location using a filter.
*
* @param string $projectId Your Google Cloud project id (e.g. 'my-project')
* @param string $locationId Your secret location (e.g. 'us-central1')
* @param string $filter Filter string (see Secret Manager filtering docs)
*/
function list_regional_secrets_with_filter(string $projectId, string $locationId, string $filter): void
{
$options = ['apiEndpoint' => "secretmanager.$locationId.rep.googleapis.com"];
$client = new SecretManagerServiceClient($options);

$parent = $client->locationName($projectId, $locationId);

$request = ListSecretsRequest::build($parent)->setFilter($filter);

foreach ($client->listSecrets($request) as $secret) {
printf('Found secret %s' . PHP_EOL, $secret->getName());
}
}
// [END secretmanager_list_regional_secrets_with_filter]

// The following 2 lines are only needed to execute the samples on the CLI
require_once __DIR__ . '/../../testing/sample_helpers.php';
\Google\Cloud\Samples\execute_sample(__FILE__, __NAMESPACE__, $argv);
55 changes: 55 additions & 0 deletions secretmanager/src/list_secret_versions_with_filter.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
<?php
/*
* Copyright 2026 Google LLC.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

/*
* For instructions on how to run the full sample:
*
* @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/main/secretmanager/README.md
*/

declare(strict_types=1);

namespace Google\Cloud\Samples\SecretManager;

// [START secretmanager_list_secret_versions_with_filter]
use Google\Cloud\SecretManager\V1\Client\SecretManagerServiceClient;
use Google\Cloud\SecretManager\V1\ListSecretVersionsRequest;

/**
* List secret versions for a secret using a filter.
*
* @param string $projectId Your Google Cloud project id (e.g. 'my-project')
* @param string $secretId Your secret id (e.g. 'my-secret')
* @param string $filter Filter string (see Secret Manager filtering docs)
*/
function list_secret_versions_with_filter(string $projectId, string $secretId, string $filter): void
{
$client = new SecretManagerServiceClient();

$parent = $client->secretName($projectId, $secretId);

$request = ListSecretVersionsRequest::build($parent)->setFilter($filter);

foreach ($client->listSecretVersions($request) as $version) {
printf('Found secret version %s' . PHP_EOL, $version->getName());
}
}
// [END secretmanager_list_secret_versions_with_filter]

// The following 2 lines are only needed to execute the samples on the CLI
require_once __DIR__ . '/../../testing/sample_helpers.php';
\Google\Cloud\Samples\execute_sample(__FILE__, __NAMESPACE__, $argv);
54 changes: 54 additions & 0 deletions secretmanager/src/list_secrets_with_filter.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
<?php
/*
* Copyright 2026 Google LLC.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

/*
* For instructions on how to run the full sample:
*
* @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/main/secretmanager/README.md
*/

declare(strict_types=1);

namespace Google\Cloud\Samples\SecretManager;

// [START secretmanager_list_secrets_with_filter]
use Google\Cloud\SecretManager\V1\Client\SecretManagerServiceClient;
use Google\Cloud\SecretManager\V1\ListSecretsRequest;

/**
* List secrets in a project using a filter.
*
* @param string $projectId Your Google Cloud project id (e.g. 'my-project')
* @param string $filter Filter string (see Secret Manager filtering docs)
*/
function list_secrets_with_filter(string $projectId, string $filter): void
{
$client = new SecretManagerServiceClient();

$parent = $client->projectName($projectId);

$request = ListSecretsRequest::build($parent)->setFilter($filter);

foreach ($client->listSecrets($request) as $secret) {
printf('Found secret %s' . PHP_EOL, $secret->getName());
}
}
// [END secretmanager_list_secrets_with_filter]

// The following 2 lines are only needed to execute the samples on the CLI
require_once __DIR__ . '/../../testing/sample_helpers.php';
\Google\Cloud\Samples\execute_sample(__FILE__, __NAMESPACE__, $argv);
32 changes: 32 additions & 0 deletions secretmanager/test/regionalsecretmanagerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -405,6 +405,23 @@ public function testIamRevokeAccess()
$this->assertStringContainsString('Updated IAM policy', $output);
}

public function testListSecretVersionsWithFilter()
{
$name = self::$client->parseName(self::$testSecretWithVersions->getName());

// Filter for enabled versions.
$filter = 'state = ENABLED';

$output = $this->runFunctionSnippet('list_regional_secret_versions_with_filter', [
$name['project'],
$name['location'],
$name['secret'],
$filter,
]);

$this->assertStringContainsString('Found secret version', $output);
}

public function testListSecretVersions()
{
$name = self::$client->parseName(self::$testSecretWithVersions->getName());
Expand All @@ -418,6 +435,21 @@ public function testListSecretVersions()
$this->assertStringContainsString('secret version', $output);
}

public function testListSecretsWithFilter()
{
$name = self::$client->parseName(self::$testSecret->getName());

$filter = 'name:' . $name['secret'];

$output = $this->runFunctionSnippet('list_regional_secrets_with_filter', [
$name['project'],
$name['location'],
$filter,
]);

$this->assertStringContainsString('Found secret', $output);
}

public function testListSecrets()
{
$name = self::$client->parseName(self::$testSecret->getName());
Expand Down
30 changes: 30 additions & 0 deletions secretmanager/test/secretmanagerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -414,6 +414,22 @@ public function testIamRevokeAccess()
$this->assertStringContainsString('Updated IAM policy', $output);
}

public function testListSecretVersionsWithFilter()
{
$name = self::$client->parseName(self::$testSecretWithVersions->getName());

// Filter for enabled versions.
$filter = 'state = ENABLED';

$output = $this->runFunctionSnippet('list_secret_versions_with_filter', [
$name['project'],
$name['secret'],
$filter,
]);

$this->assertStringContainsString('Found secret version', $output);
}

public function testListSecretVersions()
{
$name = self::$client->parseName(self::$testSecretWithVersions->getName());
Expand All @@ -426,6 +442,20 @@ public function testListSecretVersions()
$this->assertStringContainsString('secret version', $output);
}

public function testListSecretsWithFilter()
{
$name = self::$client->parseName(self::$testSecret->getName());

$filter = 'name:' . $name['secret'];

$output = $this->runFunctionSnippet('list_secrets_with_filter', [
$name['project'],
$filter,
]);

$this->assertStringContainsString('Found secret', $output);
}

public function testListSecrets()
{
$name = self::$client->parseName(self::$testSecret->getName());
Expand Down