google.cloud.forseti.common.gcp_api._base_repository module

Base GCP client which uses the discovery API.

class BaseRepositoryClient(api_name, versions=None, credentials=None, quota_max_calls=None, quota_period=None, use_rate_limiter=False, read_only=False, **kwargs)[source]

Bases: object

Base class for API repository for a specified Cloud API.

__repr__()[source]

The object representation.

Returns:The object representation.
Return type:str
_init_repository(repository_class, version=None)[source]

Safely initialize a repository class to a property.

Parameters:
  • repository_class (class) – The class to initialize.
  • version (str) – The gcp service version for the repository.
Returns:

An instance of repository_class.

Return type:

object

class GCPRepository(gcp_service, credentials, component, num_retries=5, key_field='project', entity_field=None, list_key_field=None, get_key_field=None, max_results_field='maxResults', search_query_field='query', resource_path_template=None, rate_limiter=None, use_cached_http=True, read_only=False)[source]

Bases: object

Base class for GCP APIs.

_build_next_request(verb, prior_request, prior_response)[source]

Builds pagination-aware request object.

More details:
https://developers.google.com/api-client-library/python/guide/pagination
Parameters:
  • verb (str) – Request verb (ex. insert, update, delete).
  • prior_request (httplib2.HttpRequest) – Request that may trigger paging.
  • prior_response (dict) – Potentially partial response.
Returns:

HttpRequest or None. None is returned when

there is nothing more to fetch - request completed.

Return type:

httplib2.HttpRequest

_build_request(verb, verb_arguments)[source]

Builds HttpRequest object.

Parameters:
  • verb (str) – Request verb (ex. insert, update, delete).
  • verb_arguments (dict) – Arguments to be passed with the request.
Returns:

HttpRequest to be sent to the API.

Return type:

httplib2.HttpRequest

Build a full URI for a specific resource.

Parameters:**kwargs – The args to expand in the URI template.
Returns:The Resource URI
Return type:str
Raises:ValueError – Raised if the resource_path_template parameter was undefined when the repository was created.
_execute(request, *args, **kwargs)[source]

Run execute with retries and rate limiting.

Parameters:request (object) – The HttpRequest object to execute.
Returns:The response from the API.
Return type:dict
_request_supports_pagination(verb)[source]

Determines if the API action supports pagination.

Parameters:verb (str) – Request verb (ex. insert, update, delete).
Returns:True when API supports pagination, False otherwise.
Return type:bool
execute_command(verb, verb_arguments)[source]

Executes command (ex. add) via a dedicated http object.

Async APIs may take minutes to complete. Therefore, callers are encouraged to leverage concurrent.futures (or similar) to place long running commands on a separate threads.

Parameters:
  • verb (str) – Method to execute on the component (ex. get, list).
  • verb_arguments (dict) – key-value pairs to be passed to _build_request.
Returns:

An async operation Service Response.

Return type:

dict

execute_paged_query(verb, verb_arguments)[source]

Executes query (ex. list) via a dedicated http object.

Parameters:
  • verb (str) – Method to execute on the component (ex. get, list).
  • verb_arguments (dict) – key-value pairs to be passed to _BuildRequest.
Yields:

dict – Service Response.

Raises:

PaginationNotSupportedError – When an API does not support paging.

execute_query(verb, verb_arguments)[source]

Executes query (ex. get) via a dedicated http object.

Parameters:
  • verb (str) – Method to execute on the component (ex. get, list).
  • verb_arguments (dict) – key-value pairs to be passed to _BuildRequest.
Returns:

Service Response.

Return type:

dict

execute_search_query(verb, verb_arguments)[source]

Executes query (ex. search) via a dedicated http object.

Parameters:
  • verb (str) – Method to execute on the component (ex. search).
  • verb_arguments (dict) – key-value pairs to be passed to _BuildRequest.
Yields:

dict – Service Response.

http

A thread local instance of httplib2.Http.

Returns:
An Http instance authorized by
the credentials.
Return type:google_auth_httplib2.AuthorizedHttp
_build_service_from_document(credentials, document_path)[source]

Builds an API client from a local discovery document

Parameters:
  • credentials (OAuth2Credentials) – Credentials that will be used to authenticate the API calls.
  • document_path (str) – The local path of the discovery document
Returns:

A Resource object with methods for interacting with the service.

Return type:

object

_create_service_api(*args, **kw)[source]

Builds and returns a cloud API service object.

Parameters:
  • credentials (OAuth2Credentials) – Credentials that will be used to authenticate the API calls.
  • service_name (str) – The name of the API.
  • version (str) – The version of the API to use.
  • is_private_api (bool) – Whether the API is a private API.
  • developer_key (str) – The api key to use to determine the project associated with the API call, most API services do not require this to be set.
  • cache_discovery (bool) – Whether or not to cache the discovery doc.
Returns:

A Resource object with methods for interacting with the service.

Return type:

object