google.cloud.forseti.common.gcp_api.repository_mixins module

Mixin classes for _base_repository.GCPRepository implementations.

class AggregatedListQueryMixin[source]

Bases: google.cloud.forseti.common.gcp_api.repository_mixins.ListQueryMixin

Mixin that implements a paged AggregatedList query.

aggregated_list(resource=None, fields=None, max_results=None, verb='aggregatedList', **kwargs)[source]

List all subresource entities of a given resource.

Parameters:
  • self (GCPRespository) – An instance of a GCPRespository class.
  • resource (str) – The id of the resource to query.
  • fields (str) – Fields to include in the response - partial response.
  • max_results (int) – Number of entries to include per page.
  • verb (str) – The method to call on the API.
  • **kwargs (dict) – Optional additional arguments to pass to the query.
Returns:

An iterator of API responses by page.

Return type:

iterator

class GetIamPolicyQueryMixin[source]

Bases: object

Mixin that implements getIamPolicy query.

get_iam_policy(resource, fields=None, verb='getIamPolicy', include_body=True, resource_field='resource', **kwargs)[source]

Get resource IAM Policy.

Parameters:
  • self (GCPRespository) – An instance of a GCPRespository class.
  • resource (str) – The id of the resource to fetch.
  • fields (str) – Fields to include in the response - partial response.
  • verb (str) – The method to call on the API.
  • include_body (bool) – If true, include an empty body parameter in the method args.
  • resource_field (str) – The parameter name of the resource field to pass to the method.
  • **kwargs (dict) – Optional additional arguments to pass to the query.
Returns:

Response from the API.

Return type:

dict

Raises:

errors.HttpError – When attempting to get a non-existent entity. ex: HttpError 404 when requesting … returned

“The resource ‘…’ was not found”

class GetQueryMixin[source]

Bases: object

Mixin that implements Get query.

get(resource, target=None, fields=None, verb='get', **kwargs)[source]

Get API entity.

Parameters:
  • self (GCPRespository) – An instance of a GCPRespository class.
  • resource (str) – The id of the resource to query.
  • target (str) – Name of the entity to fetch.
  • fields (str) – Fields to include in the response - partial response.
  • verb (str) – The method to call on the API.
  • **kwargs (dict) – Optional additional arguments to pass to the query.
Returns:

Response from the API.

Return type:

dict

Raises:
  • ValueError – When get_key_field was not defined in the base GCPRepository instance.

  • errors.HttpError – When attempting to get a non-existent entity. ex: HttpError 404 when requesting … returned

    “The resource ‘…’ was not found”

class ListQueryMixin[source]

Bases: object

Mixin that implements paged List query.

list(resource=None, fields=None, max_results=None, verb='list', **kwargs)[source]

List subresources of a given resource.

Parameters:
  • self (GCPRespository) – An instance of a GCPRespository class.
  • resource (str) – The id of the resource to query.
  • fields (str) – Fields to include in the response - partial response.
  • max_results (int) – Number of entries to include per page.
  • verb (str) – The method to call on the API.
  • **kwargs (dict) – Optional additional arguments to pass to the query.
Yields:

dict – An API response containing one page of results.

class OrgPolicyQueryMixin[source]

Bases: object

Mixin that implements getOrgPolicy and listOrgPolicies query.

get_effective_org_policy(resource, constraint, fields=None, verb='getEffectiveOrgPolicy', **kwargs)[source]

Get Effective Org Policy for a constraint on a resource.

Parameters:
  • self (GCPRespository) – An instance of a GCPRespository class.
  • resource (str) – The id of the resource to fetch.
  • constraint (str) – The constraint name to fetch the policy for.
  • fields (str) – Fields to include in the response - partial response.
  • verb (str) – The method to call on the API.
  • **kwargs (dict) – Optional additional arguments to pass to the query.
Returns:

Response from the API.

Return type:

dict

Raises:

errors.HttpError – When attempting to get a non-existent entity. ex: HttpError 404 when requesting … returned

“The resource ‘…’ was not found”

get_org_policy(resource, constraint, fields=None, verb='getOrgPolicy', **kwargs)[source]

Get Org Policy for a constraint on a resource.

Parameters:
  • self (GCPRespository) – An instance of a GCPRespository class.
  • resource (str) – The id of the resource to fetch.
  • constraint (str) – The constraint name to fetch the policy for.
  • fields (str) – Fields to include in the response - partial response.
  • verb (str) – The method to call on the API.
  • **kwargs (dict) – Optional additional arguments to pass to the query.
Returns:

Response from the API.

Return type:

dict

Raises:

errors.HttpError – When attempting to get a non-existent entity. ex: HttpError 404 when requesting … returned

“The resource ‘…’ was not found”

list_org_policies(resource, fields=None, max_results=None, verb='listOrgPolicies', **kwargs)[source]

List Org Policies applied to the resource.

Parameters:
  • self (GCPRespository) – An instance of a GCPRespository class.
  • resource (str) – The id of the resource to query.
  • fields (str) – Fields to include in the response - partial response.
  • max_results (int) – Number of entries to include per page.
  • verb (str) – The method to call on the API.
  • **kwargs (dict) – Optional additional arguments to pass to the query.
Yields:

dict – An API response containing one page of results.

Raises:

errors.HttpError – When attempting to get a non-existent entity. ex: HttpError 404 when requesting … returned

“The resource ‘…’ was not found”

class SearchQueryMixin[source]

Bases: object

Mixin that implements a paged Search query.

search(query=None, fields=None, max_results=500, verb='search')[source]

List all subresource entities visable to the caller.

Parameters:
  • self (GCPRespository) – An instance of a GCPRespository class.
  • query (str) – Additional filters to apply to the restrict the set of resources returned.
  • fields (str) – Fields to include in the response - partial response.
  • max_results (int) – Number of entries to include per page.
  • verb (str) – The method to call on the API.
Yields:

dict – An API response containing one page of results.