Skip to content
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ private AssetSnippets() {}
*
* @param organizationName The organization to list assets for.
*/
// [START securitycenter_list_all_assets]
// [START list_all_assets]
static ImmutableList<ListAssetsResult> listAssets(OrganizationName organizationName) {
try (SecurityCenterClient client = SecurityCenterClient.create()) {
Expand All @@ -66,12 +67,14 @@ static ImmutableList<ListAssetsResult> listAssets(OrganizationName organizationN
}
}
// [END list_all_assets]
// [END securitycenter_list_all_assets]

/**
* Lists all project assets for an organization.
*
* @param organizationName The organization to list assets for.
*/
// [START securitycenter_list_assets_with_filter]
// [START list_assets_with_filter]
static ImmutableList<ListAssetsResult> listAssetsWithFilter(OrganizationName organizationName) {
try (SecurityCenterClient client = SecurityCenterClient.create()) {
Expand All @@ -98,13 +101,15 @@ static ImmutableList<ListAssetsResult> listAssetsWithFilter(OrganizationName org
}
}
// [END list_assets_with_filter]
// [END securitycenter_list_assets_with_filter]

/**
* Lists all project assets for an organization at a given point in time.
*
* @param organizationName The organization to list assets for.
* @param asOf The snapshot time to query for assets. If null defaults to one day ago.
*/
// [START securitycenter_list_assets_at_time]
// [START list_assets_as_of_time]
static ImmutableList<ListAssetsResult> listAssetsAsOfYesterday(
OrganizationName organizationName, Instant asOf) {
Expand Down Expand Up @@ -138,6 +143,7 @@ static ImmutableList<ListAssetsResult> listAssetsAsOfYesterday(
}
}
// [END list_assets_as_of_time]
// [END securitycenter_list_assets_at_time]

/**
* Returns Assets and metadata about assets activity (e.g. added, removed, no change) between
Expand All @@ -146,6 +152,7 @@ static ImmutableList<ListAssetsResult> listAssetsAsOfYesterday(
* @param timeSpan The time-range to compare assets over.
* @param asOf The instant in time to query for. If null, current time is assumed.
*/
// [START securitycenter_list_assets_and_changes]
// [START list_asset_changes_status_changes]
static ImmutableList<ListAssetsResult> listAssetAndStatusChanges(
OrganizationName organizationName, Duration timeSpan, Instant asOf) {
Expand Down Expand Up @@ -182,12 +189,14 @@ static ImmutableList<ListAssetsResult> listAssetAndStatusChanges(
}
}
// [END list_asset_changes_status_changes]
// [END securitycenter_list_assets_and_changes]

/**
* Groups all assets by their specified properties (e.g. type) for an organization.
*
* @param organizationName The organization to group assets for.
*/
// [START securitycenter_group_all_assets]
// [START group_all_assets]
static ImmutableList<GroupResult> groupAssets(OrganizationName organizationName) {
try (SecurityCenterClient client = SecurityCenterClient.create()) {
Expand All @@ -213,13 +222,15 @@ static ImmutableList<GroupResult> groupAssets(OrganizationName organizationName)
}
}
// [END group_all_assets]
// [END securitycenter_group_all_assets]

/**
* Filters all assets by their specified properties and groups them by specified properties for an
* organization.
*
* @param organizationName The organization to group assets for.
*/
// [START securitycenter_group_all_assets_with_filter]
// [START group_all_assets_with_filter]
static ImmutableList<GroupResult> groupAssetsWithFilter(OrganizationName organizationName) {
try (SecurityCenterClient client = SecurityCenterClient.create()) {
Expand Down Expand Up @@ -248,13 +259,15 @@ static ImmutableList<GroupResult> groupAssetsWithFilter(OrganizationName organiz
}
}
// [END group_all_assets_with_filter]
// [END securitycenter_group_all_assets_with_filter]

/**
* Groups all assets by their state_changes (ADDED/DELETED/ACTIVE) during a period of time for an
* organization.
*
* @param organizationName The organization to group assets for.
*/
// [START securitycenter_group_all_assets_with_compare_duration]
// [START group_all_assets_with_compare_duration]
static ImmutableList<GroupResult> groupAssetsWithCompareDuration(
OrganizationName organizationName, Duration duration) {
Expand Down Expand Up @@ -286,7 +299,9 @@ static ImmutableList<GroupResult> groupAssetsWithCompareDuration(
}
}
// [END group_all_assets_with_compare_duration]
// [END securitycenter_group_all_assets_with_compare_duration]

// [START securitycenter_run_asset_discovery]
// [START run_asset_discovery]
static void runAssetDiscovery(OrganizationName organizationName) {
try (SecurityCenterClient client = SecurityCenterClient.create()) {
Expand All @@ -306,6 +321,7 @@ static void runAssetDiscovery(OrganizationName organizationName) {
}
}
// [END run_asset_discovery]
// [END securitycenter_run_asset_discovery]

public static void main(String... args) {
String org_id = System.getenv("ORGANIZATION_ID");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ private FindingSnippets() {}
*
* @param sourceName The source for the finding.
*/
// [START securitycenter_create_finding]
// [START create_finding]
static Finding createFinding(SourceName sourceName, String findingId) {
try (SecurityCenterClient client = SecurityCenterClient.create()) {
Expand Down Expand Up @@ -87,12 +88,14 @@ static Finding createFinding(SourceName sourceName, String findingId) {
}
}
// [END create_finding]
// [END securitycenter_create_finding]

/**
* Create a finding with source properties under a source.
*
* @param sourceName The source for the finding.
*/
// [START securitycenter_create_finding_with_source_properties]
// [START create_finding_with_source_properties]
static Finding createFindingWithSourceProperties(SourceName sourceName) {
try (SecurityCenterClient client = SecurityCenterClient.create()) {
Expand Down Expand Up @@ -139,12 +142,14 @@ static Finding createFindingWithSourceProperties(SourceName sourceName) {
}
}
// [END create_finding_with_source_properties]
// [END securitycenter_create_finding_with_source_properties]

/**
* Update a finding's source properties.
*
* @param findingName The finding to update.
*/
// [START securitycenter_update_finding_source_properties]
// [START update_finding]
static Finding updateFinding(FindingName findingName) {
try (SecurityCenterClient client = SecurityCenterClient.create()) {
Expand Down Expand Up @@ -186,12 +191,14 @@ static Finding updateFinding(FindingName findingName) {
}
}
// [END update_finding]
// [END securitycenter_update_finding_source_properties]

/**
* Updates a finding's state to INACTIVE.
*
* @param findingName The finding to update.
*/
// [START securitycenter_update_finding_state]
// [START update_finding_state]
static Finding setFindingState(FindingName findingName) {
try (SecurityCenterClient client = SecurityCenterClient.create()) {
Expand All @@ -217,12 +224,14 @@ static Finding setFindingState(FindingName findingName) {
}
}
// [END update_finding_state]
// [END securitycenter_update_finding_state]

/**
* List all findings under an organization.
*
* @param organizationName The source to list all findings for.
*/
// [START securitycenter_list_all_findings]
// [START list_all_findings]
static ImmutableList<ListFindingsResult> listAllFindings(OrganizationName organizationName) {
try (SecurityCenterClient client = SecurityCenterClient.create()) {
Expand All @@ -248,12 +257,14 @@ static ImmutableList<ListFindingsResult> listAllFindings(OrganizationName organi
}
}
// [END list_all_findings]
// [END securitycenter_list_all_findings]

/**
* List filtered findings under a source.
*
* @param sourceName The source to list filtered findings for.
*/
// [START securitycenter_list_filtered_findings]
// [START list_filtered_findings]
static ImmutableList<ListFindingsResult> listFilteredFindings(SourceName sourceName) {
try (SecurityCenterClient client = SecurityCenterClient.create()) {
Expand Down Expand Up @@ -281,12 +292,14 @@ static ImmutableList<ListFindingsResult> listFilteredFindings(SourceName sourceN
}
}
// [END list_filtered_findings]
// [END securitycenter_list_filtered_findings]

/**
* List findings at a specific time under a source.
*
* @param sourceName The source to list findings at a specific time for.
*/
// [START securitycenter_list_findings_at_time]
// [START list_findings_at_time]
static ImmutableList<ListFindingsResult> listFindingsAtTime(SourceName sourceName) {
try (SecurityCenterClient client = SecurityCenterClient.create()) {
Expand Down Expand Up @@ -319,13 +332,15 @@ static ImmutableList<ListFindingsResult> listFindingsAtTime(SourceName sourceNam
}
}
// [END list_findings_at_time]
// [END securitycenter_list_findings_at_time]

/**
* Demonstrate calling testIamPermissions to determin if the service account has the correct
* permissions.
*
* @param sourceName The source to create a finding for.
*/
// [START securitycenter_test_iam]
// [START test_iam_permissions]
static TestIamPermissionsResponse testIamPermissions(SourceName sourceName) {
try (SecurityCenterClient client = SecurityCenterClient.create()) {
Expand All @@ -348,13 +363,15 @@ static TestIamPermissionsResponse testIamPermissions(SourceName sourceName) {
}
}
// [END test_iam_permissions]
// [END securitycenter_test_iam]

/**
* 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.
*/
// [START securitycenter_group_all_findings]
// [START group_all_findings]
static ImmutableList<GroupResult> groupFindings(OrganizationName organizationName) {
try (SecurityCenterClient client = SecurityCenterClient.create()) {
Expand All @@ -380,13 +397,15 @@ static ImmutableList<GroupResult> groupFindings(OrganizationName organizationNam
}
}
// [END group_all_findings]
// [END securitycenter_group_all_findings]

/**
* Group findings under an organization and a source by their specified properties (e.g.
* category).
*
* @param sourceName The source to limit the findings to.
*/
// [START securitycenter_group_findings_with_source]
// [START group_findings_with_source]
static ImmutableList<GroupResult> groupFindingsWithSource(SourceName sourceName) {
try (SecurityCenterClient client = SecurityCenterClient.create()) {
Expand All @@ -412,13 +431,15 @@ static ImmutableList<GroupResult> groupFindingsWithSource(SourceName sourceName)
}
}
// [END group_findings_with_source]
// [END securitycenter_group_findings_with_source]

/**
* Group active findings under an organization and a source by their specified properties (e.g.
* category).
*
* @param sourceName The source to limit the findings to.
*/
// [START securitycenter_group_active_findings_with_source]
// [START group_active_findings_with_source]
static ImmutableList<GroupResult> groupActiveFindingsWithSource(SourceName sourceName) {
try (SecurityCenterClient client = SecurityCenterClient.create()) {
Expand Down Expand Up @@ -447,13 +468,15 @@ static ImmutableList<GroupResult> groupActiveFindingsWithSource(SourceName sourc
}
}
// [END group_active_findings_with_source]
// [END securitycenter_group_active_findings_with_source]

/**
* Group active findings under an organization and a source by their specified properties (e.g.
* category) at a specified time.
*
* @param sourceName The source to limit the findings to.
*/
// [START securitycenter_group_active_findings_with_source_at_time]
// [START group_active_findings_with_source_at_time]
static ImmutableList<GroupResult> groupActiveFindingsWithSourceAtTime(SourceName sourceName) {
try (SecurityCenterClient client = SecurityCenterClient.create()) {
Expand Down Expand Up @@ -489,13 +512,15 @@ static ImmutableList<GroupResult> groupActiveFindingsWithSourceAtTime(SourceName
}
}
// [END group_active_findings_with_source_at_time]
// [END securitycenter_group_active_findings_with_source_at_time]

/**
* Group active findings under an organization and a source by their state_changes
* (ADDED/CHANGED/UNCHANGED) during a period.
*
* @param sourceName The source to limit the findings to.
*/
// [START securitycenter_group_active_findings_with_source_and_compare_duration]
// [START group_active_findings_with_source_and_compare_duration]
static ImmutableList<GroupResult> groupActiveFindingsWithSourceAndCompareDuration(
SourceName sourceName, Duration duration) {
Expand Down Expand Up @@ -529,4 +554,5 @@ static ImmutableList<GroupResult> groupActiveFindingsWithSourceAndCompareDuratio
}
}
// [END group_active_findings_with_source_and_compare_duration]
// [END securitycenter_group_active_findings_with_source_and_compare_duration]
}
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ private OrganizationSnippets() {}
*
* @param organizationName The organization to get settings for.
*/
// [START securitycenter_get_org_settings]
// [START get_organization_settings]
static OrganizationSettings getOrganizationSettings(OrganizationName organizationName) {
try (SecurityCenterClient client = SecurityCenterClient.create()) {
Expand All @@ -53,12 +54,14 @@ static OrganizationSettings getOrganizationSettings(OrganizationName organizatio
}
}
// [END get_organization_settings]
// [END securitycenter_get_org_settings]

/**
* Update Asset Discovery OrganizationSettings for an organization
*
* @param organizationName The organization to update settings for.
*/
// [START securitycenter_enable_asset_discovery]
// [START update_organization_settings]
static OrganizationSettings updateOrganizationSettings(OrganizationName organizationName) {
try (SecurityCenterClient client = SecurityCenterClient.create()) {
Expand Down Expand Up @@ -87,5 +90,6 @@ static OrganizationSettings updateOrganizationSettings(OrganizationName organiza
}
}
// [END update_organization_settings]
// [END securitycenter_enable_asset_discovery]

}
Loading