Skip to content

chore: upgrade storagetransfer samples to new surface #1882

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 7 commits into from
Jan 8, 2024
Merged
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
2 changes: 1 addition & 1 deletion storagetransfer/composer.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"require": {
"google/cloud-storage-transfer": "^1.0",
"google/cloud-storage-transfer": "^1.4",
"paragonie/random_compat": "^9.0.0"
},
"require-dev": {
Expand Down
15 changes: 11 additions & 4 deletions storagetransfer/src/quickstart.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,13 @@
namespace Google\Cloud\Samples\StorageTransfer;

# [START storagetransfer_quickstart]
use Google\Cloud\StorageTransfer\V1\StorageTransferServiceClient;
use Google\Cloud\StorageTransfer\V1\Client\StorageTransferServiceClient;
use Google\Cloud\StorageTransfer\V1\CreateTransferJobRequest;
use Google\Cloud\StorageTransfer\V1\GcsData;
use Google\Cloud\StorageTransfer\V1\RunTransferJobRequest;
use Google\Cloud\StorageTransfer\V1\TransferJob;
use Google\Cloud\StorageTransfer\V1\TransferJob\Status;
use Google\Cloud\StorageTransfer\V1\TransferSpec;
use Google\Cloud\StorageTransfer\V1\GcsData;

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

$client = new StorageTransferServiceClient();
$response = $client->createTransferJob($transferJob);
$client->runTransferJob($response->getName(), $projectId);
$request = (new CreateTransferJobRequest())
->setTransferJob($transferJob);
$response = $client->createTransferJob($request);
$request2 = (new RunTransferJobRequest())
->setJobName($response->getName())
->setProjectId($projectId);
$client->runTransferJob($request2);

printf('Created and ran transfer job from %s to %s with name %s ' . PHP_EOL, $sourceGcsBucketName, $sinkGcsBucketName, $response->getName());
}
Expand Down
16 changes: 12 additions & 4 deletions storagetransfer/test/StorageTransferTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,12 @@
namespace Google\Cloud\Samples\StorageTransfer;

use Google\Cloud\Storage\StorageClient;
use Google\Cloud\StorageTransfer\V1\StorageTransferServiceClient;
use Google\Cloud\StorageTransfer\V1\Client\StorageTransferServiceClient;
use Google\Cloud\StorageTransfer\V1\GetGoogleServiceAccountRequest;
use Google\Cloud\StorageTransfer\V1\TransferJob;
use Google\Cloud\StorageTransfer\V1\TransferJob\Status;
use Google\Cloud\StorageTransfer\V1\UpdateTransferJobRequest;
use Google\Cloud\TestUtils\TestTrait;
use Google\Cloud\StorageTransfer\V1\TransferJob;
use PHPUnit\Framework\TestCase;

class StorageTransferTest extends TestCase
Expand Down Expand Up @@ -70,13 +72,19 @@ public function testQuickstart()
'name' => $jobName,
'status' => Status::DELETED
]);
$request = (new UpdateTransferJobRequest())
->setJobName($jobName)
->setProjectId(self::$projectId)
->setTransferJob($transferJob);

self::$sts->updateTransferJob($jobName, self::$projectId, $transferJob);
self::$sts->updateTransferJob($request);
}

private static function grantStsPermissions($bucket)
{
$googleServiceAccount = self::$sts->getGoogleServiceAccount(self::$projectId);
$request2 = (new GetGoogleServiceAccountRequest())
->setProjectId(self::$projectId);
$googleServiceAccount = self::$sts->getGoogleServiceAccount($request2);
$email = $googleServiceAccount->getAccountEmail();
$members = ['serviceAccount:' . $email];

Expand Down