Search in sources :

Example 16 with SecurityCenterClient

use of com.google.cloud.securitycenter.v1.SecurityCenterClient in project google-cloud-java by GoogleCloudPlatform.

the class SourceSnippets method getIamPolicySource.

// [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]
static Policy getIamPolicySource(SourceName sourceName) {
    try (SecurityCenterClient client = SecurityCenterClient.create()) {
        // Start setting up a request to get IAM policy for a source.
        // SourceName sourceName = SourceName.of(/*organization=*/"123234324",/*source=*/
        // "423432321");
        GetIamPolicyRequest request = GetIamPolicyRequest.newBuilder().setResource(sourceName.toString()).build();
        // Call the API.
        Policy response = client.getIamPolicy(request);
        System.out.println("Policy: " + response);
        return response;
    } catch (IOException e) {
        throw new RuntimeException("Couldn't create client.", e);
    }
}
Also used : Policy(com.google.iam.v1.Policy) IOException(java.io.IOException) GetIamPolicyRequest(com.google.iam.v1.GetIamPolicyRequest) SecurityCenterClient(com.google.cloud.securitycenter.v1.SecurityCenterClient)

Example 17 with SecurityCenterClient

use of com.google.cloud.securitycenter.v1.SecurityCenterClient in project google-cloud-java by GoogleCloudPlatform.

the class SourceSnippets method getSource.

// [END securitycenter_update_source]
/**
 * Get a source under an organization.
 *
 * @param sourceName The source to get.
 */
// [START securitycenter_get_source]
static Source getSource(SourceName sourceName) {
    try (SecurityCenterClient client = SecurityCenterClient.create()) {
        // Start setting up a request to get a source.
        // SourceName sourceName = SourceName.of(/*organization=*/"123234324",/*source=*/
        // "423432321");
        GetSourceRequest.Builder request = GetSourceRequest.newBuilder().setName(sourceName.toString());
        // Call the API.
        Source response = client.getSource(request.build());
        System.out.println("Source: " + response);
        return response;
    } catch (IOException e) {
        throw new RuntimeException("Couldn't create client.", e);
    }
}
Also used : GetSourceRequest(com.google.cloud.securitycenter.v1.GetSourceRequest) IOException(java.io.IOException) SecurityCenterClient(com.google.cloud.securitycenter.v1.SecurityCenterClient) Source(com.google.cloud.securitycenter.v1.Source)

Example 18 with SecurityCenterClient

use of com.google.cloud.securitycenter.v1.SecurityCenterClient in project google-cloud-java by GoogleCloudPlatform.

the class SourceSnippets method createSource.

/**
 * Create a source under an organization.
 *
 * @param organizationName The organization for the source.
 */
// [START securitycenter_create_source]
static Source createSource(OrganizationName organizationName) {
    try (SecurityCenterClient client = SecurityCenterClient.create()) {
        // Start setting up a request to create a source in an organization.
        // OrganizationName organizationName = OrganizationName.of(/*organizationId=*/"123234324");
        Source source = Source.newBuilder().setDisplayName("Customized Display Name").setDescription("A new custom source that does X").build();
        CreateSourceRequest.Builder request = CreateSourceRequest.newBuilder().setParent(organizationName.toString()).setSource(source);
        // Call the API.
        Source response = client.createSource(request.build());
        System.out.println("Created Source: " + response);
        return response;
    } catch (IOException e) {
        throw new RuntimeException("Couldn't create client.", e);
    }
}
Also used : IOException(java.io.IOException) SecurityCenterClient(com.google.cloud.securitycenter.v1.SecurityCenterClient) CreateSourceRequest(com.google.cloud.securitycenter.v1.CreateSourceRequest) Source(com.google.cloud.securitycenter.v1.Source)

Example 19 with SecurityCenterClient

use of com.google.cloud.securitycenter.v1.SecurityCenterClient in project google-cloud-java by GoogleCloudPlatform.

the class FindingSnippets method groupActiveFindingsWithSourceAtTime.

// [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]
static ImmutableList<GroupResult> groupActiveFindingsWithSourceAtTime(SourceName sourceName) {
    try (SecurityCenterClient client = SecurityCenterClient.create()) {
        // SourceName sourceName = SourceName.of(/*organization=*/"123234324",/*source=*/
        // "423432321");
        // 1 day ago
        Instant oneDayAgo = Instant.now().minusSeconds(60 * 60 * 24);
        GroupFindingsRequest.Builder request = GroupFindingsRequest.newBuilder().setParent(sourceName.toString()).setGroupBy("category").setFilter("state=\"ACTIVE\"").setReadTime(Timestamp.newBuilder().setSeconds(oneDayAgo.getEpochSecond()).setNanos(oneDayAgo.getNano()));
        // Call the API.
        GroupFindingsPagedResponse response = client.groupFindings(request.build());
        // This creates one list for all findings.  If your organization has a large number of
        // findings
        // this can cause out of memory issues.  You can process them batches by returning
        // the Iterable returned response.iterateAll() directly.
        ImmutableList<GroupResult> results = ImmutableList.copyOf(response.iterateAll());
        System.out.println("Findings:");
        System.out.println(results);
        return results;
    } catch (IOException e) {
        throw new RuntimeException("Couldn't create client.", e);
    }
}
Also used : Instant(org.threeten.bp.Instant) GroupFindingsRequest(com.google.cloud.securitycenter.v1.GroupFindingsRequest) GroupResult(com.google.cloud.securitycenter.v1.GroupResult) GroupFindingsPagedResponse(com.google.cloud.securitycenter.v1.SecurityCenterClient.GroupFindingsPagedResponse) IOException(java.io.IOException) SecurityCenterClient(com.google.cloud.securitycenter.v1.SecurityCenterClient)

Example 20 with SecurityCenterClient

use of com.google.cloud.securitycenter.v1.SecurityCenterClient in project google-cloud-java by GoogleCloudPlatform.

the class FindingSnippets method listFindingsAtTime.

// [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]
static ImmutableList<ListFindingsResult> listFindingsAtTime(SourceName sourceName) {
    try (SecurityCenterClient client = SecurityCenterClient.create()) {
        // SourceName sourceName = SourceName.of(/*organizationId=*/"123234324",
        // /*sourceId=*/"423432321");
        // 5 days ago
        Instant fiveDaysAgo = Instant.now().minus(Duration.ofDays(5));
        ListFindingsRequest.Builder request = ListFindingsRequest.newBuilder().setParent(sourceName.toString()).setReadTime(Timestamp.newBuilder().setSeconds(fiveDaysAgo.getEpochSecond()).setNanos(fiveDaysAgo.getNano()));
        // Call the API.
        ListFindingsPagedResponse response = client.listFindings(request.build());
        // This creates one list for all findings.  If your organization has a large number of
        // findings this can cause out of memory issues.  You can process them in incrementally
        // by returning the Iterable returned response.iterateAll() directly.
        ImmutableList<ListFindingsResult> results = ImmutableList.copyOf(response.iterateAll());
        System.out.println("Findings:");
        System.out.println(results);
        return results;
    } catch (IOException e) {
        throw new RuntimeException("Couldn't create client.", e);
    }
}
Also used : Instant(org.threeten.bp.Instant) ListFindingsRequest(com.google.cloud.securitycenter.v1.ListFindingsRequest) IOException(java.io.IOException) SecurityCenterClient(com.google.cloud.securitycenter.v1.SecurityCenterClient) ListFindingsPagedResponse(com.google.cloud.securitycenter.v1.SecurityCenterClient.ListFindingsPagedResponse) ListFindingsResult(com.google.cloud.securitycenter.v1.ListFindingsResponse.ListFindingsResult)

Aggregations

SecurityCenterClient (com.google.cloud.securitycenter.v1.SecurityCenterClient)35 IOException (java.io.IOException)35 GroupResult (com.google.cloud.securitycenter.v1.GroupResult)8 FieldMask (com.google.protobuf.FieldMask)7 Instant (org.threeten.bp.Instant)6 GroupFindingsRequest (com.google.cloud.securitycenter.v1.GroupFindingsRequest)5 ListAssetsRequest (com.google.cloud.securitycenter.v1.ListAssetsRequest)5 ListAssetsResult (com.google.cloud.securitycenter.v1.ListAssetsResponse.ListAssetsResult)5 GroupFindingsPagedResponse (com.google.cloud.securitycenter.v1.SecurityCenterClient.GroupFindingsPagedResponse)5 ListAssetsPagedResponse (com.google.cloud.securitycenter.v1.SecurityCenterClient.ListAssetsPagedResponse)5 Finding (com.google.cloud.securitycenter.v1.Finding)4 ListFindingsRequest (com.google.cloud.securitycenter.v1.ListFindingsRequest)4 ListFindingsResult (com.google.cloud.securitycenter.v1.ListFindingsResponse.ListFindingsResult)4 ListFindingsPagedResponse (com.google.cloud.securitycenter.v1.SecurityCenterClient.ListFindingsPagedResponse)4 SecurityMarks (com.google.cloud.securitycenter.v1.SecurityMarks)4 Source (com.google.cloud.securitycenter.v1.Source)4 UpdateSecurityMarksRequest (com.google.cloud.securitycenter.v1.UpdateSecurityMarksRequest)4 GroupAssetsRequest (com.google.cloud.securitycenter.v1.GroupAssetsRequest)3 GroupAssetsPagedResponse (com.google.cloud.securitycenter.v1.SecurityCenterClient.GroupAssetsPagedResponse)3 OrganizationSettings (com.google.cloud.securitycenter.v1.OrganizationSettings)2