3434import org .threeten .bp .Duration ;
3535import org .threeten .bp .Instant ;
3636
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+ */
3840public class AssetSnippets {
39- private AssetSnippets () {}
41+
42+ private AssetSnippets () {
43+ }
4044
4145 /**
4246 * Lists all assets for an organization.
@@ -46,8 +50,12 @@ private AssetSnippets() {}
4650 // [START securitycenter_list_all_assets]
4751 static ImmutableList <ListAssetsResult > listAssets (OrganizationName organizationName ) {
4852 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");
5159 ListAssetsRequest .Builder request =
5260 ListAssetsRequest .newBuilder ().setParent (organizationName .toString ());
5361
@@ -75,8 +83,12 @@ static ImmutableList<ListAssetsResult> listAssets(OrganizationName organizationN
7583 // [START securitycenter_list_assets_with_filter]
7684 static ImmutableList <ListAssetsResult > listAssetsWithFilter (OrganizationName organizationName ) {
7785 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");
8092 ListAssetsRequest .Builder request =
8193 ListAssetsRequest .newBuilder ()
8294 .setParent (organizationName .toString ())
@@ -109,10 +121,13 @@ static ImmutableList<ListAssetsResult> listAssetsWithFilter(OrganizationName org
109121 static ImmutableList <ListAssetsResult > listAssetsAsOfYesterday (
110122 OrganizationName organizationName , Instant asOf ) {
111123 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
116131 ListAssetsRequest .Builder request =
117132 ListAssetsRequest .newBuilder ()
118133 .setParent (organizationName .toString ())
@@ -151,8 +166,12 @@ static ImmutableList<ListAssetsResult> listAssetAndStatusChanges(
151166 OrganizationName organizationName , Duration timeSpan , Instant asOf ) {
152167 try (SecurityCenterClient client = SecurityCenterClient .create ()) {
153168
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");
156175 ListAssetsRequest .Builder request =
157176 ListAssetsRequest .newBuilder ()
158177 .setParent (organizationName .toString ())
@@ -191,8 +210,12 @@ static ImmutableList<ListAssetsResult> listAssetAndStatusChanges(
191210 // [START securitycenter_group_all_assets]
192211 static ImmutableList <GroupResult > groupAssets (OrganizationName organizationName ) {
193212 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");
196219 GroupAssetsRequest .Builder request =
197220 GroupAssetsRequest .newBuilder ()
198221 .setGroupBy ("security_center_properties.resource_type" )
@@ -223,9 +246,10 @@ static ImmutableList<GroupResult> groupAssets(OrganizationName organizationName)
223246 // [START securitycenter_group_all_assets_with_filter]
224247 static ImmutableList <GroupResult > groupAssetsWithFilter (OrganizationName organizationName ) {
225248 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
227250 // 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.
229253 GroupAssetsRequest .Builder request =
230254 GroupAssetsRequest .newBuilder ()
231255 .setFilter (
@@ -259,9 +283,13 @@ static ImmutableList<GroupResult> groupAssetsWithFilter(OrganizationName organiz
259283 static ImmutableList <GroupResult > groupAssetsWithCompareDuration (
260284 OrganizationName organizationName , Duration duration ) {
261285 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");
265293 GroupAssetsRequest .Builder request =
266294 GroupAssetsRequest .newBuilder ()
267295 .setGroupBy ("state_change" )
0 commit comments