use of io.grafeas.v1.GrafeasClient in project java-docs-samples by GoogleCloudPlatform.
the class CreateNote method createNote.
// Creates and returns a new Note
public static Note createNote(String noteId, String projectId) throws IOException, InterruptedException {
// String noteId = "my-note";
// String projectId = "my-project-id";
final String projectName = ProjectName.format(projectId);
Note newNote = Note.newBuilder().setVulnerability(VulnerabilityNote.newBuilder().addDetails(VulnerabilityNote.Detail.newBuilder().setAffectedCpeUri("your-uri-here").setAffectedPackage("your-package-here").setAffectedVersionStart(Version.newBuilder().setKind(Version.VersionKind.MINIMUM)).setAffectedVersionEnd(Version.newBuilder().setKind(Version.VersionKind.MAXIMUM)))).build();
// Initialize client that will be used to send requests. After completing all of your requests,
// call the "close" method on the client to safely clean up any remaining background resources.
GrafeasClient client = ContainerAnalysisClient.create().getGrafeasClient();
Note result = client.createNote(projectName, noteId, newNote);
return result;
}
use of io.grafeas.v1.GrafeasClient in project java-docs-samples by GoogleCloudPlatform.
the class DeleteNote method deleteNote.
// Deletes an existing Note from the server
public static void deleteNote(String noteId, String projectId) throws IOException, InterruptedException {
// String noteId = "my-note";
// String projectId = "my-project-id";
final NoteName noteName = NoteName.of(projectId, noteId);
// Initialize client that will be used to send requests. After completing all of your requests,
// call the "close" method on the client to safely clean up any remaining background resources.
GrafeasClient client = ContainerAnalysisClient.create().getGrafeasClient();
client.deleteNote(noteName);
}
use of io.grafeas.v1.GrafeasClient in project java-docs-samples by GoogleCloudPlatform.
the class GetDiscoveryInfo method getDiscoveryInfo.
// Retrieves and prints the Discovery Occurrence created for a specified image
// The Discovery Occurrence contains information about the initial scan on the image
public static void getDiscoveryInfo(String resourceUrl, String projectId) throws IOException, InterruptedException {
// String resourceUrl = "https://gcr.io/project/image@sha256:123";
// String projectId = "my-project-id";
String filterStr = "kind=\"DISCOVERY\" AND resourceUrl=\"" + resourceUrl + "\"";
final String projectName = ProjectName.format(projectId);
// Initialize client that will be used to send requests. After completing all of your requests,
// call the "close" method on the client to safely clean up any remaining background resources.
GrafeasClient client = ContainerAnalysisClient.create().getGrafeasClient();
for (Occurrence o : client.listOccurrences(projectName, filterStr).iterateAll()) {
System.out.println(o);
}
}
use of io.grafeas.v1.GrafeasClient in project java-docs-samples by GoogleCloudPlatform.
the class OccurrencesForImage method getOccurrencesForImage.
// Retrieves all the Occurrences associated with a specified image
// Here, all Occurrences are simply printed and counted
public static int getOccurrencesForImage(String resourceUrl, String projectId) throws IOException, InterruptedException {
// String resourceUrl = "https://gcr.io/project/image@sha256:123";
// String projectId = "my-project-id";
final String projectName = ProjectName.format(projectId);
final String filterStr = String.format("resourceUrl=\"%s\"", resourceUrl);
// Initialize client that will be used to send requests. After completing all of your requests,
// call the "close" method on the client to safely clean up any remaining background resources.
GrafeasClient client = ContainerAnalysisClient.create().getGrafeasClient();
int i = 0;
for (Occurrence o : client.listOccurrences(projectName, filterStr).iterateAll()) {
// Write custom code to process each Occurrence here
System.out.println(o.getName());
i = i + 1;
}
return i;
}
Aggregations