Skip to content

Commit 5d1b532

Browse files
authored
chore: upgrade storageinsights to new surface (#2021)
1 parent 6d57786 commit 5d1b532

6 files changed

+40
-17
lines changed

storageinsights/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-storageinsights": "^0.3.2"
3+
"google/cloud-storageinsights": "^1.0"
44
},
55
"require-dev": {
66
"google/cloud-storage": "^1.41.0"

storageinsights/src/create_inventory_report_config.php

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,14 +18,15 @@
1818
namespace Google\Cloud\Samples\StorageInsights;
1919

2020
# [START storageinsights_create_inventory_report_config]
21-
use Google\Type\Date;
21+
use Google\Cloud\StorageInsights\V1\Client\StorageInsightsClient;
22+
use Google\Cloud\StorageInsights\V1\CloudStorageDestinationOptions;
23+
use Google\Cloud\StorageInsights\V1\CloudStorageFilters;
24+
use Google\Cloud\StorageInsights\V1\CreateReportConfigRequest;
2225
use Google\Cloud\StorageInsights\V1\CSVOptions;
23-
use Google\Cloud\StorageInsights\V1\ReportConfig;
2426
use Google\Cloud\StorageInsights\V1\FrequencyOptions;
25-
use Google\Cloud\StorageInsights\V1\CloudStorageFilters;
26-
use Google\Cloud\StorageInsights\V1\StorageInsightsClient;
2727
use Google\Cloud\StorageInsights\V1\ObjectMetadataReportOptions;
28-
use Google\Cloud\StorageInsights\V1\CloudStorageDestinationOptions;
28+
use Google\Cloud\StorageInsights\V1\ReportConfig;
29+
use Google\Type\Date;
2930

3031
/**
3132
* Creates an inventory report config.
@@ -70,7 +71,10 @@ function create_inventory_report_config(
7071
->setBucket($destinationBucket)));
7172

7273
$formattedParent = $storageInsightsClient->locationName($projectId, $bucketLocation);
73-
$response = $storageInsightsClient->createReportConfig($formattedParent, $reportConfig);
74+
$createReportConfigRequest = (new CreateReportConfigRequest())
75+
->setParent($formattedParent)
76+
->setReportConfig($reportConfig);
77+
$response = $storageInsightsClient->createReportConfig($createReportConfigRequest);
7478

7579
print('Created inventory report config with name:' . PHP_EOL);
7680
print($response->getName());

storageinsights/src/delete_inventory_report_config.php

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

2020
# [START storageinsights_delete_inventory_report_config]
21-
use Google\Cloud\StorageInsights\V1\StorageInsightsClient;
21+
use Google\Cloud\StorageInsights\V1\Client\StorageInsightsClient;
22+
use Google\Cloud\StorageInsights\V1\DeleteReportConfigRequest;
2223

2324
/**
2425
* Delete an inventory report config.
@@ -39,7 +40,9 @@ function delete_inventory_report_config(
3940
$storageInsightsClient = new StorageInsightsClient();
4041

4142
$reportConfigName = $storageInsightsClient->reportConfigName($projectId, $bucketLocation, $inventoryReportConfigUuid);
42-
$storageInsightsClient->deleteReportConfig($reportConfigName);
43+
$deleteReportConfigRequest = (new DeleteReportConfigRequest())
44+
->setName($reportConfigName);
45+
$storageInsightsClient->deleteReportConfig($deleteReportConfigRequest);
4346

4447
printf('Deleted inventory report config with name %s' . PHP_EOL, $reportConfigName);
4548
}

storageinsights/src/edit_inventory_report_config.php

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

2020
# [START storageinsights_edit_inventory_report_config]
21-
use Google\Cloud\StorageInsights\V1\StorageInsightsClient;
21+
use Google\Cloud\StorageInsights\V1\Client\StorageInsightsClient;
22+
use Google\Cloud\StorageInsights\V1\GetReportConfigRequest;
23+
use Google\Cloud\StorageInsights\V1\UpdateReportConfigRequest;
2224
use Google\Protobuf\FieldMask;
2325

2426
/**
@@ -40,15 +42,20 @@ function edit_inventory_report_config(
4042
$storageInsightsClient = new StorageInsightsClient();
4143

4244
$reportConfigName = $storageInsightsClient->reportConfigName($projectId, $bucketLocation, $inventoryReportConfigUuid);
43-
$reportConfig = $storageInsightsClient->getReportConfig($reportConfigName);
45+
$getReportConfigRequest = (new GetReportConfigRequest())
46+
->setName($reportConfigName);
47+
$reportConfig = $storageInsightsClient->getReportConfig($getReportConfigRequest);
4448

4549
// Set any other fields you want to update here
4650
$updatedReportConfig = $reportConfig->setDisplayName('Updated Display Name');
4751
$updateMask = new FieldMask([
4852
'paths' => ['display_name']
4953
]);
54+
$updateReportConfigRequest = (new UpdateReportConfigRequest())
55+
->setUpdateMask($updateMask)
56+
->setReportConfig($updatedReportConfig);
5057

51-
$storageInsightsClient->updateReportConfig($updateMask, $updatedReportConfig);
58+
$storageInsightsClient->updateReportConfig($updateReportConfigRequest);
5259

5360
printf('Edited inventory report config with name %s' . PHP_EOL, $reportConfigName);
5461
}

storageinsights/src/get_inventory_report_names.php

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

2020
# [START storageinsights_get_inventory_report_names]
21-
use Google\Cloud\StorageInsights\V1\StorageInsightsClient;
21+
use Google\Cloud\StorageInsights\V1\Client\StorageInsightsClient;
22+
use Google\Cloud\StorageInsights\V1\GetReportConfigRequest;
23+
use Google\Cloud\StorageInsights\V1\ListReportDetailsRequest;
2224

2325
/**
2426
* Gets an existing inventory report config.
@@ -39,11 +41,15 @@ function get_inventory_report_names(
3941
$storageInsightsClient = new StorageInsightsClient();
4042

4143
$reportConfigName = $storageInsightsClient->reportConfigName($projectId, $bucketLocation, $inventoryReportConfigUuid);
42-
$reportConfig = $storageInsightsClient->getReportConfig($reportConfigName);
44+
$getReportConfigRequest = (new GetReportConfigRequest())
45+
->setName($reportConfigName);
46+
$reportConfig = $storageInsightsClient->getReportConfig($getReportConfigRequest);
4347
$extension = $reportConfig->hasCsvOptions() ? 'csv' : 'parquet';
4448
print('You can use the Google Cloud Storage Client '
4549
. 'to download the following objects from Google Cloud Storage:' . PHP_EOL);
46-
$listReportConfigs = $storageInsightsClient->listReportDetails($reportConfig->getName());
50+
$listReportDetailsRequest = (new ListReportDetailsRequest())
51+
->setParent($reportConfig->getName());
52+
$listReportConfigs = $storageInsightsClient->listReportDetails($listReportDetailsRequest);
4753
foreach ($listReportConfigs->iterateAllElements() as $reportDetail) {
4854
for ($index = $reportDetail->getShardsCount() - 1; $index >= 0; $index--) {
4955
printf('%s%d.%s' . PHP_EOL, $reportDetail->getReportPathPrefix(), $index, $extension);

storageinsights/src/list_inventory_report_configs.php

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

2020
# [START storageinsights_list_inventory_report_configs]
21-
use Google\Cloud\StorageInsights\V1\StorageInsightsClient;
21+
use Google\Cloud\StorageInsights\V1\Client\StorageInsightsClient;
22+
use Google\Cloud\StorageInsights\V1\ListReportConfigsRequest;
2223

2324
/**
2425
* Lists inventory report configs.
@@ -35,7 +36,9 @@ function list_inventory_report_configs(string $projectId, string $location): voi
3536
$storageInsightsClient = new StorageInsightsClient();
3637

3738
$formattedParent = $storageInsightsClient->locationName($projectId, $location);
38-
$configs = $storageInsightsClient->listReportConfigs($formattedParent);
39+
$listReportConfigsRequest = (new ListReportConfigsRequest())
40+
->setParent($formattedParent);
41+
$configs = $storageInsightsClient->listReportConfigs($listReportConfigsRequest);
3942

4043
printf('Inventory report configs in project %s and location %s:' . PHP_EOL, $projectId, $location);
4144
foreach ($configs->iterateAllElements() as $config) {

0 commit comments

Comments
 (0)