Skip to content

Commit 0b2d0a3

Browse files
storageinsights: update edit inventory report config sample (#9283)
* storageinsights: update edit inventory report config sample * fix lint issues * lint
1 parent 5752f77 commit 0b2d0a3

File tree

2 files changed

+9
-4
lines changed

2 files changed

+9
-4
lines changed

storageinsights/src/main/java/com/google/cloud/storage/storageinsights/samples/EditInventoryReportConfig.java

+8-3
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
import com.google.cloud.storageinsights.v1.ReportConfigName;
2323
import com.google.cloud.storageinsights.v1.StorageInsightsClient;
2424
import com.google.cloud.storageinsights.v1.UpdateReportConfigRequest;
25+
import com.google.protobuf.FieldMask;
2526
import java.io.IOException;
2627

2728
public class EditInventoryReportConfig {
@@ -42,17 +43,21 @@ public static void main(String[] args) throws IOException {
4243
// [START storageinsights_edit_inventory_report_config]
4344

4445
public static void editInventoryReportConfig(
45-
String projectId, String location, String inventoryReportConfigUuid) throws IOException {
46+
String projectId, String location, String inventoryReportConfigUuid) throws IOException {
4647
try (StorageInsightsClient storageInsightsClient = StorageInsightsClient.create()) {
4748
ReportConfigName name = ReportConfigName.of(projectId, location, inventoryReportConfigUuid);
4849
ReportConfig reportConfig = storageInsightsClient.getReportConfig(name);
4950

5051
// Set any other fields you want to update here
5152
ReportConfig updatedReportConfig =
52-
reportConfig.toBuilder().setDisplayName("Updated Display Name").build();
53+
reportConfig.toBuilder().setDisplayName("Updated Display Name").build();
5354

5455
storageInsightsClient.updateReportConfig(
55-
UpdateReportConfigRequest.newBuilder().setReportConfig(updatedReportConfig).build());
56+
UpdateReportConfigRequest.newBuilder()
57+
// Add any fields that you want to update to the update mask, in snake case
58+
.setUpdateMask(FieldMask.newBuilder().addPaths("display_name")
59+
.build())
60+
.setReportConfig(updatedReportConfig).build());
5661

5762
System.out.println("Edited inventory report config with name " + name);
5863
}

storageinsights/src/test/java/com/google/cloud/storage/storageinsights/samples/test/ITStorageinsightsSamplesTest.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -182,7 +182,7 @@ public void testEditInventoryReportConfig() throws Exception {
182182
EditInventoryReportConfig.editInventoryReportConfig(
183183
PROJECT_ID, BUCKET_LOCATION, reportConfigName.split("/")[5]);
184184
ReportConfig reportConfig = insights.getReportConfig(reportConfigName);
185-
assertThat(reportConfig.getDisplayName().contains("Updated"));
185+
assertThat(reportConfig.getDisplayName()).contains("Updated");
186186
} finally {
187187
insights.deleteReportConfig(reportConfigName);
188188
}

0 commit comments

Comments
 (0)