Skip to content

Commit 471a7b4

Browse files
authored
chore: upgrade secretmanager samples to new client surface (#1946)
1 parent 9307fcb commit 471a7b4

6 files changed

Lines changed: 47 additions & 21 deletions

File tree

dialogflow/composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"require": {
3-
"google/cloud-dialogflow": "^1.10",
3+
"google/cloud-dialogflow": "^1.11",
44
"symfony/console": "^5.0"
55
},
66
"autoload": {

recaptcha/composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
22
"require": {
3-
"google/cloud-recaptcha-enterprise": "^1.7"
3+
"google/cloud-recaptcha-enterprise": "^1.8"
44
}
55
}

secretmanager/composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
22
"require": {
3-
"google/cloud-secret-manager": "^1.0.0"
3+
"google/cloud-secret-manager": "^1.13"
44
}
55
}

secretmanager/quickstart.php

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -26,10 +26,13 @@
2626

2727
// [START secretmanager_quickstart]
2828
// Import the Secret Manager client library.
29+
use Google\Cloud\SecretManager\V1\AccessSecretVersionRequest;
30+
use Google\Cloud\SecretManager\V1\AddSecretVersionRequest;
31+
use Google\Cloud\SecretManager\V1\Client\SecretManagerServiceClient;
32+
use Google\Cloud\SecretManager\V1\CreateSecretRequest;
2933
use Google\Cloud\SecretManager\V1\Replication;
3034
use Google\Cloud\SecretManager\V1\Replication\Automatic;
3135
use Google\Cloud\SecretManager\V1\Secret;
32-
use Google\Cloud\SecretManager\V1\SecretManagerServiceClient;
3336
use Google\Cloud\SecretManager\V1\SecretPayload;
3437

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

4548
// Create the parent secret.
46-
$secret = $client->createSecret($parent, $secretId,
47-
new Secret([
49+
$createSecretRequest = (new CreateSecretRequest())
50+
->setParent($parent)
51+
->setSecretId($secretId)
52+
->setSecret(new Secret([
4853
'replication' => new Replication([
4954
'automatic' => new Automatic(),
5055
]),
51-
])
52-
);
56+
]));
57+
$secret = $client->createSecret($createSecretRequest);
5358

5459
// Add the secret version.
55-
$version = $client->addSecretVersion($secret->getName(), new SecretPayload([
60+
$addSecretVersionRequest = (new AddSecretVersionRequest())
61+
->setParent($secret->getName())
62+
->setPayload(new SecretPayload([
5663
'data' => 'hello world',
5764
]));
65+
$version = $client->addSecretVersion($addSecretVersionRequest);
5866

5967
// Access the secret version.
60-
$response = $client->accessSecretVersion($version->getName());
68+
$accessSecretVersionRequest = (new AccessSecretVersionRequest())
69+
->setName($version->getName());
70+
$response = $client->accessSecretVersion($accessSecretVersionRequest);
6171

6272
// Print the secret payload.
6373
//

secretmanager/test/quickstartTest.php

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,8 @@
1818
declare(strict_types=1);
1919

2020
use Google\ApiCore\ApiException as GaxApiException;
21-
use Google\Cloud\SecretManager\V1\SecretManagerServiceClient;
21+
use Google\Cloud\SecretManager\V1\Client\SecretManagerServiceClient;
22+
use Google\Cloud\SecretManager\V1\DeleteSecretRequest;
2223
use Google\Cloud\TestUtils\TestTrait;
2324
use PHPUnit\Framework\TestCase;
2425

@@ -39,7 +40,9 @@ public static function tearDownAfterClass(): void
3940
$name = $client->secretName(self::$projectId, self::$secretId);
4041

4142
try {
42-
$client->deleteSecret($name);
43+
$deleteSecretRequest = (new DeleteSecretRequest())
44+
->setName($name);
45+
$client->deleteSecret($deleteSecretRequest);
4346
} catch (GaxApiException $e) {
4447
if ($e->getStatus() != 'NOT_FOUND') {
4548
throw $e;

secretmanager/test/secretmanagerTest.php

Lines changed: 22 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,14 @@
2020
namespace Google\Cloud\Samples\SecretManager;
2121

2222
use Google\ApiCore\ApiException as GaxApiException;
23+
use Google\Cloud\SecretManager\V1\AddSecretVersionRequest;
24+
use Google\Cloud\SecretManager\V1\Client\SecretManagerServiceClient;
25+
use Google\Cloud\SecretManager\V1\CreateSecretRequest;
26+
use Google\Cloud\SecretManager\V1\DeleteSecretRequest;
27+
use Google\Cloud\SecretManager\V1\DisableSecretVersionRequest;
2328
use Google\Cloud\SecretManager\V1\Replication;
2429
use Google\Cloud\SecretManager\V1\Replication\Automatic;
2530
use Google\Cloud\SecretManager\V1\Secret;
26-
use Google\Cloud\SecretManager\V1\SecretManagerServiceClient;
2731
use Google\Cloud\SecretManager\V1\SecretPayload;
2832
use Google\Cloud\SecretManager\V1\SecretVersion;
2933
use Google\Cloud\TestUtils\TestTrait;
@@ -81,32 +85,41 @@ private static function createSecret(): Secret
8185
{
8286
$parent = self::$client->projectName(self::$projectId);
8387
$secretId = self::randomSecretId();
84-
85-
return self::$client->createSecret($parent, $secretId,
86-
new Secret([
88+
$createSecretRequest = (new CreateSecretRequest())
89+
->setParent($parent)
90+
->setSecretId($secretId)
91+
->setSecret(new Secret([
8792
'replication' => new Replication([
8893
'automatic' => new Automatic(),
8994
]),
90-
])
91-
);
95+
]));
96+
97+
return self::$client->createSecret($createSecretRequest);
9298
}
9399

94100
private static function addSecretVersion(Secret $secret): SecretVersion
95101
{
96-
return self::$client->addSecretVersion($secret->getName(), new SecretPayload([
102+
$addSecretVersionRequest = (new AddSecretVersionRequest())
103+
->setParent($secret->getName())
104+
->setPayload(new SecretPayload([
97105
'data' => 'my super secret data',
98106
]));
107+
return self::$client->addSecretVersion($addSecretVersionRequest);
99108
}
100109

101110
private static function disableSecretVersion(SecretVersion $version): SecretVersion
102111
{
103-
return self::$client->disableSecretVersion($version->getName());
112+
$disableSecretVersionRequest = (new DisableSecretVersionRequest())
113+
->setName($version->getName());
114+
return self::$client->disableSecretVersion($disableSecretVersionRequest);
104115
}
105116

106117
private static function deleteSecret(string $name)
107118
{
108119
try {
109-
self::$client->deleteSecret($name);
120+
$deleteSecretRequest = (new DeleteSecretRequest())
121+
->setName($name);
122+
self::$client->deleteSecret($deleteSecretRequest);
110123
} catch (GaxApiException $e) {
111124
if ($e->getStatus() != 'NOT_FOUND') {
112125
throw $e;

0 commit comments

Comments
 (0)