Skip to content

Commit

Permalink
chore: update secretmanager quickstart
Browse files Browse the repository at this point in the history
  • Loading branch information
bshaffer committed Dec 27, 2023
1 parent 107e20b commit 7d93a3d
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 8 deletions.
2 changes: 1 addition & 1 deletion secretmanager/composer.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"require": {
"google/cloud-secret-manager": "^1.12.2"
"google/cloud-secret-manager": "^1.12"
}
}
24 changes: 17 additions & 7 deletions secretmanager/quickstart.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,13 @@

// [START secretmanager_quickstart]
// Import the Secret Manager client library.
use Google\Cloud\SecretManager\V1\AccessSecretVersionRequest;
use Google\Cloud\SecretManager\V1\AddSecretVersionRequest;
use Google\Cloud\SecretManager\V1\Client\SecretManagerServiceClient;
use Google\Cloud\SecretManager\V1\CreateSecretRequest;
use Google\Cloud\SecretManager\V1\Replication;
use Google\Cloud\SecretManager\V1\Replication\Automatic;
use Google\Cloud\SecretManager\V1\Secret;
use Google\Cloud\SecretManager\V1\SecretManagerServiceClient;
use Google\Cloud\SecretManager\V1\SecretPayload;

/** Uncomment and populate these variables in your code */
Expand All @@ -43,21 +46,28 @@
$parent = $client->projectName($projectId);

// Create the parent secret.
$secret = $client->createSecret($parent, $secretId,
new Secret([
$createSecretRequest = (new CreateSecretRequest())
->setParent($parent)
->setSecretId($secretId)
->setSecret(new Secret([
'replication' => new Replication([
'automatic' => new Automatic(),
]),
])
);
]));
$secret = $client->createSecret($createSecretRequest);

// Add the secret version.
$version = $client->addSecretVersion($secret->getName(), new SecretPayload([
$addSecretVersionRequest = (new AddSecretVersionRequest())
->setParent($secret->getName())
->setPayload(new SecretPayload([
'data' => 'hello world',
]));
$version = $client->addSecretVersion($addSecretVersionRequest);

// Access the secret version.
$response = $client->accessSecretVersion($version->getName());
$accessSecretVersionRequest = (new AccessSecretVersionRequest())
->setName($version->getName());
$response = $client->accessSecretVersion($accessSecretVersionRequest);

// Print the secret payload.
//
Expand Down

0 comments on commit 7d93a3d

Please sign in to comment.