google.cloud.forseti.common.gcp_api.cloudasset module

Wrapper for Cloud Asset API client.

class CloudAssetClient(global_configs, **kwargs)[source]

Bases: object

Cloud Asset Client.

OPERATION_DELAY_IN_SEC = 5.0
export_assets(parent, destination_object, content_type=None, asset_types=None, blocking=False, timeout=0)[source]

Export assets under a parent resource to the destination GCS object.

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.
  • blocking (bool) – If true, don’t return until the async operation completes on the backend or timeout seconds pass.
  • timeout (float) – If greater than 0 and blocking is True, then raise an exception if timeout seconds pass before the operation completes.
Returns:

Operation status and info.

Return type:

dict

Raises:
  • ApiExecutionError – Returns if there is an error in the API response.
  • OperationTimeoutError – Raised if the operation times out.
  • ValueError – Raised on invalid parent resource name.
get_operation(operation_name)[source]

Get the Operations Status.

Parameters:

operation_name (str) – The name of the operation to get.

Returns:

Operation status and info.

Return type:

dict

Raises:
  • ApiExecutionError – Returns if there is an error in the API response.
  • ValueError – Raised on invalid parent resource name.
wait_for_completion(parent, operation, timeout=0, initial_delay=None, retry_delay=None)[source]

Wait for the operation to complete.

Parameters:
  • parent (str) – The name of the parent resource to export assests under.
  • operation (dict) – The operation response from an API call.
  • timeout (float) – The maximum time to wait for the operation to complete.
  • initial_delay (float) – The time to wait before first checking if the API has completed. If None then the default value, configured as CloudAssetClient.OPERATION_DELAY_IN_SEC, is used.
  • retry_delay (float) – The time to wait between checking if the API has completed. If None then the default value, configured as CloudAssetClient.OPERATION_DELAY_IN_SEC, is used.
Returns:

Operation status and info.

Return type:

dict

Raises:

OperationTimeoutError – Raised if the operation times out.

class CloudAssetRepositoryClient(quota_max_calls=None, quota_period=60.0, use_rate_limiter=True)[source]

Bases: google.cloud.forseti.common.gcp_api._base_repository.BaseRepositoryClient

Cloud Asset API Respository.

operations

Returns a _CloudAssetOperationsRepository instance.

top_level

Returns a _CloudAssetV1Repository instance.

class _CloudAssetOperationsRepository(**kwargs)[source]

Bases: google.cloud.forseti.common.gcp_api.repository_mixins.GetQueryMixin, google.cloud.forseti.common.gcp_api._base_repository.GCPRepository

Implementation of Cloud Asset Operations repository.

class _CloudAssetV1Repository(**kwargs)[source]

Bases: google.cloud.forseti.common.gcp_api.repository_mixins.ExportAssetsQueryMixin, google.cloud.forseti.common.gcp_api._base_repository.GCPRepository

Implementation of Cloud Asset V1 repository.