Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

docs(scc-samples): update comments to include new parent types #9596

Merged
merged 5 commits into from
Jul 11, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just a heads up that the SCC Assets API is deprecated and will be replaced by integrating Cloud Asset Inventory's API in SCC. The CAI replacement is expected to GA at the beginning of August. Existing users have a year to move off of the SCC API. SCC's Assets API is disabled for all new users who activate SCC after last week's deprecation notice. New users can only use CAI.

Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,13 @@
import org.threeten.bp.Duration;
import org.threeten.bp.Instant;

/** Snippets for how to work with Assets in Cloud Security Command Center. */
/**
* Snippets for how to work with Assets in Security Command Center.
*/
public class AssetSnippets {
private AssetSnippets() {}

private AssetSnippets() {
}

/**
* Lists all assets for an organization.
Expand All @@ -46,8 +50,12 @@ private AssetSnippets() {}
// [START securitycenter_list_all_assets]
static ImmutableList<ListAssetsResult> listAssets(OrganizationName organizationName) {
try (SecurityCenterClient client = SecurityCenterClient.create()) {
// Start setting up a request for to search for all assets in an organization.
// OrganizationName organizationName = OrganizationName.of(/*organizationId=*/"123234324");
// Start setting up a request to search for all assets in an organization, project, or folder.
//
// Parent must be in one of the following formats:
// OrganizationName organizationName = OrganizationName.of("organization-id");
// ProjectName projectName = ProjectName.of("project-id");
// FolderName folderName = FolderName.of("folder-id");
ListAssetsRequest.Builder request =
ListAssetsRequest.newBuilder().setParent(organizationName.toString());

Expand Down Expand Up @@ -75,8 +83,12 @@ static ImmutableList<ListAssetsResult> listAssets(OrganizationName organizationN
// [START securitycenter_list_assets_with_filter]
static ImmutableList<ListAssetsResult> listAssetsWithFilter(OrganizationName organizationName) {
try (SecurityCenterClient client = SecurityCenterClient.create()) {
// Start setting up a request for to search for all assets in an organization.
// OrganizationName organizationName = OrganizationName.of(/*organizationId=*/"123234324");
// Start setting up a request to search for all assets in an organization, project, or folder.
//
// Parent must be in one of the following formats:
// OrganizationName organizationName = OrganizationName.of("organization-id");
// ProjectName projectName = ProjectName.of("project-id");
// FolderName folderName = FolderName.of("folder-id");
ListAssetsRequest.Builder request =
ListAssetsRequest.newBuilder()
.setParent(organizationName.toString())
Expand Down Expand Up @@ -109,10 +121,13 @@ static ImmutableList<ListAssetsResult> listAssetsWithFilter(OrganizationName org
static ImmutableList<ListAssetsResult> listAssetsAsOfYesterday(
OrganizationName organizationName, Instant asOf) {
try (SecurityCenterClient client = SecurityCenterClient.create()) {
// Start setting up a request for to search for all assets in an organization.
// OrganizationName organizationName = OrganizationName.of(/*organizationId=*/"123234324");

// Initialize the builder with the organization and filter
// Start setting up a request to search for all assets in an organization, project, or folder.
//
// Parent must be in one of the following formats:
// OrganizationName organizationName = OrganizationName.of("organization-id");
// ProjectName projectName = ProjectName.of("project-id");
// FolderName folderName = FolderName.of("folder-id");
// Initialize the builder with the parent and filter
ListAssetsRequest.Builder request =
ListAssetsRequest.newBuilder()
.setParent(organizationName.toString())
Expand Down Expand Up @@ -151,8 +166,12 @@ static ImmutableList<ListAssetsResult> listAssetAndStatusChanges(
OrganizationName organizationName, Duration timeSpan, Instant asOf) {
try (SecurityCenterClient client = SecurityCenterClient.create()) {

// Start setting up a request for to search for all assets in an organization.
// OrganizationName organizationName = OrganizationName.of(/*organizationId=*/"123234324");
// Start setting up a request to search for all assets in an organization, project, or folder.
//
// Parent must be in one of the following formats:
// OrganizationName organizationName = OrganizationName.of("organization-id");
// ProjectName projectName = ProjectName.of("project-id");
// FolderName folderName = FolderName.of("folder-id");
ListAssetsRequest.Builder request =
ListAssetsRequest.newBuilder()
.setParent(organizationName.toString())
Expand Down Expand Up @@ -191,8 +210,12 @@ static ImmutableList<ListAssetsResult> listAssetAndStatusChanges(
// [START securitycenter_group_all_assets]
static ImmutableList<GroupResult> groupAssets(OrganizationName organizationName) {
try (SecurityCenterClient client = SecurityCenterClient.create()) {
// Start setting up a request for to group all assets by type in an organization.
// OrganizationName organizationName = OrganizationName.of("123234324");
// Start setting up a request to group all assets by type in an organization, project, or folder.
//
// Parent must be in one of the following formats:
// OrganizationName organizationName = OrganizationName.of("organization-id");
// ProjectName projectName = ProjectName.of("project-id");
// FolderName folderName = FolderName.of("folder-id");
GroupAssetsRequest.Builder request =
GroupAssetsRequest.newBuilder()
.setGroupBy("security_center_properties.resource_type")
Expand Down Expand Up @@ -223,9 +246,10 @@ static ImmutableList<GroupResult> groupAssets(OrganizationName organizationName)
// [START securitycenter_group_all_assets_with_filter]
static ImmutableList<GroupResult> groupAssetsWithFilter(OrganizationName organizationName) {
try (SecurityCenterClient client = SecurityCenterClient.create()) {
// Start setting up a request for to filter all assets by type and group them by project in an
// Start setting up a request to filter all assets by type and group them by project in an
// organization.
// OrganizationName organizationName = OrganizationName.of("123234324");
// You can also use a project or folder as a parent resource and filter assets in them
// respectively.
GroupAssetsRequest.Builder request =
GroupAssetsRequest.newBuilder()
.setFilter(
Expand Down Expand Up @@ -259,9 +283,13 @@ static ImmutableList<GroupResult> groupAssetsWithFilter(OrganizationName organiz
static ImmutableList<GroupResult> groupAssetsWithCompareDuration(
OrganizationName organizationName, Duration duration) {
try (SecurityCenterClient client = SecurityCenterClient.create()) {
// Start setting up a request for to group all assets during a period of time in an
// organization.
// OrganizationName organizationName = OrganizationName.of("123234324");
// Start setting up a request to group all assets during a period of time in an
// organization, project, or folder.
//
// Parent must be in one of the following formats:
// OrganizationName organizationName = OrganizationName.of("organization-id");
// ProjectName projectName = ProjectName.of("project-id");
// FolderName folderName = FolderName.of("folder-id");
GroupAssetsRequest.Builder request =
GroupAssetsRequest.newBuilder()
.setGroupBy("state_change")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,13 @@
import org.threeten.bp.Duration;
import org.threeten.bp.Instant;

/** Snippets for how to work with Findings in Cloud Security Command Center. */
/**
* Snippets for how to work with Findings in Security Command Center.
*/
public class FindingSnippets {
private FindingSnippets() {}

private FindingSnippets() {
}

/**
* Create a finding under a source.
Expand Down Expand Up @@ -226,7 +230,14 @@ static Finding setFindingState(FindingName findingName) {
// [START securitycenter_list_all_findings]
static ImmutableList<ListFindingsResult> listAllFindings(OrganizationName organizationName) {
try (SecurityCenterClient client = SecurityCenterClient.create()) {
// OrganizationName organizationName = OrganizationName.of(/*organizationId=*/"123234324");
// Input parameters for SourceName must be in one of the following formats:
// * OrganizationName organizationName = OrganizationName.of("organization-id");
// organizationName.getOrganization();
// * ProjectName projectName = ProjectName.of("project-id");
// projectName.getProject();
// * FolderName folderName = FolderName.of("folder-id");
// folderName.getFolder();
//
// "-" Indicates listing across all sources.
SourceName sourceName = SourceName.of(organizationName.getOrganization(), "-");

Expand Down Expand Up @@ -257,8 +268,11 @@ static ImmutableList<ListFindingsResult> listAllFindings(OrganizationName organi
// [START securitycenter_list_filtered_findings]
static ImmutableList<ListFindingsResult> listFilteredFindings(SourceName sourceName) {
try (SecurityCenterClient client = SecurityCenterClient.create()) {
// SourceName sourceName = SourceName.of(/*organizationId=*/"123234324",
// /*sourceId=*/"423432321");
// parentId: must be one of the following:
// "organization-id"
// "project-id"
// "folder-id"
// SourceName sourceName = SourceName.of(parentId, sourceId);

// Create filter to category of MEDIUM_RISK_ONE
String filter = "category=\"MEDIUM_RISK_ONE\"";
Expand Down Expand Up @@ -290,8 +304,11 @@ static ImmutableList<ListFindingsResult> listFilteredFindings(SourceName sourceN
// [START securitycenter_list_findings_at_time]
static ImmutableList<ListFindingsResult> listFindingsAtTime(SourceName sourceName) {
try (SecurityCenterClient client = SecurityCenterClient.create()) {
// SourceName sourceName = SourceName.of(/*organizationId=*/"123234324",
// /*sourceId=*/"423432321");
// parentId: must be one of the following:
// "organization-id"
// "project-id"
// "folder-id"
// SourceName sourceName = SourceName.of(parentId, sourceId);

// 5 days ago
Instant fiveDaysAgo = Instant.now().minus(Duration.ofDays(5));
Expand Down Expand Up @@ -353,12 +370,18 @@ static TestIamPermissionsResponse testIamPermissions(SourceName sourceName) {
* Group all findings under an organization across all sources by their specified properties (e.g.
* category).
*
* @param organizationName The organizatoin to group all findings for.
* @param organizationName: The organization to group all findings for.
*/
// [START securitycenter_group_all_findings]
static ImmutableList<GroupResult> groupFindings(OrganizationName organizationName) {
try (SecurityCenterClient client = SecurityCenterClient.create()) {
// OrganizationName organizationName = OrganizationName.of("123234324");
// Input parameters for 'SourceName' must be in one of the following formats:
// * OrganizationName organizationName = OrganizationName.of("organization-id");
// organizationName.getOrganization();
// * ProjectName projectName = ProjectName.of("project-id");
// projectName.getProject();
// * FolderName folderName = FolderName.of("folder-id");
// folderName.getFolder();
SourceName sourceName = SourceName.of(organizationName.getOrganization(), "-");

GroupFindingsRequest.Builder request =
Expand Down Expand Up @@ -390,8 +413,11 @@ static ImmutableList<GroupResult> groupFindings(OrganizationName organizationNam
// [START securitycenter_group_findings_with_source]
static ImmutableList<GroupResult> groupFindingsWithSource(SourceName sourceName) {
try (SecurityCenterClient client = SecurityCenterClient.create()) {
// SourceName sourceName = SourceName.of(/*organization=*/"123234324",/*source=*/
// "423432321");
// parentId: must be one of the following:
// "organization-id"
// "project-id"
// "folder-id"
// SourceName sourceName = SourceName.of(parentId, sourceId);

GroupFindingsRequest.Builder request =
GroupFindingsRequest.newBuilder().setParent(sourceName.toString()).setGroupBy("category");
Expand Down Expand Up @@ -422,8 +448,11 @@ static ImmutableList<GroupResult> groupFindingsWithSource(SourceName sourceName)
// [START securitycenter_group_active_findings_with_source]
static ImmutableList<GroupResult> groupActiveFindingsWithSource(SourceName sourceName) {
try (SecurityCenterClient client = SecurityCenterClient.create()) {
// SourceName sourceName = SourceName.of(/*organization=*/"123234324",/*source=*/
// "423432321");
// parentId: must be one of the following:
// "organization-id"
// "project-id"
// "folder-id"
// SourceName sourceName = SourceName.of(parentId, sourceId);

GroupFindingsRequest.Builder request =
GroupFindingsRequest.newBuilder()
Expand Down Expand Up @@ -457,8 +486,11 @@ static ImmutableList<GroupResult> groupActiveFindingsWithSource(SourceName sourc
// [START securitycenter_group_active_findings_with_source_at_time]
static ImmutableList<GroupResult> groupActiveFindingsWithSourceAtTime(SourceName sourceName) {
try (SecurityCenterClient client = SecurityCenterClient.create()) {
// SourceName sourceName = SourceName.of(/*organization=*/"123234324",/*source=*/
// "423432321");
// parentId: must be one of the following:
// "organization-id"
// "project-id"
// "folder-id"
// SourceName sourceName = SourceName.of(parentId, sourceId);

// 1 day ago
Instant oneDayAgo = Instant.now().minusSeconds(60 * 60 * 24);
Expand Down Expand Up @@ -500,8 +532,11 @@ static ImmutableList<GroupResult> groupActiveFindingsWithSourceAtTime(SourceName
static ImmutableList<GroupResult> groupActiveFindingsWithSourceAndCompareDuration(
SourceName sourceName, Duration duration) {
try (SecurityCenterClient client = SecurityCenterClient.create()) {
// SourceName sourceName = SourceName.of(/*organization=*/"123234324",/*source=*/
// "423432321");
// parentId: must be one of the following:
// "organization-id"
// "project-id"
// "folder-id"
// SourceName sourceName = SourceName.of(parentId, sourceId);

GroupFindingsRequest.Builder request =
GroupFindingsRequest.newBuilder()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
import com.google.protobuf.FieldMask;
import java.io.IOException;

/** Snippets for how to work with Organizations in Cloud Security Command Center. */
/** Snippets for how to work with Organizations in Security Command Center. */
public class OrganizationSnippets {

private OrganizationSnippets() {}
Expand Down