use of io.grafeas.v1.VulnerabilityOccurrence in project java-docs-samples by GoogleCloudPlatform.
the class VulnerabilityFunction method accept.
@Override
public void accept(PubSubMessage payload, Context context) {
String json = new String(Base64.getDecoder().decode(payload.getData()), StandardCharsets.UTF_8);
OccurrenceNotification notification = gson.fromJson(json, OccurrenceNotification.class);
// Retrieve the occurrence detials from the notification
// https://cloud.google.com/container-registry/docs/reference/rest/v1/projects.occurrences#Occurrence
Occurrence occurrence = grafeasClient.getOccurrence(notification.getName());
// If the occurence is a vulnerability, output the log line base on severity
if (NoteKind.VULNERABILITY.equals(occurrence.getKind())) {
VulnerabilityOccurrence vulnerability = occurrence.getVulnerability();
if (vulnerability.getSeverity().getNumber() >= Severity.HIGH_VALUE) {
logger.warning(String.format("Image: %s, CVE: %s, Severity: %s", occurrence.getResourceUri(), vulnerability.getShortDescription(), vulnerability.getSeverity()));
}
}
}
Aggregations