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);
}
}
Aggregations