Google Cloud Asset

See the official Asset API Python Client documentation here: link.

Classes

class bibt.gcp.asset.classes.Client(gcp_org_id, credentials=None)[source]

Instantiates a Client object for further API calls.

from bibt.gcp import asset

client = asset.Client(os.environ["GCP_ORG_ID"])
asset = client.get_asset(...)
Parameters:
  • gcp_org_id (str) – your GCP organization ID. needed to query the Cloud Asset Inventory API.

  • credentials (google_auth:google.oauth2.credentials.Credentials) – the credentials object to use when making API calls, if not using the account running the function for authentication.

get_asset(scope, asset_name, asset_types=None, detailed=True, page_size=1000)[source]

Get a specific asset by name from the CAI API.

Parameters:
  • scope (str) – the parent resource to search under. Can be one of: organizations/1234, folders/1234, projects/1234, or projects/name.

  • asset_name (str) – the name of the asset, in the form of //cloudsql.googleapis.com/projects/my-project/instances/my-db.

  • asset_types (list) – a list of asset types to return, in the format compute.googleapis.com/Disk (for example). See here for all supported types.

  • detailed (bool) – if true, will get the full resource metadata from a list_assets call, otherwise just returns basic metadata from search_assets.

  • page_size (int) – the number of results to return per page. a lower number will result in more API calls.

Return type:

Asset

Returns:

an asset object (or None).

get_parent_project(scope, asset)[source]

For a given scope and asset, attempts to retrieve the parent project. If a project, folder, or organization is passed, simply returns that.

Parameters:
  • scope (str) – the parent resource to search under. Can be one of: organizations/1234, folders/1234, projects/1234, or projects/name.

  • asset (Asset) – the asset object for which to return the parent.

Return type:

Asset

Returns:

an asset object representing a project, folder, or organization (or None).

list_assets(parent, asset_types=None, content_type=None, page_size=1000)[source]
List assets from the CAI API. For more information, view

the documentation.

Parameters:
  • parent (str) – the parent resource to search under. Can be one of: organizations/1234, folders/1234, projects/1234, or projects/name.

  • asset_types (list) – a list of asset types to return, in the format compute.googleapis.com/Disk (for example). See here for all supported types.

  • content_type (str) – the type of data to return. usually you’ll want RESOURCE, but can be any value from here.

  • page_size (int) – the number of results to return per page. a lower number will result in more API calls.

Return type:

ListAssetsPager

Returns:

a pager which may be iterated on to retrieve results. contains Asset objects.

search_asset_iam_policy(scope, query)[source]

Search IAM policies from the CAI API. For more information, view the documentation.

Parameters:
  • scope (str) – the parent resource to search under. Can be one of: organizations/1234, folders/1234, projects/1234, or projects/name.

  • query (str) – an asset query, see here for more information.

Return type:

SearchAllIamPoliciesPager

Returns:

a pager which may be iterated on to retrieve results. contains IamPolicySearchResult objects.

search_assets(scope, query, asset_types=None, order_by=None, page_size=1000)[source]

Search assets from the CAI API. This provides minimal asset metadata, use list_assets for full information. For more information, view the documentation.

Parameters:
  • scope (str) – the parent resource to search under. Can be one of: organizations/1234, folders/1234, projects/1234, or projects/name.

  • query (str) – an asset query, see here for more information.

  • asset_types (list) – a list of asset types to return, in the format compute.googleapis.com/Disk (for example). See here for all supported types.

  • order_by (str) – the field(s) to order results by. sorting can increase response wait time. view the documentation linked above for usable fields.

  • page_size (int) – the number of results to return per page. a lower number will result in more API calls.

Return type:

SearchAllResourcesPager

Returns:

a pager which may be iterated on to retrieve results. contains ResourceSearchResult objects.