google.cloud.forseti.services.base.config module

Base classes required for handling configuration of the gRPC server.

class AbstractInventoryConfig[source]

Bases: dict

Abstract base class for service configuration.

This class is used to implement dependency injection for the gRPC services.

_abc_cache = <_weakrefset.WeakSet object>
_abc_negative_cache = <_weakrefset.WeakSet object>
_abc_negative_cache_version = 190
_abc_registry = <_weakrefset.WeakSet object>
get_api_quota_configs()[source]

Returns the per API quota configs.

Raises:NotImplementedError – Abstract.
get_cai_enabled()[source]

Returns True if the cloudasset API should be used for the inventory.

Raises:NotImplementedError – Abstract.
get_cai_gcs_path()[source]

Returns the GCS bucket path to store the CAI data dumps in.

Raises:NotImplementedError – Abstract.
get_gsuite_admin_email()[source]

Returns gsuite admin email.

Raises:NotImplementedError – Abstract.
get_retention_days_configs()[source]

Returns the days of inventory data to retain.

Raises:NotImplementedError – Abstract.
get_root_resource_id()[source]

Returns the root resource id.

Raises:NotImplementedError – Abstract.
get_service_config()[source]

Returns the service config.

Raises:NotImplementedError – Abstract.
set_service_config(service_config)[source]

Attach a service configuration.

Parameters:service_config (object) – Service configuration.
Raises:NotImplementedError – Abstract.
class AbstractServiceConfig[source]

Bases: object

Abstract base class for service configuration.

This class is used to implement dependency injection for the gRPC services.

_abc_cache = <_weakrefset.WeakSet object>
_abc_negative_cache = <_weakrefset.WeakSet object>
_abc_negative_cache_version = 190
_abc_registry = <_weakrefset.WeakSet object>
client()[source]

Get an API client.

Raises:NotImplementedError – Abstract.
get_engine()[source]

Get the database engine.

Raises:NotImplementedError – Abstract.
get_storage_class()[source]

Returns the class used for the inventory storage.

Raises:NotImplementedError – Abstract.
run_in_background(func)[source]

Runs a function in a thread pool in the background.

Parameters:func (Function) – Function to be executed.
Raises:NotImplementedError – Abstract.
scoped_session()[source]

Get a scoped session.

Raises:NotImplementedError – Abstract.
class InventoryConfig(root_resource_id, gsuite_admin_email, api_quota_configs, retention_days, cai_configs, *args, **kwargs)[source]

Bases: google.cloud.forseti.services.base.config.AbstractInventoryConfig

Implements composed dependency injection for the inventory.

_abc_cache = <_weakrefset.WeakSet object>
_abc_negative_cache = <_weakrefset.WeakSet object>
_abc_negative_cache_version = 190
_abc_registry = <_weakrefset.WeakSet object>
get_api_quota_configs()[source]

Returns the per API quota configs.

Returns:The API quota configurations.
Return type:dict
get_cai_enabled()[source]

Returns True if the cloudasset API should be used for the inventory.

Returns:Whether CAI should be integrated with the inventory or not.
Return type:bool
get_cai_gcs_path()[source]

Returns the GCS bucket path to store the CAI data dumps in.

Returns:The GCS bucket path for CAI data.
Return type:str
get_gsuite_admin_email()[source]

Return the gsuite admin email to use.

Returns:Gsuite admin email.
Return type:str
get_retention_days_configs()[source]

Returns the days of inventory data to retain.

Returns:The days of inventory data to retain.
Return type:int
get_root_resource_id()[source]

Return the configured root resource id.

Returns:Root resource id.
Return type:str
get_service_config()[source]

Return the attached service configuration.

Returns:Service configuration.
Return type:object
set_service_config(service_config)[source]

Attach a service configuration.

Parameters:service_config (object) – Service configuration.
class ServiceConfig(forseti_config_file_path, forseti_db_connect_string, endpoint)[source]

Bases: google.cloud.forseti.services.base.config.AbstractServiceConfig

Implements composed dependency injection to Forseti Server services.

_abc_cache = <_weakrefset.WeakSet object>
_abc_negative_cache = <_weakrefset.WeakSet object>
_abc_negative_cache_version = 190
_abc_registry = <_weakrefset.WeakSet object>
_read_from_config(config_file_path=None)[source]

Read from the forseti configuration file.

Parameters:config_file_path (str) – Forseti server config file path
Returns:(Forseti server configuration, Error message)
Return type:tuple(dict, str)
client()[source]

Get an API client.

Returns:API client to use against services.
Return type:object
get_engine()[source]

Get the database engine.

Returns:Database engine object.
Return type:object
get_forseti_config()[source]

Get the Forseti config.

Returns:Forseti config.
Return type:dict
get_global_config()[source]

Get the global config.

Returns:Global config.
Return type:dict
get_inventory_config()[source]

Get the inventory config.

Returns:Inventory config.
Return type:object
get_notifier_config()[source]

Get the notifier config.

Returns:Notifier config.
Return type:dict
get_scanner_config()[source]

Get the scanner config.

Returns:Scanner config.
Return type:dict
get_storage_class()[source]

Returns the storage class used to access the inventory.

Returns:Type of a storage implementation.
Return type:class
run_in_background(func)[source]

Runs a function in a thread pool in the background.

Parameters:func (Function) – Function to be executed.
scoped_session()[source]

Get a scoped session.

Returns:A scoped session.
Return type:object
update_configuration(config_file_path=None)[source]

Update the inventory, scanner, global and notifier configurations.

Parameters:config_file_path (str) – Forseti server config file path.
Returns:(Configuration was updated, Error message)
Return type:tuple(bool, str)
_validate_cai_enabled(root_resource_id, cai_configs)[source]

Verifies if CloudAsset Inventory can be used for this inventory config.

Parameters:
  • root_resource_id (str) – Root resource to start crawling from
  • cai_configs (dict) – Settings for the Cloud AssetInventory API
Returns:

True if CAI is supported and enabled by configuration, else False.

Return type:

bool