Skip to content

Commit 94129eb

Browse files
authored
chore: upgrade storagetransfer samples to new surface (#1882)
1 parent 09b69c1 commit 94129eb

File tree

3 files changed

+24
-9
lines changed

3 files changed

+24
-9
lines changed

storagetransfer/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-storage-transfer": "^1.0",
3+
"google/cloud-storage-transfer": "^1.4",
44
"paragonie/random_compat": "^9.0.0"
55
},
66
"require-dev": {

storagetransfer/src/quickstart.php

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,13 @@
1818
namespace Google\Cloud\Samples\StorageTransfer;
1919

2020
# [START storagetransfer_quickstart]
21-
use Google\Cloud\StorageTransfer\V1\StorageTransferServiceClient;
21+
use Google\Cloud\StorageTransfer\V1\Client\StorageTransferServiceClient;
22+
use Google\Cloud\StorageTransfer\V1\CreateTransferJobRequest;
23+
use Google\Cloud\StorageTransfer\V1\GcsData;
24+
use Google\Cloud\StorageTransfer\V1\RunTransferJobRequest;
2225
use Google\Cloud\StorageTransfer\V1\TransferJob;
2326
use Google\Cloud\StorageTransfer\V1\TransferJob\Status;
2427
use Google\Cloud\StorageTransfer\V1\TransferSpec;
25-
use Google\Cloud\StorageTransfer\V1\GcsData;
2628

2729
/**
2830
* Creates and runs a transfer job between two GCS buckets
@@ -46,8 +48,13 @@ function quickstart($projectId, $sourceGcsBucketName, $sinkGcsBucketName)
4648
]);
4749

4850
$client = new StorageTransferServiceClient();
49-
$response = $client->createTransferJob($transferJob);
50-
$client->runTransferJob($response->getName(), $projectId);
51+
$request = (new CreateTransferJobRequest())
52+
->setTransferJob($transferJob);
53+
$response = $client->createTransferJob($request);
54+
$request2 = (new RunTransferJobRequest())
55+
->setJobName($response->getName())
56+
->setProjectId($projectId);
57+
$client->runTransferJob($request2);
5158

5259
printf('Created and ran transfer job from %s to %s with name %s ' . PHP_EOL, $sourceGcsBucketName, $sinkGcsBucketName, $response->getName());
5360
}

storagetransfer/test/StorageTransferTest.php

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,12 @@
1818
namespace Google\Cloud\Samples\StorageTransfer;
1919

2020
use Google\Cloud\Storage\StorageClient;
21-
use Google\Cloud\StorageTransfer\V1\StorageTransferServiceClient;
21+
use Google\Cloud\StorageTransfer\V1\Client\StorageTransferServiceClient;
22+
use Google\Cloud\StorageTransfer\V1\GetGoogleServiceAccountRequest;
23+
use Google\Cloud\StorageTransfer\V1\TransferJob;
2224
use Google\Cloud\StorageTransfer\V1\TransferJob\Status;
25+
use Google\Cloud\StorageTransfer\V1\UpdateTransferJobRequest;
2326
use Google\Cloud\TestUtils\TestTrait;
24-
use Google\Cloud\StorageTransfer\V1\TransferJob;
2527
use PHPUnit\Framework\TestCase;
2628

2729
class StorageTransferTest extends TestCase
@@ -70,13 +72,19 @@ public function testQuickstart()
7072
'name' => $jobName,
7173
'status' => Status::DELETED
7274
]);
75+
$request = (new UpdateTransferJobRequest())
76+
->setJobName($jobName)
77+
->setProjectId(self::$projectId)
78+
->setTransferJob($transferJob);
7379

74-
self::$sts->updateTransferJob($jobName, self::$projectId, $transferJob);
80+
self::$sts->updateTransferJob($request);
7581
}
7682

7783
private static function grantStsPermissions($bucket)
7884
{
79-
$googleServiceAccount = self::$sts->getGoogleServiceAccount(self::$projectId);
85+
$request2 = (new GetGoogleServiceAccountRequest())
86+
->setProjectId(self::$projectId);
87+
$googleServiceAccount = self::$sts->getGoogleServiceAccount($request2);
8088
$email = $googleServiceAccount->getAccountEmail();
8189
$members = ['serviceAccount:' . $email];
8290

0 commit comments

Comments
 (0)