Search in sources :

Example 6 with Finding

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

the class FindingSnippets method updateFinding.

// [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]
static Finding updateFinding(FindingName findingName) {
    try (SecurityCenterClient client = SecurityCenterClient.create()) {
        // FindingName findingName = FindingName.of(/*organization=*/"123234324",
        // /*source=*/"423432321", /*findingId=*/"samplefindingid2");
        // Use the current time as the finding "event time".
        Instant eventTime = Instant.now();
        // Define source properties values as protobuf "Value" objects.
        Value stringValue = Value.newBuilder().setStringValue("value").build();
        FieldMask updateMask = FieldMask.newBuilder().addPaths("event_time").addPaths("source_properties.stringKey").build();
        Finding finding = Finding.newBuilder().setName(findingName.toString()).setEventTime(Timestamp.newBuilder().setSeconds(eventTime.getEpochSecond()).setNanos(eventTime.getNano())).putSourceProperties("stringKey", stringValue).build();
        UpdateFindingRequest.Builder request = UpdateFindingRequest.newBuilder().setFinding(finding).setUpdateMask(updateMask);
        // Call the API.
        Finding response = client.updateFinding(request.build());
        System.out.println("Updated Finding: " + response);
        return response;
    } catch (IOException e) {
        throw new RuntimeException("Couldn't create client.", e);
    }
}
Also used : UpdateFindingRequest(com.google.cloud.securitycenter.v1.UpdateFindingRequest) Instant(org.threeten.bp.Instant) Finding(com.google.cloud.securitycenter.v1.Finding) Value(com.google.protobuf.Value) IOException(java.io.IOException) SecurityCenterClient(com.google.cloud.securitycenter.v1.SecurityCenterClient) FieldMask(com.google.protobuf.FieldMask)

Example 7 with Finding

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

the class FindingSnippets method createFinding.

/**
 * Create a finding under a source.
 *
 * @param sourceName The source for the finding.
 */
// [START securitycenter_create_finding]
static Finding createFinding(SourceName sourceName, String findingId) {
    try (SecurityCenterClient client = SecurityCenterClient.create()) {
        // SourceName sourceName = SourceName.of(/*organization=*/"123234324",/*source=*/
        // "423432321");
        // String findingId = "samplefindingid";
        // Use the current time as the finding "event time".
        Instant eventTime = Instant.now();
        // The resource this finding applies to.  The CSCC UI can link
        // the findings for a resource to the corresponding Asset of a resource
        // if there are matches.
        String resourceName = "//cloudresourcemanager.googleapis.com/organizations/11232";
        // Start setting up a request to create a finding in a source.
        Finding finding = Finding.newBuilder().setParent(sourceName.toString()).setState(State.ACTIVE).setResourceName(resourceName).setEventTime(Timestamp.newBuilder().setSeconds(eventTime.getEpochSecond()).setNanos(eventTime.getNano())).setCategory("MEDIUM_RISK_ONE").build();
        // Call the API.
        Finding response = client.createFinding(sourceName, findingId, finding);
        System.out.println("Created Finding: " + response);
        return response;
    } catch (IOException e) {
        throw new RuntimeException("Couldn't create client.", e);
    }
}
Also used : Instant(org.threeten.bp.Instant) Finding(com.google.cloud.securitycenter.v1.Finding) IOException(java.io.IOException) SecurityCenterClient(com.google.cloud.securitycenter.v1.SecurityCenterClient)

Example 8 with Finding

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

the class FindingSnippets method createFindingWithSourceProperties.

// [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]
static Finding createFindingWithSourceProperties(SourceName sourceName) {
    try (SecurityCenterClient client = SecurityCenterClient.create()) {
        // SourceName sourceName = SourceName.of(/*organization=*/"123234324",/*source=*/
        // "423432321");
        // Use the current time as the finding "event time".
        Instant eventTime = Instant.now();
        // Controlled by caller.
        String findingId = "samplefindingid2";
        // The resource this finding applies to.  The CSCC UI can link
        // the findings for a resource to the corresponding Asset of a resource
        // if there are matches.
        String resourceName = "//cloudresourcemanager.googleapis.com/organizations/11232";
        // Define source properties values as protobuf "Value" objects.
        Value stringValue = Value.newBuilder().setStringValue("stringExample").build();
        Value numValue = Value.newBuilder().setNumberValue(1234).build();
        ImmutableMap<String, Value> sourceProperties = ImmutableMap.of("stringKey", stringValue, "numKey", numValue);
        // Start setting up a request to create a finding in a source.
        Finding finding = Finding.newBuilder().setParent(sourceName.toString()).setState(State.ACTIVE).setResourceName(resourceName).setEventTime(Timestamp.newBuilder().setSeconds(eventTime.getEpochSecond()).setNanos(eventTime.getNano())).putAllSourceProperties(sourceProperties).build();
        // Call the API.
        Finding response = client.createFinding(sourceName, findingId, finding);
        System.out.println("Created Finding with Source Properties: " + response);
        return response;
    } catch (IOException e) {
        throw new RuntimeException("Couldn't create client.", e);
    }
}
Also used : Instant(org.threeten.bp.Instant) Finding(com.google.cloud.securitycenter.v1.Finding) Value(com.google.protobuf.Value) IOException(java.io.IOException) SecurityCenterClient(com.google.cloud.securitycenter.v1.SecurityCenterClient)

Example 9 with Finding

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

the class SecurityMarkSnippets method addToFinding.

// [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_finding_security_marks]
static SecurityMarks addToFinding(FindingName findingName) {
    // /*source=*/"423432321", /*findingId=*/"samplefindingid2");
    try (SecurityCenterClient client = SecurityCenterClient.create()) {
        // Start setting up a request to add security marks for a finding.
        ImmutableMap markMap = ImmutableMap.of("key_a", "value_a", "key_b", "value_b");
        // Add security marks and field mask for security marks.
        SecurityMarks securityMarks = SecurityMarks.newBuilder().setName(findingName + "/securityMarks").putAllMarks(markMap).build();
        FieldMask updateMask = FieldMask.newBuilder().addPaths("marks.key_a").addPaths("marks.key_b").build();
        UpdateSecurityMarksRequest request = UpdateSecurityMarksRequest.newBuilder().setSecurityMarks(securityMarks).setUpdateMask(updateMask).build();
        // Call the API.
        SecurityMarks response = client.updateSecurityMarks(request);
        System.out.println("Security Marks:");
        System.out.println(response);
        return response;
    } catch (IOException e) {
        throw new RuntimeException("Couldn't create client.", e);
    }
}
Also used : SecurityMarks(com.google.cloud.securitycenter.v1.SecurityMarks) UpdateSecurityMarksRequest(com.google.cloud.securitycenter.v1.UpdateSecurityMarksRequest) IOException(java.io.IOException) SecurityCenterClient(com.google.cloud.securitycenter.v1.SecurityCenterClient) ImmutableMap(com.google.common.collect.ImmutableMap) FieldMask(com.google.protobuf.FieldMask)

Aggregations

SecurityCenterClient (com.google.cloud.securitycenter.v1.SecurityCenterClient)6 IOException (java.io.IOException)6 Finding (com.google.cloud.securitycenter.v1.Finding)4 Instant (org.threeten.bp.Instant)4 DlpServiceClient (com.google.cloud.dlp.v2.DlpServiceClient)3 ByteContentItem (com.google.privacy.dlp.v2.ByteContentItem)3 ContentItem (com.google.privacy.dlp.v2.ContentItem)3 Finding (com.google.privacy.dlp.v2.Finding)3 InspectConfig (com.google.privacy.dlp.v2.InspectConfig)3 InspectContentRequest (com.google.privacy.dlp.v2.InspectContentRequest)3 InspectContentResponse (com.google.privacy.dlp.v2.InspectContentResponse)3 FindingLimits (com.google.privacy.dlp.v2.InspectConfig.FindingLimits)2 InspectResult (com.google.privacy.dlp.v2.InspectResult)2 ByteString (com.google.protobuf.ByteString)2 FieldMask (com.google.protobuf.FieldMask)2 Value (com.google.protobuf.Value)2 ParseException (org.apache.commons.cli.ParseException)2 SecurityMarks (com.google.cloud.securitycenter.v1.SecurityMarks)1 UpdateFindingRequest (com.google.cloud.securitycenter.v1.UpdateFindingRequest)1 UpdateSecurityMarksRequest (com.google.cloud.securitycenter.v1.UpdateSecurityMarksRequest)1