34
34
import org .threeten .bp .Duration ;
35
35
import org .threeten .bp .Instant ;
36
36
37
- /** Snippets for how to work with Assets in Cloud Security Command Center. */
37
+ /**
38
+ * Snippets for how to work with Assets in Security Command Center.
39
+ */
38
40
public class AssetSnippets {
39
- private AssetSnippets () {}
41
+
42
+ private AssetSnippets () {
43
+ }
40
44
41
45
/**
42
46
* Lists all assets for an organization.
@@ -46,8 +50,12 @@ private AssetSnippets() {}
46
50
// [START securitycenter_list_all_assets]
47
51
static ImmutableList <ListAssetsResult > listAssets (OrganizationName organizationName ) {
48
52
try (SecurityCenterClient client = SecurityCenterClient .create ()) {
49
- // Start setting up a request for to search for all assets in an organization.
50
- // OrganizationName organizationName = OrganizationName.of(/*organizationId=*/"123234324");
53
+ // Start setting up a request to search for all assets in an organization, project, or folder.
54
+ //
55
+ // Parent must be in one of the following formats:
56
+ // OrganizationName organizationName = OrganizationName.of("organization-id");
57
+ // ProjectName projectName = ProjectName.of("project-id");
58
+ // FolderName folderName = FolderName.of("folder-id");
51
59
ListAssetsRequest .Builder request =
52
60
ListAssetsRequest .newBuilder ().setParent (organizationName .toString ());
53
61
@@ -75,8 +83,12 @@ static ImmutableList<ListAssetsResult> listAssets(OrganizationName organizationN
75
83
// [START securitycenter_list_assets_with_filter]
76
84
static ImmutableList <ListAssetsResult > listAssetsWithFilter (OrganizationName organizationName ) {
77
85
try (SecurityCenterClient client = SecurityCenterClient .create ()) {
78
- // Start setting up a request for to search for all assets in an organization.
79
- // OrganizationName organizationName = OrganizationName.of(/*organizationId=*/"123234324");
86
+ // Start setting up a request to search for all assets in an organization, project, or folder.
87
+ //
88
+ // Parent must be in one of the following formats:
89
+ // OrganizationName organizationName = OrganizationName.of("organization-id");
90
+ // ProjectName projectName = ProjectName.of("project-id");
91
+ // FolderName folderName = FolderName.of("folder-id");
80
92
ListAssetsRequest .Builder request =
81
93
ListAssetsRequest .newBuilder ()
82
94
.setParent (organizationName .toString ())
@@ -109,10 +121,13 @@ static ImmutableList<ListAssetsResult> listAssetsWithFilter(OrganizationName org
109
121
static ImmutableList <ListAssetsResult > listAssetsAsOfYesterday (
110
122
OrganizationName organizationName , Instant asOf ) {
111
123
try (SecurityCenterClient client = SecurityCenterClient .create ()) {
112
- // Start setting up a request for to search for all assets in an organization.
113
- // OrganizationName organizationName = OrganizationName.of(/*organizationId=*/"123234324");
114
-
115
- // Initialize the builder with the organization and filter
124
+ // Start setting up a request to search for all assets in an organization, project, or folder.
125
+ //
126
+ // Parent must be in one of the following formats:
127
+ // OrganizationName organizationName = OrganizationName.of("organization-id");
128
+ // ProjectName projectName = ProjectName.of("project-id");
129
+ // FolderName folderName = FolderName.of("folder-id");
130
+ // Initialize the builder with the parent and filter
116
131
ListAssetsRequest .Builder request =
117
132
ListAssetsRequest .newBuilder ()
118
133
.setParent (organizationName .toString ())
@@ -151,8 +166,12 @@ static ImmutableList<ListAssetsResult> listAssetAndStatusChanges(
151
166
OrganizationName organizationName , Duration timeSpan , Instant asOf ) {
152
167
try (SecurityCenterClient client = SecurityCenterClient .create ()) {
153
168
154
- // Start setting up a request for to search for all assets in an organization.
155
- // OrganizationName organizationName = OrganizationName.of(/*organizationId=*/"123234324");
169
+ // Start setting up a request to search for all assets in an organization, project, or folder.
170
+ //
171
+ // Parent must be in one of the following formats:
172
+ // OrganizationName organizationName = OrganizationName.of("organization-id");
173
+ // ProjectName projectName = ProjectName.of("project-id");
174
+ // FolderName folderName = FolderName.of("folder-id");
156
175
ListAssetsRequest .Builder request =
157
176
ListAssetsRequest .newBuilder ()
158
177
.setParent (organizationName .toString ())
@@ -191,8 +210,12 @@ static ImmutableList<ListAssetsResult> listAssetAndStatusChanges(
191
210
// [START securitycenter_group_all_assets]
192
211
static ImmutableList <GroupResult > groupAssets (OrganizationName organizationName ) {
193
212
try (SecurityCenterClient client = SecurityCenterClient .create ()) {
194
- // Start setting up a request for to group all assets by type in an organization.
195
- // OrganizationName organizationName = OrganizationName.of("123234324");
213
+ // Start setting up a request to group all assets by type in an organization, project, or folder.
214
+ //
215
+ // Parent must be in one of the following formats:
216
+ // OrganizationName organizationName = OrganizationName.of("organization-id");
217
+ // ProjectName projectName = ProjectName.of("project-id");
218
+ // FolderName folderName = FolderName.of("folder-id");
196
219
GroupAssetsRequest .Builder request =
197
220
GroupAssetsRequest .newBuilder ()
198
221
.setGroupBy ("security_center_properties.resource_type" )
@@ -223,9 +246,10 @@ static ImmutableList<GroupResult> groupAssets(OrganizationName organizationName)
223
246
// [START securitycenter_group_all_assets_with_filter]
224
247
static ImmutableList <GroupResult > groupAssetsWithFilter (OrganizationName organizationName ) {
225
248
try (SecurityCenterClient client = SecurityCenterClient .create ()) {
226
- // Start setting up a request for to filter all assets by type and group them by project in an
249
+ // Start setting up a request to filter all assets by type and group them by project in an
227
250
// organization.
228
- // OrganizationName organizationName = OrganizationName.of("123234324");
251
+ // You can also use a project or folder as a parent resource and filter assets in them
252
+ // respectively.
229
253
GroupAssetsRequest .Builder request =
230
254
GroupAssetsRequest .newBuilder ()
231
255
.setFilter (
@@ -259,9 +283,13 @@ static ImmutableList<GroupResult> groupAssetsWithFilter(OrganizationName organiz
259
283
static ImmutableList <GroupResult > groupAssetsWithCompareDuration (
260
284
OrganizationName organizationName , Duration duration ) {
261
285
try (SecurityCenterClient client = SecurityCenterClient .create ()) {
262
- // Start setting up a request for to group all assets during a period of time in an
263
- // organization.
264
- // OrganizationName organizationName = OrganizationName.of("123234324");
286
+ // Start setting up a request to group all assets during a period of time in an
287
+ // organization, project, or folder.
288
+ //
289
+ // Parent must be in one of the following formats:
290
+ // OrganizationName organizationName = OrganizationName.of("organization-id");
291
+ // ProjectName projectName = ProjectName.of("project-id");
292
+ // FolderName folderName = FolderName.of("folder-id");
265
293
GroupAssetsRequest .Builder request =
266
294
GroupAssetsRequest .newBuilder ()
267
295
.setGroupBy ("state_change" )
0 commit comments