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 CreateQueryMixin[source]

Bases: object

Mixin that implements a Create query.

create(verb='create', **kwargs)[source]

Create a resource.

Parameters:
  • self (GCPRespository) – An instance of a GCPRespository class.
  • verb (str) – The method to call on the API.
  • **kwargs (dict) – Optional additional arguments to pass to create.
Returns:

An API response containing one page of results.

Return type:

dict

class DeleteResourceMixin[source]

Bases: object

Mixin that implements the Delete API command for resources.

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

Delete an existing resource.

Parameters:
  • self (GCPRespository) – An instance of a GCPRespository class.
  • resource (str) – Name of the parent resource to delete the resource under.
  • target (str) – Name of the entity to delete.
  • verb (str) – The method to call on the API.
  • **kwargs (dict) – Optional additional arguments to pass to the api.
Returns:

The API response containing the async operation.

Return type:

dict

Raises:

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

class ExportAssetsQueryMixin[source]

Bases: object

Mixin that implements the exportAssets query.

export_assets(parent, destination_object, content_type=None, asset_types=None, fields=None, verb='exportAssets', **kwargs)[source]

Export assets under a parent resource to a file on GCS.

Parameters:
  • parent (str) – The name of the parent resource to export assests under.
  • destination_object (str) – The GCS path and file name to store the results in. The bucket must be in the same project that has the Cloud Asset API enabled.
  • content_type (str) – The specific content type to export, currently supports “RESOURCE” and “IAM_POLICY”. If not specified only the CAI metadata for assets are included.
  • asset_types (list) – The list of asset types to filter the results to, if not specified, exports all assets known to CAI.
  • fields (str) – Fields to include in the response - partial response.
  • verb (str) – The method to call on the API.
  • **kwargs (dict) – Additional parameters to pass to the API method.
Returns:

The response from the API.

Return type:

dict

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. :param self: An instance of a GCPRespository class. :type self: GCPRespository :param resource: The id of the resource to fetch. :type resource: str :param fields: Fields to include in the response - partial response. :type fields: str :param verb: The method to call on the API. :type verb: str :param include_body: If true, include an empty body parameter in the

method args.
Parameters:
  • 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 InsertResourceMixin[source]

Bases: object

Mixin that implements the Insert API command for resources.

insert(resource, data, verb='insert', **kwargs)[source]

Insert a new resource.

Parameters:
  • self (GCPRespository) – An instance of a GCPRespository class.
  • resource (str) – Name of the parent resource to insert the resource under.
  • data (dict) – The json representation of the resource to add.
  • verb (str) – The method to call on the API.
  • **kwargs (dict) – Optional additional arguments to pass to the api.
Returns:

The API response containing the async operation.

Return type:

dict

Raises:

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

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 PatchResourceMixin[source]

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

Mixin that implements the Patch API command for resources.

patch(resource, data, target=None, verb='patch', **kwargs)[source]

Patch an existing resource.

Parameters:
  • self (GCPRespository) – An instance of a GCPRespository class.
  • resource (str) – Name of the parent resource to patch the resource under.
  • data (dict) – The json representation of the resource to patch, this will update the existing resource.
  • target (str) – Name of the entity to patch.
  • verb (str) – The method to call on the API.
  • **kwargs (dict) – Optional additional arguments to pass to the api.
Returns:

The API response containing the async operation.

Return type:

dict

Raises:

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

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.

class UpdateResourceMixin[source]

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

Mixin that implements the Update API command for resources.

update(resource, data, target=None, verb='update', **kwargs)[source]

Update an existing resource.

Parameters:
  • self (GCPRespository) – An instance of a GCPRespository class.
  • resource (str) – Name of the parent resource to update the resource under.
  • data (dict) – The json representation of the resource to update, this will replace the existing resource.
  • target (str) – Name of the entity to update.
  • verb (str) – The method to call on the API.
  • **kwargs (dict) – Optional additional arguments to pass to the api.
Returns:

The API response containing the async operation.

Return type:

dict

Raises:

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

class _ModifyResourceBaseMixin[source]

Bases: object

Base class for Patch and Update Mixins.

_modify_resource(resource, data, target, verb, **kwargs)[source]

Patch or update an existing resource.

Parameters:
  • self (GCPRespository) – An instance of a GCPRespository class.
  • resource (str) – Name of the parent resource to modify the resource under.
  • data (dict) – The json representation of the resource to modify, this will update the existing resource.
  • target (str) – Name of the entity to modify.
  • verb (str) – The method to call on the API.
  • **kwargs (dict) – Optional additional arguments to pass to the api.
Returns:

The API response containing the async operation.

Return type:

dict

Raises:

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

_create_fake_operation(resource_link, verb, name)[source]

Creates a fake operation resource dictionary for dry run.

Parameters:
  • resource_link (str) – The full URL to the resource the operation would have modified.
  • verb (str) – The API method the operation would have been for.
  • name (str) – The operation name, can be any string.
Returns:

A fake Operation resource.

Return type:

dict