Skip to content

Commit 6d1cbe1

Browse files
authored
chore: upgrade spanner samples to new client surface (#1952)
1 parent 1ec5c14 commit 6d1cbe1

3 files changed

Lines changed: 16 additions & 6 deletions

File tree

spanner/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-spanner": "^1.62.1"
3+
"google/cloud-spanner": "^1.68"
44
}
55
}

spanner/src/enable_fine_grained_access.php

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,11 @@
2424
namespace Google\Cloud\Samples\Spanner;
2525

2626
// [START spanner_enable_fine_grained_access]
27-
use Google\Cloud\Spanner\Admin\Database\V1\DatabaseAdminClient;
2827
use \Google\Cloud\Iam\V1\Binding;
2928
use \Google\Type\Expr;
29+
use Google\Cloud\Iam\V1\GetIamPolicyRequest;
30+
use Google\Cloud\Iam\V1\SetIamPolicyRequest;
31+
use Google\Cloud\Spanner\Admin\Database\V1\Client\DatabaseAdminClient;
3032

3133
/**
3234
* Enable Fine Grained Access.
@@ -54,7 +56,9 @@ function enable_fine_grained_access(
5456
): void {
5557
$adminClient = new DatabaseAdminClient();
5658
$resource = sprintf('projects/%s/instances/%s/databases/%s', $projectId, $instanceId, $databaseId);
57-
$policy = $adminClient->getIamPolicy($resource);
59+
$getIamPolicyRequest = (new GetIamPolicyRequest())
60+
->setResource($resource);
61+
$policy = $adminClient->getIamPolicy($getIamPolicyRequest);
5862

5963
// IAM conditions need at least version 3
6064
if ($policy->getVersion() != 3) {
@@ -70,7 +74,10 @@ function enable_fine_grained_access(
7074
])
7175
]);
7276
$policy->setBindings([$binding]);
73-
$adminClient->setIamPolicy($resource, $policy);
77+
$setIamPolicyRequest = (new SetIamPolicyRequest())
78+
->setResource($resource)
79+
->setPolicy($policy);
80+
$adminClient->setIamPolicy($setIamPolicyRequest);
7481

7582
printf('Enabled fine-grained access in IAM' . PHP_EOL);
7683
}

spanner/src/list_database_roles.php

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,8 @@
2424
namespace Google\Cloud\Samples\Spanner;
2525

2626
// [START spanner_list_database_roles]
27-
use Google\Cloud\Spanner\Admin\Database\V1\DatabaseAdminClient;
27+
use Google\Cloud\Spanner\Admin\Database\V1\Client\DatabaseAdminClient;
28+
use Google\Cloud\Spanner\Admin\Database\V1\ListDatabaseRolesRequest;
2829

2930
/**
3031
* List Database roles in the given database.
@@ -44,8 +45,10 @@ function list_database_roles(
4445
): void {
4546
$adminClient = new DatabaseAdminClient();
4647
$resource = sprintf('projects/%s/instances/%s/databases/%s', $projectId, $instanceId, $databaseId);
48+
$listDatabaseRolesRequest = (new ListDatabaseRolesRequest())
49+
->setParent($resource);
4750

48-
$roles = $adminClient->listDatabaseRoles($resource);
51+
$roles = $adminClient->listDatabaseRoles($listDatabaseRolesRequest);
4952
printf('List of Database roles:' . PHP_EOL);
5053
foreach ($roles as $role) {
5154
printf($role->getName() . PHP_EOL);

0 commit comments

Comments
 (0)