Search in sources :

Example 11 with GrafeasClient

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;
}
Also used : GrafeasClient(io.grafeas.v1.GrafeasClient) VulnerabilityNote(io.grafeas.v1.VulnerabilityNote) Note(io.grafeas.v1.Note)

Example 12 with GrafeasClient

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

Example 13 with GrafeasClient

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

Example 14 with GrafeasClient

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

Aggregations

GrafeasClient (io.grafeas.v1.GrafeasClient)14 Occurrence (io.grafeas.v1.Occurrence)9 NoteName (io.grafeas.v1.NoteName)5 Note (io.grafeas.v1.Note)3 DiscoveryOccurrence (io.grafeas.v1.DiscoveryOccurrence)2 AnalysisStatus (io.grafeas.v1.DiscoveryOccurrence.AnalysisStatus)2 OccurrenceName (io.grafeas.v1.OccurrenceName)2 VulnerabilityNote (io.grafeas.v1.VulnerabilityNote)2 VulnerabilityOccurrence (io.grafeas.v1.VulnerabilityOccurrence)2 LinkedList (java.util.LinkedList)2 TimeoutException (java.util.concurrent.TimeoutException)2 Test (org.junit.Test)2 DiscoveryNote (io.grafeas.v1.DiscoveryNote)1 GrafeasSettings (io.grafeas.v1.GrafeasSettings)1 ListNoteOccurrencesRequest (io.grafeas.v1.ListNoteOccurrencesRequest)1 Severity (io.grafeas.v1.Severity)1 Date (java.util.Date)1