Skip to content

Commit 1927bfc

Browse files
authored
docs(scc-samples): update comments to include new parent types (googleapis#9596)
* docs(scc-samples): update comments to include new parent types * updated acc to review comments * updated acc to review comments * fix typo * update acc to review comments
1 parent 68b12a0 commit 1927bfc

File tree

5 files changed

+145
-52
lines changed

5 files changed

+145
-52
lines changed

Diff for: google-cloud-examples/src/main/java/com/google/cloud/examples/securitycenter/snippets/AssetSnippets.java

+47-19
Original file line numberDiff line numberDiff line change
@@ -34,9 +34,13 @@
3434
import org.threeten.bp.Duration;
3535
import 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+
*/
3840
public 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")

Diff for: google-cloud-examples/src/main/java/com/google/cloud/examples/securitycenter/snippets/FindingSnippets.java

+52-17
Original file line numberDiff line numberDiff line change
@@ -40,9 +40,13 @@
4040
import org.threeten.bp.Duration;
4141
import org.threeten.bp.Instant;
4242

43-
/** Snippets for how to work with Findings in Cloud Security Command Center. */
43+
/**
44+
* Snippets for how to work with Findings in Security Command Center.
45+
*/
4446
public class FindingSnippets {
45-
private FindingSnippets() {}
47+
48+
private FindingSnippets() {
49+
}
4650

4751
/**
4852
* Create a finding under a source.
@@ -226,7 +230,14 @@ static Finding setFindingState(FindingName findingName) {
226230
// [START securitycenter_list_all_findings]
227231
static ImmutableList<ListFindingsResult> listAllFindings(OrganizationName organizationName) {
228232
try (SecurityCenterClient client = SecurityCenterClient.create()) {
229-
// OrganizationName organizationName = OrganizationName.of(/*organizationId=*/"123234324");
233+
// Input parameters for SourceName must be in one of the following formats:
234+
// * OrganizationName organizationName = OrganizationName.of("organization-id");
235+
// organizationName.getOrganization();
236+
// * ProjectName projectName = ProjectName.of("project-id");
237+
// projectName.getProject();
238+
// * FolderName folderName = FolderName.of("folder-id");
239+
// folderName.getFolder();
240+
//
230241
// "-" Indicates listing across all sources.
231242
SourceName sourceName = SourceName.of(organizationName.getOrganization(), "-");
232243

@@ -257,8 +268,11 @@ static ImmutableList<ListFindingsResult> listAllFindings(OrganizationName organi
257268
// [START securitycenter_list_filtered_findings]
258269
static ImmutableList<ListFindingsResult> listFilteredFindings(SourceName sourceName) {
259270
try (SecurityCenterClient client = SecurityCenterClient.create()) {
260-
// SourceName sourceName = SourceName.of(/*organizationId=*/"123234324",
261-
// /*sourceId=*/"423432321");
271+
// parentId: must be one of the following:
272+
// "organization-id"
273+
// "project-id"
274+
// "folder-id"
275+
// SourceName sourceName = SourceName.of(parentId, sourceId);
262276

263277
// Create filter to category of MEDIUM_RISK_ONE
264278
String filter = "category=\"MEDIUM_RISK_ONE\"";
@@ -290,8 +304,11 @@ static ImmutableList<ListFindingsResult> listFilteredFindings(SourceName sourceN
290304
// [START securitycenter_list_findings_at_time]
291305
static ImmutableList<ListFindingsResult> listFindingsAtTime(SourceName sourceName) {
292306
try (SecurityCenterClient client = SecurityCenterClient.create()) {
293-
// SourceName sourceName = SourceName.of(/*organizationId=*/"123234324",
294-
// /*sourceId=*/"423432321");
307+
// parentId: must be one of the following:
308+
// "organization-id"
309+
// "project-id"
310+
// "folder-id"
311+
// SourceName sourceName = SourceName.of(parentId, sourceId);
295312

296313
// 5 days ago
297314
Instant fiveDaysAgo = Instant.now().minus(Duration.ofDays(5));
@@ -353,12 +370,18 @@ static TestIamPermissionsResponse testIamPermissions(SourceName sourceName) {
353370
* Group all findings under an organization across all sources by their specified properties (e.g.
354371
* category).
355372
*
356-
* @param organizationName The organizatoin to group all findings for.
373+
* @param organizationName: The organization to group all findings for.
357374
*/
358375
// [START securitycenter_group_all_findings]
359376
static ImmutableList<GroupResult> groupFindings(OrganizationName organizationName) {
360377
try (SecurityCenterClient client = SecurityCenterClient.create()) {
361-
// OrganizationName organizationName = OrganizationName.of("123234324");
378+
// Input parameters for 'SourceName' must be in one of the following formats:
379+
// * OrganizationName organizationName = OrganizationName.of("organization-id");
380+
// organizationName.getOrganization();
381+
// * ProjectName projectName = ProjectName.of("project-id");
382+
// projectName.getProject();
383+
// * FolderName folderName = FolderName.of("folder-id");
384+
// folderName.getFolder();
362385
SourceName sourceName = SourceName.of(organizationName.getOrganization(), "-");
363386

364387
GroupFindingsRequest.Builder request =
@@ -390,8 +413,11 @@ static ImmutableList<GroupResult> groupFindings(OrganizationName organizationNam
390413
// [START securitycenter_group_findings_with_source]
391414
static ImmutableList<GroupResult> groupFindingsWithSource(SourceName sourceName) {
392415
try (SecurityCenterClient client = SecurityCenterClient.create()) {
393-
// SourceName sourceName = SourceName.of(/*organization=*/"123234324",/*source=*/
394-
// "423432321");
416+
// parentId: must be one of the following:
417+
// "organization-id"
418+
// "project-id"
419+
// "folder-id"
420+
// SourceName sourceName = SourceName.of(parentId, sourceId);
395421

396422
GroupFindingsRequest.Builder request =
397423
GroupFindingsRequest.newBuilder().setParent(sourceName.toString()).setGroupBy("category");
@@ -422,8 +448,11 @@ static ImmutableList<GroupResult> groupFindingsWithSource(SourceName sourceName)
422448
// [START securitycenter_group_active_findings_with_source]
423449
static ImmutableList<GroupResult> groupActiveFindingsWithSource(SourceName sourceName) {
424450
try (SecurityCenterClient client = SecurityCenterClient.create()) {
425-
// SourceName sourceName = SourceName.of(/*organization=*/"123234324",/*source=*/
426-
// "423432321");
451+
// parentId: must be one of the following:
452+
// "organization-id"
453+
// "project-id"
454+
// "folder-id"
455+
// SourceName sourceName = SourceName.of(parentId, sourceId);
427456

428457
GroupFindingsRequest.Builder request =
429458
GroupFindingsRequest.newBuilder()
@@ -457,8 +486,11 @@ static ImmutableList<GroupResult> groupActiveFindingsWithSource(SourceName sourc
457486
// [START securitycenter_group_active_findings_with_source_at_time]
458487
static ImmutableList<GroupResult> groupActiveFindingsWithSourceAtTime(SourceName sourceName) {
459488
try (SecurityCenterClient client = SecurityCenterClient.create()) {
460-
// SourceName sourceName = SourceName.of(/*organization=*/"123234324",/*source=*/
461-
// "423432321");
489+
// parentId: must be one of the following:
490+
// "organization-id"
491+
// "project-id"
492+
// "folder-id"
493+
// SourceName sourceName = SourceName.of(parentId, sourceId);
462494

463495
// 1 day ago
464496
Instant oneDayAgo = Instant.now().minusSeconds(60 * 60 * 24);
@@ -500,8 +532,11 @@ static ImmutableList<GroupResult> groupActiveFindingsWithSourceAtTime(SourceName
500532
static ImmutableList<GroupResult> groupActiveFindingsWithSourceAndCompareDuration(
501533
SourceName sourceName, Duration duration) {
502534
try (SecurityCenterClient client = SecurityCenterClient.create()) {
503-
// SourceName sourceName = SourceName.of(/*organization=*/"123234324",/*source=*/
504-
// "423432321");
535+
// parentId: must be one of the following:
536+
// "organization-id"
537+
// "project-id"
538+
// "folder-id"
539+
// SourceName sourceName = SourceName.of(parentId, sourceId);
505540

506541
GroupFindingsRequest.Builder request =
507542
GroupFindingsRequest.newBuilder()

Diff for: google-cloud-examples/src/main/java/com/google/cloud/examples/securitycenter/snippets/OrganizationSnippets.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
import com.google.protobuf.FieldMask;
2424
import java.io.IOException;
2525

26-
/** Snippets for how to work with Organizations in Cloud Security Command Center. */
26+
/** Snippets for how to work with Organizations in Security Command Center. */
2727
public class OrganizationSnippets {
2828

2929
private OrganizationSnippets() {}

0 commit comments

Comments
 (0)