GitHub Repository | Product Reference |
Service Description: Grafeas API.
Retrieves analysis results of Cloud components such as Docker container images.
Analysis results are stored as a series of occurrences. An Occurrence
contains information
about a specific analysis instance on a resource. An occurrence refers to a Note
. A note
contains details describing the analysis and is generally stored in a separate project, called a
Provider
. Multiple occurrences can refer to the same note.
For example, an SSL vulnerability could affect multiple images. In this case, there would be one note for the vulnerability and an occurrence for each image with the vulnerability referring to that note.
This class provides the ability to make remote calls to the backing service through method calls that map to API methods. Sample code to get started:
// This snippet has been automatically generated and should be regarded as a code template only.
// It will require modifications to work:
// - It may require correct/in-range values for request initialization.
// - It may require specifying regional endpoints when creating the service client as shown in
// https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
try (GrafeasClient grafeasClient = GrafeasClient.create()) {
OccurrenceName name = OccurrenceName.of("[PROJECT]", "[OCCURRENCE]");
Occurrence response = grafeasClient.getOccurrence(name);
}
Note: close() needs to be called on the GrafeasClient object to clean up resources such as threads. In the example above, try-with-resources is used, which automatically calls close().
The surface of this class includes several types of Java methods for each of the API's methods:
- A "flattened" method. With this type of method, the fields of the request type have been converted into function parameters. It may be the case that not all fields are available as parameters, and not every API method will have a flattened method entry point.
- A "request object" method. This type of method only takes one parameter, a request object, which must be constructed before the call. Not every API method will have a request object method.
- A "callable" method. This type of method takes no parameters and returns an immutable API callable object, which can be used to initiate calls to the service.
See the individual methods for example code.
Many parameters require resource names to be formatted in a particular way. To assist with these names, this class includes a format method for each type of name, and additionally a parse method to extract the individual identifiers contained within names that are returned.
This class can be customized by passing in a custom instance of GrafeasSettings to create(). For example:
To customize credentials:
// This snippet has been automatically generated and should be regarded as a code template only.
// It will require modifications to work:
// - It may require correct/in-range values for request initialization.
// - It may require specifying regional endpoints when creating the service client as shown in
// https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
GrafeasSettings grafeasSettings =
GrafeasSettings.newBuilder()
.setCredentialsProvider(FixedCredentialsProvider.create(myCredentials))
.build();
GrafeasClient grafeasClient = GrafeasClient.create(grafeasSettings);
To customize the endpoint:
// This snippet has been automatically generated and should be regarded as a code template only.
// It will require modifications to work:
// - It may require correct/in-range values for request initialization.
// - It may require specifying regional endpoints when creating the service client as shown in
// https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
GrafeasSettings grafeasSettings = GrafeasSettings.newBuilder().setEndpoint(myEndpoint).build();
GrafeasClient grafeasClient = GrafeasClient.create(grafeasSettings);
Please refer to the GitHub repository's samples for more quickstart code snippets.
Static Methods
create()
public static final GrafeasClient create()
Constructs an instance of GrafeasClient with default settings.
Returns | |
---|---|
Type | Description |
GrafeasClient |
Exceptions | |
---|---|
Type | Description |
IOException |
create(GrafeasSettings settings)
public static final GrafeasClient create(GrafeasSettings settings)
Constructs an instance of GrafeasClient, using the given settings. The channels are created based on the settings passed in, or defaults for any settings that are not set.
Parameter | |
---|---|
Name | Description |
settings | GrafeasSettings |
Returns | |
---|---|
Type | Description |
GrafeasClient |
Exceptions | |
---|---|
Type | Description |
IOException |
create(GrafeasStub stub)
public static final GrafeasClient create(GrafeasStub stub)
Constructs an instance of GrafeasClient, using the given stub for making calls. This is for advanced usage - prefer using create(GrafeasSettings).
Parameter | |
---|---|
Name | Description |
stub | GrafeasStub |
Returns | |
---|---|
Type | Description |
GrafeasClient |
Constructors
GrafeasClient(GrafeasSettings settings)
protected GrafeasClient(GrafeasSettings settings)
Constructs an instance of GrafeasClient, using the given settings. This is protected so that it is easy to make a subclass, but otherwise, the static factory methods should be preferred.
Parameter | |
---|---|
Name | Description |
settings | GrafeasSettings |
GrafeasClient(GrafeasStub stub)
protected GrafeasClient(GrafeasStub stub)
Parameter | |
---|---|
Name | Description |
stub | GrafeasStub |
Methods
awaitTermination(long duration, TimeUnit unit)
public boolean awaitTermination(long duration, TimeUnit unit)
Parameters | |
---|---|
Name | Description |
duration | long |
unit | TimeUnit |
Returns | |
---|---|
Type | Description |
boolean |
Exceptions | |
---|---|
Type | Description |
InterruptedException |
batchCreateNotes(BatchCreateNotesRequest request)
public final BatchCreateNotesResponse batchCreateNotes(BatchCreateNotesRequest request)
Creates new notes in batch.
Sample code:
// This snippet has been automatically generated and should be regarded as a code template only.
// It will require modifications to work:
// - It may require correct/in-range values for request initialization.
// - It may require specifying regional endpoints when creating the service client as shown in
// https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
try (GrafeasClient grafeasClient = GrafeasClient.create()) {
BatchCreateNotesRequest request =
BatchCreateNotesRequest.newBuilder()
.setParent(ProjectName.of("[PROJECT]").toString())
.putAllNotes(new HashMap<String, Note>())
.build();
BatchCreateNotesResponse response = grafeasClient.batchCreateNotes(request);
}
Parameter | |
---|---|
Name | Description |
request | BatchCreateNotesRequest The request object containing all of the parameters for the API call. |
Returns | |
---|---|
Type | Description |
BatchCreateNotesResponse |
batchCreateNotes(ProjectName parent, Map<String,Note> notes)
public final BatchCreateNotesResponse batchCreateNotes(ProjectName parent, Map<String,Note> notes)
Creates new notes in batch.
Sample code:
// This snippet has been automatically generated and should be regarded as a code template only.
// It will require modifications to work:
// - It may require correct/in-range values for request initialization.
// - It may require specifying regional endpoints when creating the service client as shown in
// https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
try (GrafeasClient grafeasClient = GrafeasClient.create()) {
ProjectName parent = ProjectName.of("[PROJECT]");
Map<String, Note> notes = new HashMap<>();
BatchCreateNotesResponse response = grafeasClient.batchCreateNotes(parent, notes);
}
Parameters | |
---|---|
Name | Description |
parent | ProjectName The name of the project in the form of |
notes | Map<String,Note> The notes to create. Max allowed length is 1000. |
Returns | |
---|---|
Type | Description |
BatchCreateNotesResponse |
batchCreateNotes(String parent, Map<String,Note> notes)
public final BatchCreateNotesResponse batchCreateNotes(String parent, Map<String,Note> notes)
Creates new notes in batch.
Sample code:
// This snippet has been automatically generated and should be regarded as a code template only.
// It will require modifications to work:
// - It may require correct/in-range values for request initialization.
// - It may require specifying regional endpoints when creating the service client as shown in
// https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
try (GrafeasClient grafeasClient = GrafeasClient.create()) {
String parent = ProjectName.of("[PROJECT]").toString();
Map<String, Note> notes = new HashMap<>();
BatchCreateNotesResponse response = grafeasClient.batchCreateNotes(parent, notes);
}
Parameters | |
---|---|
Name | Description |
parent | String The name of the project in the form of |
notes | Map<String,Note> The notes to create. Max allowed length is 1000. |
Returns | |
---|---|
Type | Description |
BatchCreateNotesResponse |
batchCreateNotesCallable()
public final UnaryCallable<BatchCreateNotesRequest,BatchCreateNotesResponse> batchCreateNotesCallable()
Creates new notes in batch.
Sample code:
// This snippet has been automatically generated and should be regarded as a code template only.
// It will require modifications to work:
// - It may require correct/in-range values for request initialization.
// - It may require specifying regional endpoints when creating the service client as shown in
// https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
try (GrafeasClient grafeasClient = GrafeasClient.create()) {
BatchCreateNotesRequest request =
BatchCreateNotesRequest.newBuilder()
.setParent(ProjectName.of("[PROJECT]").toString())
.putAllNotes(new HashMap<String, Note>())
.build();
ApiFuture<BatchCreateNotesResponse> future =
grafeasClient.batchCreateNotesCallable().futureCall(request);
// Do something.
BatchCreateNotesResponse response = future.get();
}
Returns | |
---|---|
Type | Description |
UnaryCallable<BatchCreateNotesRequest,BatchCreateNotesResponse> |
batchCreateOccurrences(BatchCreateOccurrencesRequest request)
public final BatchCreateOccurrencesResponse batchCreateOccurrences(BatchCreateOccurrencesRequest request)
Creates new occurrences in batch.
Sample code:
// This snippet has been automatically generated and should be regarded as a code template only.
// It will require modifications to work:
// - It may require correct/in-range values for request initialization.
// - It may require specifying regional endpoints when creating the service client as shown in
// https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
try (GrafeasClient grafeasClient = GrafeasClient.create()) {
BatchCreateOccurrencesRequest request =
BatchCreateOccurrencesRequest.newBuilder()
.setParent(ProjectName.of("[PROJECT]").toString())
.addAllOccurrences(new ArrayList<Occurrence>())
.build();
BatchCreateOccurrencesResponse response = grafeasClient.batchCreateOccurrences(request);
}
Parameter | |
---|---|
Name | Description |
request | BatchCreateOccurrencesRequest The request object containing all of the parameters for the API call. |
Returns | |
---|---|
Type | Description |
BatchCreateOccurrencesResponse |
batchCreateOccurrences(ProjectName parent, List<Occurrence> occurrences)
public final BatchCreateOccurrencesResponse batchCreateOccurrences(ProjectName parent, List<Occurrence> occurrences)
Creates new occurrences in batch.
Sample code:
// This snippet has been automatically generated and should be regarded as a code template only.
// It will require modifications to work:
// - It may require correct/in-range values for request initialization.
// - It may require specifying regional endpoints when creating the service client as shown in
// https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
try (GrafeasClient grafeasClient = GrafeasClient.create()) {
ProjectName parent = ProjectName.of("[PROJECT]");
List<Occurrence> occurrences = new ArrayList<>();
BatchCreateOccurrencesResponse response =
grafeasClient.batchCreateOccurrences(parent, occurrences);
}
Parameters | |
---|---|
Name | Description |
parent | ProjectName The name of the project in the form of |
occurrences | List<Occurrence> The occurrences to create. Max allowed length is 1000. |
Returns | |
---|---|
Type | Description |
BatchCreateOccurrencesResponse |
batchCreateOccurrences(String parent, List<Occurrence> occurrences)
public final BatchCreateOccurrencesResponse batchCreateOccurrences(String parent, List<Occurrence> occurrences)
Creates new occurrences in batch.
Sample code:
// This snippet has been automatically generated and should be regarded as a code template only.
// It will require modifications to work:
// - It may require correct/in-range values for request initialization.
// - It may require specifying regional endpoints when creating the service client as shown in
// https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
try (GrafeasClient grafeasClient = GrafeasClient.create()) {
String parent = ProjectName.of("[PROJECT]").toString();
List<Occurrence> occurrences = new ArrayList<>();
BatchCreateOccurrencesResponse response =
grafeasClient.batchCreateOccurrences(parent, occurrences);
}
Parameters | |
---|---|
Name | Description |
parent | String The name of the project in the form of |
occurrences | List<Occurrence> The occurrences to create. Max allowed length is 1000. |
Returns | |
---|---|
Type | Description |
BatchCreateOccurrencesResponse |
batchCreateOccurrencesCallable()
public final UnaryCallable<BatchCreateOccurrencesRequest,BatchCreateOccurrencesResponse> batchCreateOccurrencesCallable()
Creates new occurrences in batch.
Sample code:
// This snippet has been automatically generated and should be regarded as a code template only.
// It will require modifications to work:
// - It may require correct/in-range values for request initialization.
// - It may require specifying regional endpoints when creating the service client as shown in
// https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
try (GrafeasClient grafeasClient = GrafeasClient.create()) {
BatchCreateOccurrencesRequest request =
BatchCreateOccurrencesRequest.newBuilder()
.setParent(ProjectName.of("[PROJECT]").toString())
.addAllOccurrences(new ArrayList<Occurrence>())
.build();
ApiFuture<BatchCreateOccurrencesResponse> future =
grafeasClient.batchCreateOccurrencesCallable().futureCall(request);
// Do something.
BatchCreateOccurrencesResponse response = future.get();
}
Returns | |
---|---|
Type | Description |
UnaryCallable<BatchCreateOccurrencesRequest,BatchCreateOccurrencesResponse> |
close()
public final void close()
createNote(CreateNoteRequest request)
public final Note createNote(CreateNoteRequest request)
Creates a new note.
Sample code:
// This snippet has been automatically generated and should be regarded as a code template only.
// It will require modifications to work:
// - It may require correct/in-range values for request initialization.
// - It may require specifying regional endpoints when creating the service client as shown in
// https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
try (GrafeasClient grafeasClient = GrafeasClient.create()) {
CreateNoteRequest request =
CreateNoteRequest.newBuilder()
.setParent(ProjectName.of("[PROJECT]").toString())
.setNoteId("noteId-1039694675")
.setNote(Note.newBuilder().build())
.build();
Note response = grafeasClient.createNote(request);
}
Parameter | |
---|---|
Name | Description |
request | CreateNoteRequest The request object conta |