Search in sources :

Example 41 with Source

use of com.google.cloud.securitycenter.v1.Source 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)20 IOException (java.io.IOException)20 Test (org.junit.Test)17 Source (hex.glm.GLM2.Source)11 Source (org.orcid.jaxb.model.common_v2.Source)10 Instant (org.threeten.bp.Instant)6 SourceClientId (org.orcid.jaxb.model.common_v2.SourceClientId)5 Finding (com.google.cloud.securitycenter.v1.Finding)4 GroupFindingsRequest (com.google.cloud.securitycenter.v1.GroupFindingsRequest)4 GroupResult (com.google.cloud.securitycenter.v1.GroupResult)4 ListFindingsRequest (com.google.cloud.securitycenter.v1.ListFindingsRequest)4 ListFindingsResult (com.google.cloud.securitycenter.v1.ListFindingsResponse.ListFindingsResult)4 GroupFindingsPagedResponse (com.google.cloud.securitycenter.v1.SecurityCenterClient.GroupFindingsPagedResponse)4 ListFindingsPagedResponse (com.google.cloud.securitycenter.v1.SecurityCenterClient.ListFindingsPagedResponse)4 Source (com.google.cloud.securitycenter.v1.Source)4 FieldMask (com.google.protobuf.FieldMask)3 SourceName (org.orcid.jaxb.model.common_v2.SourceName)3 Items (org.orcid.jaxb.model.notification.permission_v2.Items)3 NotificationPermission (org.orcid.jaxb.model.notification.permission_v2.NotificationPermission)3 Policy (com.google.iam.v1.Policy)2