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
static build_bigquery_table_output(project_id, dataset, table, force=True)[source]

Creates an OutputConfig message for output to a BigQuery table.

Parameters:
  • project_id (str) – The project that hosts the dataset.
  • dataset (str) – The dataset name to output into.
  • table (str) – The table name to create for the export, the table must not exist.
  • force (bool) – If true, force write rows even on error.
static build_gcs_object_output(destination_object)[source]

Creates an OutputConfig message for output to GCS object.

Parameters: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 and the object must not exist.
Returns:an OutputConfig message.
Return type:dict
static build_gcs_prefix_output(destination_prefix)[source]

Creates an OutputConfig message for sharding output to a GCS prefix.

Parameters:destination_prefix (str) – The GCS bucket and folder path to store the results in. The bucket must be in the same project that has the Cloud Asset API enabled and the folder must not exist.
Returns:an OutputConfig message.
Return type:dict
export_assets(parent, destination_object=None, output_config=None, 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.
  • output_config (dict) – The full outputConfig message to pass to the export assets API. Should be built using one of the build_*_output_config methods.
  • 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.