/** * Creates and returns a new Occurrence of a previously created vulnerability Note * @param client The Grafeas client used to perform the API requests. * @param imageUrl the Container Registry URL associated with the image * example: "https://gcr.io/project/image@sha256:foo" * @param noteId the identifier of the Note associated with this Occurrence * @param occProjectId the GCP project the Occurrence will be created under * @param noteProjectId the GCP project the associated Note belongs to * @return the newly created Occurrence object */ public static Occurrence createOccurrence(GrafeasV1Beta1Client client, String imageUrl, String noteId, String occProjectId, String noteProjectId) { final NoteName noteName = NoteName.of(noteProjectId, noteId); final String occProjectName = ProjectName.format(occProjectId); Occurrence.Builder occBuilder = Occurrence.newBuilder(); occBuilder.setNoteName(noteName.toString()); Details.Builder detailsBuilder = Details.newBuilder(); // Details about the vulnerability instance can be added here occBuilder.setVulnerability(detailsBuilder); // Attach the occurrence to the associated image uri Resource.Builder resourceBuilder = Resource.newBuilder(); resourceBuilder.setUri(imageUrl); occBuilder.setResource(resourceBuilder); Occurrence newOcc = occBuilder.build(); return client.createOccurrence(occProjectName, newOcc); } // [END create_occurrence]