Search in sources :

Example 1 with SecurityMarks

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

the class SecurityMarkSnippets method deleteAndUpdateMarks.

// [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]
static SecurityMarks deleteAndUpdateMarks(String assetName) {
    // String assetName = "organizations/123123342/assets/12312321";
    try (SecurityCenterClient client = SecurityCenterClient.create()) {
        // Start setting up a request to clear and update security marks for an asset.
        // Create security mark and field mask for clearing security marks.
        SecurityMarks securityMarks = SecurityMarks.newBuilder().setName(assetName + "/securityMarks").putMarks("key_a", "new_value_for_a").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 updated and cleared:");
        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) FieldMask(com.google.protobuf.FieldMask)

Example 2 with SecurityMarks

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

the class SecurityMarkSnippets method addToAsset.

/**
 * Add security mark to an asset.
 *
 * @param assetName The asset resource to add the security mark for.
 */
// [START securitycenter_add_security_marks]
static SecurityMarks addToAsset(String assetName) {
    try (SecurityCenterClient client = SecurityCenterClient.create()) {
        // String assetName = "organizations/123123342/assets/12312321";
        // Start setting up a request to add security marks for an asset.
        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(assetName + "/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)

Example 3 with SecurityMarks

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

the class SecurityMarkSnippets method clearFromAsset.

// [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]
static SecurityMarks clearFromAsset(String assetName) {
    // String assetName = "organizations/123123342/assets/12312321";
    try (SecurityCenterClient client = SecurityCenterClient.create()) {
        // Start setting up a request to clear security marks for an asset.
        // Create security mark and field mask for clearing security marks.
        SecurityMarks securityMarks = SecurityMarks.newBuilder().setName(assetName + "/securityMarks").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 cleared:");
        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) FieldMask(com.google.protobuf.FieldMask)

Example 4 with SecurityMarks

use of com.google.cloud.securitycenter.v1.SecurityMarks 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)4 SecurityMarks (com.google.cloud.securitycenter.v1.SecurityMarks)4 UpdateSecurityMarksRequest (com.google.cloud.securitycenter.v1.UpdateSecurityMarksRequest)4 FieldMask (com.google.protobuf.FieldMask)4 IOException (java.io.IOException)4 ImmutableMap (com.google.common.collect.ImmutableMap)2