Client for Grafeas API#
-
class
grafeas.grafeas_v1.
GrafeasClient
(transport, client_config=None, client_info=None)[source]# 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 aNote
. A note contains details describing the analysis and is generally stored in a separate project, called aProvider
. 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.
Constructor.
- Parameters
transport (GrafeasGrpcTransport) – A transport instance, responsible for actually making the API calls. The default transport uses the gRPC protocol. This argument may also be a callable which returns a transport instance. Callables will be sent the credentials as the first argument and the default transport class as the second argument.
client_config (dict) – DEPRECATED. A dictionary of call options for each method. If not specified, the default configuration is used.
client_info (google.api_core.gapic_v1.client_info.ClientInfo) – The client info used to send a user-agent string along with API requests. If
None
, then default info will be used. Generally, you only need to set this if you’re developing your own client library.
-
batch_create_notes
(parent, notes, retry=<object object>, timeout=<object object>, metadata=None)[source]# Creates new notes in batch.
Example
>>> from grafeas import grafeas_v1 >>> from grafeas.grafeas_v1.gapic.transports import grafeas_grpc_transport >>> >>> address = "[SERVICE_ADDRESS]" >>> scopes = ("[SCOPE]") >>> transport = grafeas_grpc_transport.GrafeasGrpcTransport(address, scopes) >>> client = grafeas_v1.GrafeasClient(transport) >>> >>> parent = client.project_path('[PROJECT]') >>> >>> # TODO: Initialize `notes`: >>> notes = {} >>> >>> response = client.batch_create_notes(parent, notes)
- Parameters
parent (str) – The name of the project in the form of
projects/[PROJECT_ID]
, under which the notes are to be created.notes (dict[str -> Union[dict, Note]]) –
The notes to create. Max allowed length is 1000.
If a dict is provided, it must be of the same form as the protobuf message
Note
retry (Optional[google.api_core.retry.Retry]) – A retry object used to retry requests. If
None
is specified, requests will not be retried.timeout (Optional[float]) – The amount of time, in seconds, to wait for the request to complete. Note that if
retry
is specified, the timeout applies to each individual attempt.metadata (Optional[Sequence[Tuple[str, str]]]) – Additional metadata that is provided to the method.
- Returns
A
BatchCreateNotesResponse
instance.- Raises
google.api_core.exceptions.GoogleAPICallError – If the request failed for any reason.
google.api_core.exceptions.RetryError – If the request failed due to a retryable error and retry attempts failed.
ValueError – If the parameters are invalid.
-
batch_create_occurrences
(parent, occurrences, retry=<object object>, timeout=<object object>, metadata=None)[source]# Creates new occurrences in batch.
Example
>>> from grafeas import grafeas_v1 >>> from grafeas.grafeas_v1.gapic.transports import grafeas_grpc_transport >>> >>> address = "[SERVICE_ADDRESS]" >>> scopes = ("[SCOPE]") >>> transport = grafeas_grpc_transport.GrafeasGrpcTransport(address, scopes) >>> client = grafeas_v1.GrafeasClient(transport) >>> >>> parent = client.project_path('[PROJECT]') >>> >>> # TODO: Initialize `occurrences`: >>> occurrences = [] >>> >>> response = client.batch_create_occurrences(parent, occurrences)
- Parameters
parent (str) – The name of the project in the form of
projects/[PROJECT_ID]
, under which the occurrences are to be created.occurrences (list[Union[dict, Occurrence]]) –
The occurrences to create. Max allowed length is 1000.
If a dict is provided, it must be of the same form as the protobuf message
Occurrence
retry (Optional[google.api_core.retry.Retry]) – A retry object used to retry requests. If
None
is specified, requests will not be retried.timeout (Optional[float]) – The amount of time, in seconds, to wait for the request to complete. Note that if
retry
is specified, the timeout applies to each individual attempt.metadata (Optional[Sequence[Tuple[str, str]]]) – Additional metadata that is provided to the method.
- Returns
A
BatchCreateOccurrencesResponse
instance.- Raises
google.api_core.exceptions.GoogleAPICallError – If the request failed for any reason.
google.api_core.exceptions.RetryError – If the request failed due to a retryable error and retry attempts failed.
ValueError – If the parameters are invalid.
-
create_note
(parent, note_id, note, retry=<object object>, timeout=<object object>, metadata=None)[source]# Creates a new note.
Example
>>> from grafeas import grafeas_v1 >>> from grafeas.grafeas_v1.gapic.transports import grafeas_grpc_transport >>> >>> address = "[SERVICE_ADDRESS]" >>> scopes = ("[SCOPE]") >>> transport = grafeas_grpc_transport.GrafeasGrpcTransport(address, scopes) >>> client = grafeas_v1.GrafeasClient(transport) >>> >>> parent = client.project_path('[PROJECT]') >>> >>> # TODO: Initialize `note_id`: >>> note_id = '' >>> >>> # TODO: Initialize `note`: >>> note = {} >>> >>> response = client.create_note(parent, note_id, note)
- Parameters
parent (str) – The name of the project in the form of
projects/[PROJECT_ID]
, under which the note is to be created.note_id (str) – The ID to use for this note.
The note to create.
If a dict is provided, it must be of the same form as the protobuf message
Note
retry (Optional[google.api_core.retry.Retry]) – A retry object used to retry requests. If
None
is specified, requests will not be retried.timeout (Optional[float]) – The amount of time, in seconds, to wait for the request to complete. Note that if
retry
is specified, the timeout applies to each individual attempt.metadata (Optional[Sequence[Tuple[str, str]]]) – Additional metadata that is provided to the method.
- Returns
A
Note
instance.- Raises
google.api_core.exceptions.GoogleAPICallError – If the request failed for any reason.
google.api_core.exceptions.RetryError – If the request failed due to a retryable error and retry attempts failed.
ValueError – If the parameters are invalid.
-
create_occurrence
(parent, occurrence, retry=<object object>, timeout=<object object>, metadata=None)[source]# Creates a new occurrence.
Example
>>> from grafeas import grafeas_v1 >>> from grafeas.grafeas_v1.gapic.transports import grafeas_grpc_transport >>> >>> address = "[SERVICE_ADDRESS]" >>> scopes = ("[SCOPE]") >>> transport = grafeas_grpc_transport.GrafeasGrpcTransport(address, scopes) >>> client = grafeas_v1.GrafeasClient(transport) >>> >>> parent = client.project_path('[PROJECT]') >>> >>> # TODO: Initialize `occurrence`: >>> occurrence = {} >>> >>> response = client.create_occurrence(parent, occurrence)
- Parameters
parent (str) – The name of the project in the form of
projects/[PROJECT_ID]
, under which the occurrence is to be created.occurrence (Union[dict, Occurrence]) –
The occurrence to create.
If a dict is provided, it must be of the same form as the protobuf message
Occurrence
retry (Optional[google.api_core.retry.Retry]) – A retry object used to retry requests. If
None
is specified, requests will not be retried.timeout (Optional[float]) – The amount of time, in seconds, to wait for the request to complete. Note that if
retry
is specified, the timeout applies to each individual attempt.metadata (Optional[Sequence[Tuple[str, str]]]) – Additional metadata that is provided to the method.
- Returns
A
Occurrence
instance.- Raises
google.api_core.exceptions.GoogleAPICallError – If the request failed for any reason.
google.api_core.exceptions.RetryError – If the request failed due to a retryable error and retry attempts failed.
ValueError – If the parameters are invalid.
-
delete_note
(name, retry=<object object>, timeout=<object object>, metadata=None)[source]# Deletes the specified note.
Example
>>> from grafeas import grafeas_v1 >>> from grafeas.grafeas_v1.gapic.transports import grafeas_grpc_transport >>> >>> address = "[SERVICE_ADDRESS]" >>> scopes = ("[SCOPE]") >>> transport = grafeas_grpc_transport.GrafeasGrpcTransport(address, scopes) >>> client = grafeas_v1.GrafeasClient(transport) >>> >>> name = client.note_path('[PROJECT]', '[NOTE]') >>> >>> client.delete_note(name)
- Parameters
name (str) – The name of the note in the form of
projects/[PROVIDER_ID]/notes/[NOTE_ID]
.retry (Optional[google.api_core.retry.Retry]) – A retry object used to retry requests. If
None
is specified, requests will not be retried.timeout (Optional[float]) – The amount of time, in seconds, to wait for the request to complete. Note that if
retry
is specified, the timeout applies to each individual attempt.metadata (Optional[Sequence[Tuple[str, str]]]) – Additional metadata that is provided to the method.
- Raises
google.api_core.exceptions.GoogleAPICallError – If the request failed for any reason.
google.api_core.exceptions.RetryError – If the request failed due to a retryable error and retry attempts failed.
ValueError – If the parameters are invalid.
-
delete_occurrence
(name, retry=<object object>, timeout=<object object>, metadata=None)[source]# Deletes the specified occurrence. For example, use this method to delete an occurrence when the occurrence is no longer applicable for the given resource.
Example
>>> from grafeas import grafeas_v1 >>> from grafeas.grafeas_v1.gapic.transports import grafeas_grpc_transport >>> >>> address = "[SERVICE_ADDRESS]" >>> scopes = ("[SCOPE]") >>> transport = grafeas_grpc_transport.GrafeasGrpcTransport(address, scopes) >>> client = grafeas_v1.GrafeasClient(transport) >>> >>> name = client.occurrence_path('[PROJECT]', '[OCCURRENCE]') >>> >>> client.delete_occurrence(name)
- Parameters
name (str) – The name of the occurrence in the form of
projects/[PROJECT_ID]/occurrences/[OCCURRENCE_ID]
.retry (Optional[google.api_core.retry.Retry]) – A retry object used to retry requests. If
None
is specified, requests will not be retried.timeout (Optional[float]) – The amount of time, in seconds, to wait for the request to complete. Note that if
retry
is specified, the timeout applies to each individual attempt.metadata (Optional[Sequence[Tuple[str, str]]]) – Additional metadata that is provided to the method.
- Raises
google.api_core.exceptions.GoogleAPICallError – If the request failed for any reason.
google.api_core.exceptions.RetryError – If the request failed due to a retryable error and retry attempts failed.
ValueError – If the parameters are invalid.
-
enums
= <module 'grafeas.grafeas_v1.gapic.enums' from '/usr/local/lib/python3.7/site-packages/grafeas/grafeas_v1/gapic/enums.py'>#
-
get_note
(name, retry=<object object>, timeout=<object object>, metadata=None)[source]# Gets the specified note.
Example
>>> from grafeas import grafeas_v1 >>> from grafeas.grafeas_v1.gapic.transports import grafeas_grpc_transport >>> >>> address = "[SERVICE_ADDRESS]" >>> scopes = ("[SCOPE]") >>> transport = grafeas_grpc_transport.GrafeasGrpcTransport(address, scopes) >>> client = grafeas_v1.GrafeasClient(transport) >>> >>> name = client.note_path('[PROJECT]', '[NOTE]') >>> >>> response = client.get_note(name)
- Parameters
name (str) – The name of the note in the form of
projects/[PROVIDER_ID]/notes/[NOTE_ID]
.retry (Optional[google.api_core.retry.Retry]) – A retry object used to retry requests. If
None
is specified, requests will not be retried.timeout (Optional[float]) – The amount of time, in seconds, to wait for the request to complete. Note that if
retry
is specified, the timeout applies to each individual attempt.metadata (Optional[Sequence[Tuple[str, str]]]) – Additional metadata that is provided to the method.
- Returns
A
Note
instance.- Raises
google.api_core.exceptions.GoogleAPICallError – If the request failed for any reason.
google.api_core.exceptions.RetryError – If the request failed due to a retryable error and retry attempts failed.
ValueError – If the parameters are invalid.
-
get_occurrence
(name, retry=<object object>, timeout=<object object>, metadata=None)[source]# Gets the specified occurrence.
Example
>>> from grafeas import grafeas_v1 >>> from grafeas.grafeas_v1.gapic.transports import grafeas_grpc_transport >>> >>> address = "[SERVICE_ADDRESS]" >>> scopes = ("[SCOPE]") >>> transport = grafeas_grpc_transport.GrafeasGrpcTransport(address, scopes) >>> client = grafeas_v1.GrafeasClient(transport) >>> >>> name = client.occurrence_path('[PROJECT]', '[OCCURRENCE]') >>> >>> response = client.get_occurrence(name)
- Parameters
name (str) – The name of the occurrence in the form of
projects/[PROJECT_ID]/occurrences/[OCCURRENCE_ID]
.retry (Optional[google.api_core.retry.Retry]) – A retry object used to retry requests. If
None
is specified, requests will not be retried.timeout (Optional[float]) – The amount of time, in seconds, to wait for the request to complete. Note that if
retry
is specified, the timeout applies to each individual attempt.metadata (Optional[Sequence[Tuple[str, str]]]) – Additional metadata that is provided to the method.
- Returns
A
Occurrence
instance.- Raises
google.api_core.exceptions.GoogleAPICallError – If the request failed for any reason.
google.api_core.exceptions.RetryError – If the request failed due to a retryable error and retry attempts failed.
ValueError – If the parameters are invalid.
-
get_occurrence_note
(name, retry=<object object>, timeout=<object object>, metadata=None)[source]# Gets the note attached to the specified occurrence. Consumer projects can use this method to get a note that belongs to a provider project.
Example
>>> from grafeas import grafeas_v1 >>> from grafeas.grafeas_v1.gapic.transports import grafeas_grpc_transport >>> >>> address = "[SERVICE_ADDRESS]" >>> scopes = ("[SCOPE]") >>> transport = grafeas_grpc_transport.GrafeasGrpcTransport(address, scopes) >>> client = grafeas_v1.GrafeasClient(transport) >>> >>> name = client.occurrence_path('[PROJECT]', '[OCCURRENCE]') >>> >>> response = client.get_occurrence_note(name)
- Parameters
name (str) – The name of the occurrence in the form of
projects/[PROJECT_ID]/occurrences/[OCCURRENCE_ID]
.retry (Optional[google.api_core.retry.Retry]) – A retry object used to retry requests. If
None
is specified, requests will not be retried.timeout (Optional[float]) – The amount of time, in seconds, to wait for the request to complete. Note that if
retry
is specified, the timeout applies to each individual attempt.metadata (Optional[Sequence[Tuple[str, str]]]) – Additional metadata that is provided to the method.
- Returns
A
Note
instance.- Raises
google.api_core.exceptions.GoogleAPICallError – If the request failed for any reason.
google.api_core.exceptions.RetryError – If the request failed due to a retryable error and retry attempts failed.
ValueError – If the parameters are invalid.
-
list_note_occurrences
(name, filter_=None, page_size=None, retry=<object object>, timeout=<object object>, metadata=None)[source]# Lists occurrences referencing the specified note. Provider projects can use this method to get all occurrences across consumer projects referencing the specified note.
Example
>>> from grafeas import grafeas_v1 >>> from grafeas.grafeas_v1.gapic.transports import grafeas_grpc_transport >>> >>> address = "[SERVICE_ADDRESS]" >>> scopes = ("[SCOPE]") >>> transport = grafeas_grpc_transport.GrafeasGrpcTransport(address, scopes) >>> client = grafeas_v1.GrafeasClient(transport) >>> >>> name = client.note_path('[PROJECT]', '[NOTE]') >>> >>> # Iterate over all results >>> for element in client.list_note_occurrences(name): ... # process element ... pass >>> >>> >>> # Alternatively: >>> >>> # Iterate over results one page at a time >>> for page in client.list_note_occurrences(name).pages: ... for element in page: ... # process element ... pass
- Parameters
name (str) – The name of the note to list occurrences for in the form of
projects/[PROVIDER_ID]/notes/[NOTE_ID]
.filter_ (str) – The filter expression.
page_size (int) – The maximum number of resources contained in the underlying API response. If page streaming is performed per- resource, this parameter does not affect the return value. If page streaming is performed per-page, this determines the maximum number of resources in a page.
retry (Optional[google.api_core.retry.Retry]) – A retry object used to retry requests. If
None
is specified, requests will not be retried.timeout (Optional[float]) – The amount of time, in seconds, to wait for the request to complete. Note that if
retry
is specified, the timeout applies to each individual attempt.metadata (Optional[Sequence[Tuple[str, str]]]) – Additional metadata that is provided to the method.
- Returns
A
PageIterator
instance. An iterable ofOccurrence
instances. You can also iterate over the pages of the response using its pages property.- Raises
google.api_core.exceptions.GoogleAPICallError – If the request failed for any reason.
google.api_core.exceptions.RetryError – If the request failed due to a retryable error and retry attempts failed.
ValueError – If the parameters are invalid.
-
list_notes
(parent, filter_=None, page_size=None, retry=<object object>, timeout=<object object>, metadata=None)[source]# Lists notes for the specified project.
Example
>>> from grafeas import grafeas_v1 >>> from grafeas.grafeas_v1.gapic.transports import grafeas_grpc_transport >>> >>> address = "[SERVICE_ADDRESS]" >>> scopes = ("[SCOPE]") >>> transport = grafeas_grpc_transport.GrafeasGrpcTransport(address, scopes) >>> client = grafeas_v1.GrafeasClient(transport) >>> >>> parent = client.project_path('[PROJECT]') >>> >>> # Iterate over all results >>> for element in client.list_notes(parent): ... # process element ... pass >>> >>> >>> # Alternatively: >>> >>> # Iterate over results one page at a time >>> for page in client.list_notes(parent).pages: ... for element in page: ... # process element ... pass
- Parameters
parent (str) – The name of the project to list notes for in the form of
projects/[PROJECT_ID]
.filter_ (str) – The filter expression.
page_size (int) – The maximum number of resources contained in the underlying API response. If page streaming is performed per- resource, this parameter does not affect the return value. If page streaming is performed per-page, this determines the maximum number of resources in a page.
retry (Optional[google.api_core.retry.Retry]) – A retry object used to retry requests. If
None
is specified, requests will not be retried.timeout (Optional[float]) – The amount of time, in seconds, to wait for the request to complete. Note that if
retry
is specified, the timeout applies to each individual attempt.metadata (Optional[Sequence[Tuple[str, str]]]) – Additional metadata that is provided to the method.
- Returns
A
PageIterator
instance. An iterable ofNote
instances. You can also iterate over the pages of the response using its pages property.- Raises
google.api_core.exceptions.GoogleAPICallError – If the request failed for any reason.
google.api_core.exceptions.RetryError – If the request failed due to a retryable error and retry attempts failed.
ValueError – If the parameters are invalid.
-
list_occurrences
(parent, filter_=None, page_size=None, retry=<object object>, timeout=<object object>, metadata=None)[source]# Lists occurrences for the specified project.
Example
>>> from grafeas import grafeas_v1 >>> from grafeas.grafeas_v1.gapic.transports import grafeas_grpc_transport >>> >>> address = "[SERVICE_ADDRESS]" >>> scopes = ("[SCOPE]") >>> transport = grafeas_grpc_transport.GrafeasGrpcTransport(address, scopes) >>> client = grafeas_v1.GrafeasClient(transport) >>> >>> parent = client.project_path('[PROJECT]') >>> >>> # Iterate over all results >>> for element in client.list_occurrences(parent): ... # process element ... pass >>> >>> >>> # Alternatively: >>> >>> # Iterate over results one page at a time >>> for page in client.list_occurrences(parent).pages: ... for element in page: ... # process element ... pass
- Parameters
parent (str) – The name of the project to list occurrences for in the form of
projects/[PROJECT_ID]
.filter_ (str) – The filter expression.
page_size (int) – The maximum number of resources contained in the underlying API response. If page streaming is performed per- resource, this parameter does not affect the return value. If page streaming is performed per-page, this determines the maximum number of resources in a page.
retry (Optional[google.api_core.retry.Retry]) – A retry object used to retry requests. If
None
is specified, requests will not be retried.timeout (Optional[float]) – The amount of time, in seconds, to wait for the request to complete. Note that if
retry
is specified, the timeout applies to each individual attempt.metadata (Optional[Sequence[Tuple[str, str]]]) – Additional metadata that is provided to the method.
- Returns
A
PageIterator
instance. An iterable ofOccurrence
instances. You can also iterate over the pages of the response using its pages property.- Raises
google.api_core.exceptions.GoogleAPICallError – If the request failed for any reason.
google.api_core.exceptions.RetryError – If the request failed due to a retryable error and retry attempts failed.
ValueError – If the parameters are invalid.
-
classmethod
occurrence_path
(project, occurrence)[source]# Return a fully-qualified occurrence string.
-
update_note
(name, note, update_mask=None, retry=<object object>, timeout=<object object>, metadata=None)[source]# Updates the specified note.
Example
>>> from grafeas import grafeas_v1 >>> from grafeas.grafeas_v1.gapic.transports import grafeas_grpc_transport >>> >>> address = "[SERVICE_ADDRESS]" >>> scopes = ("[SCOPE]") >>> transport = grafeas_grpc_transport.GrafeasGrpcTransport(address, scopes) >>> client = grafeas_v1.GrafeasClient(transport) >>> >>> name = client.note_path('[PROJECT]', '[NOTE]') >>> >>> # TODO: Initialize `note`: >>> note = {} >>> >>> response = client.update_note(name, note)
- Parameters
name (str) – The name of the note in the form of
projects/[PROVIDER_ID]/notes/[NOTE_ID]
.The updated note.
If a dict is provided, it must be of the same form as the protobuf message
Note
update_mask (Union[dict, FieldMask]) –
The fields to update.
If a dict is provided, it must be of the same form as the protobuf message
FieldMask
retry (Optional[google.api_core.retry.Retry]) – A retry object used to retry requests. If
None
is specified, requests will not be retried.timeout (Optional[float]) – The amount of time, in seconds, to wait for the request to complete. Note that if
retry
is specified, the timeout applies to each individual attempt.metadata (Optional[Sequence[Tuple[str, str]]]) – Additional metadata that is provided to the method.
- Returns
A
Note
instance.- Raises
google.api_core.exceptions.GoogleAPICallError – If the request failed for any reason.
google.api_core.exceptions.RetryError – If the request failed due to a retryable error and retry attempts failed.
ValueError – If the parameters are invalid.
-
update_occurrence
(name, occurrence, update_mask=None, retry=<object object>, timeout=<object object>, metadata=None)[source]# Updates the specified occurrence.
Example
>>> from grafeas import grafeas_v1 >>> from grafeas.grafeas_v1.gapic.transports import grafeas_grpc_transport >>> >>> address = "[SERVICE_ADDRESS]" >>> scopes = ("[SCOPE]") >>> transport = grafeas_grpc_transport.GrafeasGrpcTransport(address, scopes) >>> client = grafeas_v1.GrafeasClient(transport) >>> >>> name = client.occurrence_path('[PROJECT]', '[OCCURRENCE]') >>> >>> # TODO: Initialize `occurrence`: >>> occurrence = {} >>> >>> response = client.update_occurrence(name, occurrence)
- Parameters
name (str) – The name of the occurrence in the form of
projects/[PROJECT_ID]/occurrences/[OCCURRENCE_ID]
.occurrence (Union[dict, Occurrence]) –
The updated occurrence.
If a dict is provided, it must be of the same form as the protobuf message
Occurrence
update_mask (Union[dict, FieldMask]) –
The fields to update.
If a dict is provided, it must be of the same form as the protobuf message
FieldMask
retry (Optional[google.api_core.retry.Retry]) – A retry object used to retry requests. If
None
is specified, requests will not be retried.timeout (Optional[float]) – The amount of time, in seconds, to wait for the request to complete. Note that if
retry
is specified, the timeout applies to each individual attempt.metadata (Optional[Sequence[Tuple[str, str]]]) – Additional metadata that is provided to the method.
- Returns
A
Occurrence
instance.- Raises
google.api_core.exceptions.GoogleAPICallError – If the request failed for any reason.
google.api_core.exceptions.RetryError – If the request failed due to a retryable error and retry attempts failed.
ValueError – If the parameters are invalid.