diff --git a/google-cloud-examples/src/main/java/com/google/cloud/examples/securitycenter/snippets/AssetSnippets.java b/google-cloud-examples/src/main/java/com/google/cloud/examples/securitycenter/snippets/AssetSnippets.java index 1b97cb39e04e..956bcdb92653 100644 --- a/google-cloud-examples/src/main/java/com/google/cloud/examples/securitycenter/snippets/AssetSnippets.java +++ b/google-cloud-examples/src/main/java/com/google/cloud/examples/securitycenter/snippets/AssetSnippets.java @@ -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 listAssets(OrganizationName organizationName) { try (SecurityCenterClient client = SecurityCenterClient.create()) { @@ -66,12 +67,14 @@ static ImmutableList 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 listAssetsWithFilter(OrganizationName organizationName) { try (SecurityCenterClient client = SecurityCenterClient.create()) { @@ -98,6 +101,7 @@ static ImmutableList 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. @@ -105,6 +109,7 @@ static ImmutableList listAssetsWithFilter(OrganizationName org * @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 listAssetsAsOfYesterday( OrganizationName organizationName, Instant asOf) { @@ -138,6 +143,7 @@ static ImmutableList 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 @@ -146,6 +152,7 @@ static ImmutableList 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 listAssetAndStatusChanges( OrganizationName organizationName, Duration timeSpan, Instant asOf) { @@ -182,12 +189,14 @@ static ImmutableList 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 groupAssets(OrganizationName organizationName) { try (SecurityCenterClient client = SecurityCenterClient.create()) { @@ -213,6 +222,7 @@ static ImmutableList 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 @@ -220,6 +230,7 @@ static ImmutableList groupAssets(OrganizationName organizationName) * * @param organizationName The organization to group assets for. */ + // [START securitycenter_group_all_assets_with_filter] // [START group_all_assets_with_filter] static ImmutableList groupAssetsWithFilter(OrganizationName organizationName) { try (SecurityCenterClient client = SecurityCenterClient.create()) { @@ -248,6 +259,7 @@ static ImmutableList 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 @@ -255,6 +267,7 @@ static ImmutableList groupAssetsWithFilter(OrganizationName organiz * * @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 groupAssetsWithCompareDuration( OrganizationName organizationName, Duration duration) { @@ -286,7 +299,9 @@ static ImmutableList 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()) { @@ -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"); diff --git a/google-cloud-examples/src/main/java/com/google/cloud/examples/securitycenter/snippets/FindingSnippets.java b/google-cloud-examples/src/main/java/com/google/cloud/examples/securitycenter/snippets/FindingSnippets.java index 4980aa54205a..9034faf2cf02 100644 --- a/google-cloud-examples/src/main/java/com/google/cloud/examples/securitycenter/snippets/FindingSnippets.java +++ b/google-cloud-examples/src/main/java/com/google/cloud/examples/securitycenter/snippets/FindingSnippets.java @@ -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()) { @@ -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()) { @@ -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()) { @@ -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()) { @@ -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 listAllFindings(OrganizationName organizationName) { try (SecurityCenterClient client = SecurityCenterClient.create()) { @@ -248,12 +257,14 @@ static ImmutableList 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 listFilteredFindings(SourceName sourceName) { try (SecurityCenterClient client = SecurityCenterClient.create()) { @@ -281,12 +292,14 @@ static ImmutableList 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 listFindingsAtTime(SourceName sourceName) { try (SecurityCenterClient client = SecurityCenterClient.create()) { @@ -319,6 +332,7 @@ static ImmutableList 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 @@ -326,6 +340,7 @@ static ImmutableList listFindingsAtTime(SourceName sourceNam * * @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()) { @@ -348,6 +363,7 @@ 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. @@ -355,6 +371,7 @@ static TestIamPermissionsResponse testIamPermissions(SourceName sourceName) { * * @param organizationName The organizatoin to group all findings for. */ + // [START securitycenter_group_all_findings] // [START group_all_findings] static ImmutableList groupFindings(OrganizationName organizationName) { try (SecurityCenterClient client = SecurityCenterClient.create()) { @@ -380,6 +397,7 @@ static ImmutableList 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. @@ -387,6 +405,7 @@ static ImmutableList groupFindings(OrganizationName organizationNam * * @param sourceName The source to limit the findings to. */ + // [START securitycenter_group_findings_with_source] // [START group_findings_with_source] static ImmutableList groupFindingsWithSource(SourceName sourceName) { try (SecurityCenterClient client = SecurityCenterClient.create()) { @@ -412,6 +431,7 @@ static ImmutableList 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. @@ -419,6 +439,7 @@ static ImmutableList groupFindingsWithSource(SourceName sourceName) * * @param sourceName The source to limit the findings to. */ + // [START securitycenter_group_active_findings_with_source] // [START group_active_findings_with_source] static ImmutableList groupActiveFindingsWithSource(SourceName sourceName) { try (SecurityCenterClient client = SecurityCenterClient.create()) { @@ -447,6 +468,7 @@ static ImmutableList 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. @@ -454,6 +476,7 @@ static ImmutableList groupActiveFindingsWithSource(SourceName sourc * * @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 groupActiveFindingsWithSourceAtTime(SourceName sourceName) { try (SecurityCenterClient client = SecurityCenterClient.create()) { @@ -489,6 +512,7 @@ static ImmutableList 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 @@ -496,6 +520,7 @@ static ImmutableList groupActiveFindingsWithSourceAtTime(SourceName * * @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 groupActiveFindingsWithSourceAndCompareDuration( SourceName sourceName, Duration duration) { @@ -529,4 +554,5 @@ static ImmutableList groupActiveFindingsWithSourceAndCompareDuratio } } // [END group_active_findings_with_source_and_compare_duration] + // [END securitycenter_group_active_findings_with_source_and_compare_duration] } diff --git a/google-cloud-examples/src/main/java/com/google/cloud/examples/securitycenter/snippets/OrganizationSnippets.java b/google-cloud-examples/src/main/java/com/google/cloud/examples/securitycenter/snippets/OrganizationSnippets.java index 712323cc1bae..76c16f21e143 100644 --- a/google-cloud-examples/src/main/java/com/google/cloud/examples/securitycenter/snippets/OrganizationSnippets.java +++ b/google-cloud-examples/src/main/java/com/google/cloud/examples/securitycenter/snippets/OrganizationSnippets.java @@ -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()) { @@ -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()) { @@ -87,5 +90,6 @@ static OrganizationSettings updateOrganizationSettings(OrganizationName organiza } } // [END update_organization_settings] + // [END securitycenter_enable_asset_discovery] } diff --git a/google-cloud-examples/src/main/java/com/google/cloud/examples/securitycenter/snippets/SecurityMarkSnippets.java b/google-cloud-examples/src/main/java/com/google/cloud/examples/securitycenter/snippets/SecurityMarkSnippets.java index fe2babce754d..235a8482f54f 100644 --- a/google-cloud-examples/src/main/java/com/google/cloud/examples/securitycenter/snippets/SecurityMarkSnippets.java +++ b/google-cloud-examples/src/main/java/com/google/cloud/examples/securitycenter/snippets/SecurityMarkSnippets.java @@ -41,6 +41,7 @@ private SecurityMarkSnippets() {} * * @param assetName The asset resource to add the security mark for. */ + // [START securitycenter_add_security_marks] // [START add_to_asset] static SecurityMarks addToAsset(String assetName) { try (SecurityCenterClient client = SecurityCenterClient.create()) { @@ -74,12 +75,14 @@ static SecurityMarks addToAsset(String assetName) { } } // [END add_to_asset] + // [END securitycenter_add_security_marks] /** * Clear security marks for an asset. * * @param assetName The asset resource to clear the security marks for. */ + // [START securitycenter_delete_security_marks] // [START clear_from_asset] static SecurityMarks clearFromAsset(String assetName) { // String assetName = "organizations/123123342/assets/12312321"; @@ -108,12 +111,14 @@ static SecurityMarks clearFromAsset(String assetName) { } } // [END clear_from_asset] + // [END securitycenter_delete_security_marks] /** * Deletes and updates a security mark for an asset. * * @param assetName The asset resource path to update and remove the security marks for. */ + // [START securitycenter_add_delete_security_marks] // [START delete_and_update_marks] static SecurityMarks deleteAndUpdateMarks(String assetName) { // String assetName = "organizations/123123342/assets/12312321"; @@ -145,12 +150,14 @@ static SecurityMarks deleteAndUpdateMarks(String assetName) { } } // [END delete_and_update_marks] + // [END securitycenter_add_delete_security_marks] /** * Add security mark to a finding. * * @param findingName The finding resource path to add the security mark for. */ + // [START securitycenter_add_security_marks] // [START add_to_finding] static SecurityMarks addToFinding(FindingName findingName) { // FindingName findingName = FindingName.of(/*organization=*/"123234324", @@ -185,12 +192,14 @@ static SecurityMarks addToFinding(FindingName findingName) { } } // [END add_to_finding] + // [END securitycenter_add_security_marks] /** * Lists all assets with a filter on security marks. * * @param organizationName The organization to list assets for. */ + // [START securitycenter_list_assets_with_security_marks] // [START list_assets_with_filter] static ImmutableList listAssetsWithQueryMarks( OrganizationName organizationName) { @@ -218,12 +227,14 @@ static ImmutableList listAssetsWithQueryMarks( } } // [END list_assets_with_filter] + // [END securitycenter_list_assets_with_security_marks] /** * List all findings with a filter on security marks. * * @param sourceName The source to list filtered findings for. */ + // [START securitycenter_list_findings_with_security_marks] // [START list_filtered_findings] static ImmutableList listFindingsWithQueryMarks(SourceName sourceName) { try (SecurityCenterClient client = SecurityCenterClient.create()) { @@ -252,5 +263,6 @@ static ImmutableList listFindingsWithQueryMarks(SourceName s } } // [END list_filtered_findings] + // [END securitycenter_list_findings_with_security_marks] } diff --git a/google-cloud-examples/src/main/java/com/google/cloud/examples/securitycenter/snippets/SourceSnippets.java b/google-cloud-examples/src/main/java/com/google/cloud/examples/securitycenter/snippets/SourceSnippets.java index 0f6c84290aa2..8321b7088a6f 100644 --- a/google-cloud-examples/src/main/java/com/google/cloud/examples/securitycenter/snippets/SourceSnippets.java +++ b/google-cloud-examples/src/main/java/com/google/cloud/examples/securitycenter/snippets/SourceSnippets.java @@ -41,6 +41,7 @@ private SourceSnippets() {} * * @param organizationName The organization for the source. */ + // [START securitycenter_create_source] // [START create_source] static Source createSource(OrganizationName organizationName) { try (SecurityCenterClient client = SecurityCenterClient.create()) { @@ -65,12 +66,14 @@ static Source createSource(OrganizationName organizationName) { } } // [END create_source] + // [END securitycenter_create_source] /** * List sources under an organization. * * @param organizationName The organization for the source. */ + // [START securitycenter_list_sources] // [START list_source] static ImmutableList listSources(OrganizationName organizationName) { try (SecurityCenterClient client = SecurityCenterClient.create()) { @@ -94,12 +97,14 @@ static ImmutableList listSources(OrganizationName organizationName) { } } // [END list_source] + // [END securitycenter_list_sources] /** * Update a source under an organization. * * @param sourceName The source to update. */ + // [START securitycenter_update_source] // [START update_source] static Source updateSource(SourceName sourceName) { try (SecurityCenterClient client = SecurityCenterClient.create()) { @@ -126,12 +131,14 @@ static Source updateSource(SourceName sourceName) { } } // [END update_source] + // [END securitycenter_update_source] /** * Get a source under an organization. * * @param sourceName The source to get. */ + // [START securitycenter_get_source] // [START get_source] static Source getSource(SourceName sourceName) { try (SecurityCenterClient client = SecurityCenterClient.create()) { @@ -151,12 +158,14 @@ static Source getSource(SourceName sourceName) { } } // [END get_source] + // [END securitycenter_get_source] /** * Set IAM policy for a source. * * @param sourceName The source to set IAM Policy for. */ + // [START securitycenter_set_source_iam] // [START set_source_iam_policy] static Policy setIamPolicySource(SourceName sourceName, String userEmail) { try (SecurityCenterClient client = SecurityCenterClient.create()) { @@ -186,12 +195,14 @@ static Policy setIamPolicySource(SourceName sourceName, String userEmail) { } } // [END set_source_iam_policy] + // [END securitycenter_set_source_iam] /** * Get IAM policy for a source. * * @param sourceName The source to set IAM Policy for. */ + // [START securitycenter_get_source_iam] // [START get_source_iam_policy] static Policy getIamPolicySource(SourceName sourceName) { try (SecurityCenterClient client = SecurityCenterClient.create()) { @@ -211,5 +222,6 @@ static Policy getIamPolicySource(SourceName sourceName) { } } // [END get_source_iam_policy] + // [END securitycenter_get_source_iam] }