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
67 changes: 67 additions & 0 deletions secretmanager/src/delete_regional_secret_using_etag.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
<?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_delete_regional_secret_using_etag]
use Google\Cloud\SecretManager\V1\Client\SecretManagerServiceClient;
use Google\Cloud\SecretManager\V1\GetSecretRequest;
use Google\Cloud\SecretManager\V1\DeleteSecretRequest;

/**
* Delete a regional secret using a stored etag (optimistic concurrency).
*
* @param string $projectId Your Google Cloud Project ID (e.g. 'my-project')
* @param string $locationId Secret location (e.g. 'us-central1')
* @param string $secretId Your secret ID (e.g. 'my-secret')
*/
function delete_regional_secret_using_etag(string $projectId, string $locationId, string $secretId): void
{
$options = ['apiEndpoint' => "secretmanager.$locationId.rep.googleapis.com"];
$client = new SecretManagerServiceClient($options);

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

// Get the current secret to read the etag.
$getRequest = GetSecretRequest::build($name);
$current = $client->getSecret($getRequest);

$etag = $current->getEtag();

// Build the delete request with the etag.
$deleteRequest = (new DeleteSecretRequest())
->setName($name)
->setEtag($etag);

// Delete the secret.
$client->deleteSecret($deleteRequest);

printf('Deleted secret %s' . PHP_EOL, $secretId);
}
// [END secretmanager_delete_regional_secret_using_etag]

// 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);
65 changes: 65 additions & 0 deletions secretmanager/src/delete_secret_using_etag.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
<?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_delete_secret_using_etag]
use Google\Cloud\SecretManager\V1\Client\SecretManagerServiceClient;
use Google\Cloud\SecretManager\V1\GetSecretRequest;
use Google\Cloud\SecretManager\V1\DeleteSecretRequest;

/**
* Delete a secret using a stored etag (optimistic concurrency).
*
* @param string $projectId Your Google Cloud Project ID (e.g. 'my-project')
* @param string $secretId Your secret ID (e.g. 'my-secret')
*/
function delete_secret_using_etag(string $projectId, string $secretId): void
{
$client = new SecretManagerServiceClient();

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

// Get the current secret to read the etag.
$getRequest = GetSecretRequest::build($name);
$current = $client->getSecret($getRequest);

$etag = $current->getEtag();

// Build the delete request with the etag.
$deleteRequest = (new DeleteSecretRequest())
->setName($name)
->setEtag($etag);

// Delete the secret.
$client->deleteSecret($deleteRequest);

printf('Deleted secret %s' . PHP_EOL, $secretId);
}
// [END secretmanager_delete_secret_using_etag]

// 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);
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
<?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_destroy_regional_secret_version_using_etag]
use Google\Cloud\SecretManager\V1\Client\SecretManagerServiceClient;
use Google\Cloud\SecretManager\V1\GetSecretVersionRequest;
use Google\Cloud\SecretManager\V1\DestroySecretVersionRequest;

/**
* Destroy a regional secret version using a stored etag.
*
* @param string $projectId Your Google Cloud Project ID (e.g. 'my-project')
* @param string $locationId Secret location (e.g. 'us-central1')
* @param string $secretId Your secret ID (e.g. 'my-secret')
* @param string $versionId Your version ID (e.g. 'latest' or '5')
*/
function destroy_regional_secret_version_using_etag(string $projectId, string $locationId, string $secretId, string $versionId): void
{
$options = ['apiEndpoint' => "secretmanager.$locationId.rep.googleapis.com"];
$client = new SecretManagerServiceClient($options);

$name = $client->projectLocationSecretSecretVersionName($projectId, $locationId, $secretId, $versionId);

// Read current etag for the version.
$getRequest = GetSecretVersionRequest::build($name);
$current = $client->getSecretVersion($getRequest);
$etag = $current->getEtag();

$request = DestroySecretVersionRequest::build($name)->setEtag($etag);

$response = $client->destroySecretVersion($request);

printf('Destroyed secret version: %s' . PHP_EOL, $response->getName());
}
// [END secretmanager_destroy_regional_secret_version_using_etag]

// 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);
61 changes: 61 additions & 0 deletions secretmanager/src/destroy_secret_version_using_etag.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
<?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_destroy_secret_version_using_etag]
use Google\Cloud\SecretManager\V1\Client\SecretManagerServiceClient;
use Google\Cloud\SecretManager\V1\GetSecretVersionRequest;
use Google\Cloud\SecretManager\V1\DestroySecretVersionRequest;

/**
* Destroy a secret version using a stored etag.
*
* @param string $projectId Your Google Cloud Project ID (e.g. 'my-project')
* @param string $secretId Your secret ID (e.g. 'my-secret')
* @param string $versionId Your version ID (e.g. 'latest' or '5')
*/
function destroy_secret_version_using_etag(string $projectId, string $secretId, string $versionId): void
{
$client = new SecretManagerServiceClient();

$name = $client->secretVersionName($projectId, $secretId, $versionId);

// Read current etag for the version.
$getRequest = GetSecretVersionRequest::build($name);
$current = $client->getSecretVersion($getRequest);
$etag = $current->getEtag();

$request = DestroySecretVersionRequest::build($name)->setEtag($etag);

$response = $client->destroySecretVersion($request);

printf('Destroyed secret version: %s' . PHP_EOL, $response->getName());
}
// [END secretmanager_destroy_secret_version_using_etag]

// 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);
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
<?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_disable_regional_secret_version_using_etag]
use Google\Cloud\SecretManager\V1\Client\SecretManagerServiceClient;
use Google\Cloud\SecretManager\V1\GetSecretVersionRequest;
use Google\Cloud\SecretManager\V1\DisableSecretVersionRequest;

/**
* Disable a regional secret version using a stored etag.
*
* @param string $projectId Your Google Cloud Project ID (e.g. 'my-project')
* @param string $locationId Secret location (e.g. 'us-central1')
* @param string $secretId Your secret ID (e.g. 'my-secret')
* @param string $versionId Your version ID (e.g. 'latest' or '5')
*/
function disable_regional_secret_version_using_etag(string $projectId, string $locationId, string $secretId, string $versionId): void
{
$options = ['apiEndpoint' => "secretmanager.$locationId.rep.googleapis.com"];
$client = new SecretManagerServiceClient($options);

$name = $client->projectLocationSecretSecretVersionName($projectId, $locationId, $secretId, $versionId);

// Read current etag for the version.
$getRequest = GetSecretVersionRequest::build($name);
$current = $client->getSecretVersion($getRequest);
$etag = $current->getEtag();

$request = DisableSecretVersionRequest::build($name)->setEtag($etag);

$response = $client->disableSecretVersion($request);

printf('Disabled secret version: %s' . PHP_EOL, $response->getName());
}
// [END secretmanager_disable_regional_secret_version_using_etag]

// 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);
61 changes: 61 additions & 0 deletions secretmanager/src/disable_secret_version_using_etag.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
<?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_disable_secret_version_using_etag]
use Google\Cloud\SecretManager\V1\Client\SecretManagerServiceClient;
use Google\Cloud\SecretManager\V1\GetSecretVersionRequest;
use Google\Cloud\SecretManager\V1\DisableSecretVersionRequest;

/**
* Disable a secret version using a stored etag.
*
* @param string $projectId Your Google Cloud Project ID (e.g. 'my-project')
* @param string $secretId Your secret ID (e.g. 'my-secret')
* @param string $versionId Your version ID (e.g. 'latest' or '5')
*/
function disable_secret_version_using_etag(string $projectId, string $secretId, string $versionId): void
{
$client = new SecretManagerServiceClient();

$name = $client->secretVersionName($projectId, $secretId, $versionId);

// Read current etag for the version.
$getRequest = GetSecretVersionRequest::build($name);
$current = $client->getSecretVersion($getRequest);
$etag = $current->getEtag();

$request = DisableSecretVersionRequest::build($name)->setEtag($etag);

$response = $client->disableSecretVersion($request);

printf('Disabled secret version: %s' . PHP_EOL, $response->getName());
}
// [END secretmanager_disable_secret_version_using_etag]

// 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);
Loading