public static List<String> toStringList(List<NoteName> values) { List<String> list = new ArrayList<String>(values.size()); for (NoteName value : values) { if (value == null) { list.add(""); } else { list.add(value.toString()); } } return list; }
public static String format(String project, String note) { return newBuilder().setProject(project).setNote(note).build().toString(); }
/** * Deletes the specified note. * * <p>Sample code: * * <pre><code> * try (GrafeasV1Beta1Client grafeasV1Beta1Client = GrafeasV1Beta1Client.create()) { * NoteName name = NoteName.of("[PROJECT]", "[NOTE]"); * grafeasV1Beta1Client.deleteNote(name); * } * </code></pre> * * @param name The name of the note in the form of `projects/[PROVIDER_ID]/notes/[NOTE_ID]`. * @throws com.google.api.gax.rpc.ApiException if the remote call fails */ public final void deleteNote(NoteName name) { DeleteNoteRequest request = DeleteNoteRequest.newBuilder().setName(name == null ? null : name.toString()).build(); deleteNote(request); }
/** * Gets the specified note. * * <p>Sample code: * * <pre><code> * try (GrafeasV1Beta1Client grafeasV1Beta1Client = GrafeasV1Beta1Client.create()) { * NoteName name = NoteName.of("[PROJECT]", "[NOTE]"); * Note response = grafeasV1Beta1Client.getNote(name); * } * </code></pre> * * @param name The name of the note in the form of `projects/[PROVIDER_ID]/notes/[NOTE_ID]`. * @throws com.google.api.gax.rpc.ApiException if the remote call fails */ public final Note getNote(NoteName name) { GetNoteRequest request = GetNoteRequest.newBuilder().setName(name == null ? null : name.toString()).build(); return getNote(request); }
/** * Lists occurrences referencing the specified note. Provider projects can use this method to get * all occurrences across consumer projects referencing the specified note. * * <p>Sample code: * * <pre><code> * try (GrafeasV1Beta1Client grafeasV1Beta1Client = GrafeasV1Beta1Client.create()) { * NoteName name = NoteName.of("[PROJECT]", "[NOTE]"); * String filter = ""; * for (Occurrence element : grafeasV1Beta1Client.listNoteOccurrences(name, filter).iterateAll()) { * // doThingsWith(element); * } * } * </code></pre> * * @param name The name of the note to list occurrences for in the form of * `projects/[PROVIDER_ID]/notes/[NOTE_ID]`. * @param filter The filter expression. * @throws com.google.api.gax.rpc.ApiException if the remote call fails */ public final ListNoteOccurrencesPagedResponse listNoteOccurrences(NoteName name, String filter) { ListNoteOccurrencesRequest request = ListNoteOccurrencesRequest.newBuilder() .setName(name == null ? null : name.toString()) .setFilter(filter) .build(); return listNoteOccurrences(request); }
/** * Updates the specified note. * * <p>Sample code: * * <pre><code> * try (GrafeasV1Beta1Client grafeasV1Beta1Client = GrafeasV1Beta1Client.create()) { * NoteName name = NoteName.of("[PROJECT]", "[NOTE]"); * Note note = Note.newBuilder().build(); * FieldMask updateMask = FieldMask.newBuilder().build(); * Note response = grafeasV1Beta1Client.updateNote(name, note, updateMask); * } * </code></pre> * * @param name The name of the note in the form of `projects/[PROVIDER_ID]/notes/[NOTE_ID]`. * @param note The updated note. * @param updateMask The fields to update. * @throws com.google.api.gax.rpc.ApiException if the remote call fails */ public final Note updateNote(NoteName name, Note note, FieldMask updateMask) { UpdateNoteRequest request = UpdateNoteRequest.newBuilder() .setName(name == null ? null : name.toString()) .setNote(note) .setUpdateMask(updateMask) .build(); return updateNote(request); }
/** * Retrieves all the Occurrences associated with a specified Note * Here, all Occurrences are printed and counted * @param client The Grafeas client used to perform the API requests. * @param noteId the Note's unique identifier * @param projectId the GCP project the Note belongs to * @return number of Occurrences found */ public static int getOccurrencesForNote(GrafeasV1Beta1Client client, String noteId, String projectId) { final NoteName noteName = NoteName.of(projectId, noteId); int i = 0; ListNoteOccurrencesRequest request = ListNoteOccurrencesRequest.newBuilder() .setName(noteName.toString()) .build(); for (Occurrence o : client.listNoteOccurrences(request).iterateAll()) { // Write custom code to process each Occurrence here System.out.println(o.getName()); i = i + 1; } return i; } // [END occurrences_for_note]
/** * Pushes an update to a Note that already exists on the server * @param client The Grafeas client used to perform the API requests. * @param updated a Note object representing the desired updates to push * @param noteId the identifier of the existing Note * @param projectId the GCP project the Note belongs to */ public static Note updateNote(GrafeasV1Beta1Client client, Note updated, String noteId, String projectId) { final NoteName noteName = NoteName.of(projectId, noteId); UpdateNoteRequest request = UpdateNoteRequest.newBuilder() .setName(noteName.toString()) .setNote(updated) .build(); return client.updateNote(request); } // [END update_note]
/** * 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]
public static List<String> toStringList(List<NoteName> values) { List<String> list = new ArrayList<String>(values.size()); for (NoteName value : values) { if (value == null) { list.add(""); } else { list.add(value.toString()); } } return list; }
public static String format(String project, String note) { return newBuilder().setProject(project).setNote(note).build().toString(); }