Skip to content

Commit ebf69d4

Browse files
authored
chore: upgrade asset samples to new surface (GoogleCloudPlatform#1895)
1 parent 80c1f81 commit ebf69d4

File tree

6 files changed

+42
-31
lines changed

6 files changed

+42
-31
lines changed

asset/composer.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"require": {
3-
"google/cloud-bigquery": "^1.16.0",
4-
"google/cloud-storage": "^1.9",
5-
"google/cloud-asset": "^1.4.2"
3+
"google/cloud-bigquery": "^1.28",
4+
"google/cloud-storage": "^1.36",
5+
"google/cloud-asset": "^1.14"
66
}
77
}

asset/src/batch_get_assets_history.php

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,8 @@
1818
namespace Google\Cloud\Samples\Asset;
1919

2020
# [START asset_quickstart_batch_get_assets_history]
21-
use Google\Cloud\Asset\V1\AssetServiceClient;
21+
use Google\Cloud\Asset\V1\BatchGetAssetsHistoryRequest;
22+
use Google\Cloud\Asset\V1\Client\AssetServiceClient;
2223
use Google\Cloud\Asset\V1\ContentType;
2324
use Google\Cloud\Asset\V1\TimeWindow;
2425
use Google\Protobuf\Timestamp;
@@ -33,13 +34,13 @@ function batch_get_assets_history(string $projectId, array $assetNames): void
3334
$formattedParent = $client->projectName($projectId);
3435
$contentType = ContentType::RESOURCE;
3536
$readTimeWindow = new TimeWindow(['start_time' => new Timestamp(['seconds' => time()])]);
37+
$request = (new BatchGetAssetsHistoryRequest())
38+
->setParent($formattedParent)
39+
->setContentType($contentType)
40+
->setReadTimeWindow($readTimeWindow)
41+
->setAssetNames($assetNames);
3642

37-
$resp = $client->batchGetAssetsHistory(
38-
$formattedParent,
39-
$contentType,
40-
$readTimeWindow,
41-
['assetNames' => $assetNames]
42-
);
43+
$resp = $client->batchGetAssetsHistory($request);
4344

4445
# Do things with response.
4546
print($resp->serializeToString());

asset/src/export_assets.php

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,8 @@
1818
namespace Google\Cloud\Samples\Asset;
1919

2020
# [START asset_quickstart_export_assets]
21-
use Google\Cloud\Asset\V1\AssetServiceClient;
21+
use Google\Cloud\Asset\V1\Client\AssetServiceClient;
22+
use Google\Cloud\Asset\V1\ExportAssetsRequest;
2223
use Google\Cloud\Asset\V1\GcsDestination;
2324
use Google\Cloud\Asset\V1\OutputConfig;
2425

@@ -35,8 +36,11 @@ function export_assets(string $projectId, string $dumpFilePath)
3536

3637
$gcsDestination = new GcsDestination(['uri' => $dumpFilePath]);
3738
$outputConfig = new OutputConfig(['gcs_destination' => $gcsDestination]);
39+
$request = (new ExportAssetsRequest())
40+
->setParent("projects/$projectId")
41+
->setOutputConfig($outputConfig);
3842

39-
$resp = $client->exportAssets("projects/$projectId", $outputConfig);
43+
$resp = $client->exportAssets($request);
4044

4145
$resp->pollUntilComplete();
4246

asset/src/list_assets.php

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,8 @@
1818
namespace Google\Cloud\Samples\Asset;
1919

2020
// [START asset_quickstart_list_assets]
21-
use Google\Cloud\Asset\V1\AssetServiceClient;
21+
use Google\Cloud\Asset\V1\Client\AssetServiceClient;
22+
use Google\Cloud\Asset\V1\ListAssetsRequest;
2223

2324
/**
2425
* @param string $projectId Tthe project Id for list assets.
@@ -34,10 +35,11 @@ function list_assets(
3435
$client = new AssetServiceClient();
3536

3637
// Run request
37-
$response = $client->listAssets("projects/$projectId", [
38-
'assetTypes' => $assetTypes,
39-
'pageSize' => $pageSize,
40-
]);
38+
$request = (new ListAssetsRequest())
39+
->setParent("projects/$projectId")
40+
->setAssetTypes($assetTypes)
41+
->setPageSize($pageSize);
42+
$response = $client->listAssets($request);
4143

4244
// Print the asset names in the result
4345
foreach ($response->getPage() as $asset) {

asset/src/search_all_iam_policies.php

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,8 @@
1818
namespace Google\Cloud\Samples\Asset;
1919

2020
// [START asset_quickstart_search_all_iam_policies]
21-
use Google\Cloud\Asset\V1\AssetServiceClient;
21+
use Google\Cloud\Asset\V1\Client\AssetServiceClient;
22+
use Google\Cloud\Asset\V1\SearchAllIamPoliciesRequest;
2223

2324
/**
2425
* @param string $scope Scope of the search
@@ -36,11 +37,12 @@ function search_all_iam_policies(
3637
$asset = new AssetServiceClient();
3738

3839
// Run request
39-
$response = $asset->searchAllIamPolicies($scope, [
40-
'query' => $query,
41-
'pageSize' => $pageSize,
42-
'pageToken' => $pageToken
43-
]);
40+
$request = (new SearchAllIamPoliciesRequest())
41+
->setScope($scope)
42+
->setQuery($query)
43+
->setPageSize($pageSize)
44+
->setPageToken($pageToken);
45+
$response = $asset->searchAllIamPolicies($request);
4446

4547
// Print the resources that the policies are set on
4648
foreach ($response->getPage() as $policy) {

asset/src/search_all_resources.php

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

2020
// [START asset_quickstart_search_all_resources]
21-
use Google\Cloud\Asset\V1\AssetServiceClient;
21+
use Google\Cloud\Asset\V1\Client\AssetServiceClient;
22+
use Google\Cloud\Asset\V1\SearchAllResourcesRequest;
2223

2324
/**
2425
* @param string $scope Scope of the search
@@ -40,13 +41,14 @@ function search_all_resources(
4041
$asset = new AssetServiceClient();
4142

4243
// Run request
43-
$response = $asset->searchAllResources($scope, [
44-
'query' => $query,
45-
'assetTypes' => $assetTypes,
46-
'pageSize' => $pageSize,
47-
'pageToken' => $pageToken,
48-
'orderBy' => $orderBy
49-
]);
44+
$request = (new SearchAllResourcesRequest())
45+
->setScope($scope)
46+
->setQuery($query)
47+
->setAssetTypes($assetTypes)
48+
->setPageSize($pageSize)
49+
->setPageToken($pageToken)
50+
->setOrderBy($orderBy);
51+
$response = $asset->searchAllResources($request);
5052

5153
// Print the resource names in the first page of the result
5254
foreach ($response->getPage() as $resource) {

0 commit comments

Comments
 (0)