Search in sources :

Example 1 with VulnerabilityOccurrence

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()));
        }
    }
}
Also used : VulnerabilityOccurrence(io.grafeas.v1.VulnerabilityOccurrence) Occurrence(io.grafeas.v1.Occurrence) VulnerabilityOccurrence(io.grafeas.v1.VulnerabilityOccurrence)

Aggregations

Occurrence (io.grafeas.v1.Occurrence)1 VulnerabilityOccurrence (io.grafeas.v1.VulnerabilityOccurrence)1