c7n_gcp package¶
Subpackages¶
- c7n_gcp.actions package
- c7n_gcp.filters package
- c7n_gcp.resources package
- Submodules
- c7n_gcp.resources.appengine module
- c7n_gcp.resources.bigquery module
- c7n_gcp.resources.build module
- c7n_gcp.resources.cloudbilling module
- c7n_gcp.resources.compute module
- c7n_gcp.resources.dataflow module
- c7n_gcp.resources.deploymentmanager module
- c7n_gcp.resources.dns module
- c7n_gcp.resources.function module
- c7n_gcp.resources.gke module
- c7n_gcp.resources.iam module
- c7n_gcp.resources.loadbalancer module
- c7n_gcp.resources.logging module
- c7n_gcp.resources.mlengine module
- c7n_gcp.resources.network module
- c7n_gcp.resources.pubsub module
- c7n_gcp.resources.resourcemanager module
- c7n_gcp.resources.service module
- c7n_gcp.resources.source module
- c7n_gcp.resources.spanner module
- c7n_gcp.resources.sql module
- c7n_gcp.resources.storage module
- Module contents
Submodules¶
c7n_gcp.client module¶
Base GCP client which uses the discovery API.
-
exception
c7n_gcp.client.
PaginationNotSupported
[source]¶ Bases:
Exception
Pagination not supported on this api.
-
class
c7n_gcp.client.
ServiceClient
(gcp_service, credentials, component=None, num_retries=5, key_field='project', entity_field=None, list_key_field=None, get_key_field=None, max_results_field='maxResults', search_query_field='query', rate_limiter=None, use_cached_http=True, http=None)[source]¶ Bases:
object
Base class for GCP APIs.
-
execute_command
(verb, verb_arguments)[source]¶ Executes command (ex. add) via a dedicated http object.
Async APIs may take minutes to complete. Therefore, callers are encouraged to leverage concurrent.futures (or similar) to place long running commands on a separate threads.
- Args:
verb (str): Method to execute on the component (ex. get, list). verb_arguments (dict): key-value pairs to be passed to _build_request.
- Returns:
dict: An async operation Service Response.
-
execute_paged_query
(verb, verb_arguments)[source]¶ Executes query (ex. list) via a dedicated http object.
- Args:
verb (str): Method to execute on the component (ex. get, list). verb_arguments (dict): key-value pairs to be passed to _BuildRequest.
- Yields:
dict: Service Response.
- Raises:
PaginationNotSupportedError: When an API does not support paging.
-
execute_query
(verb, verb_arguments)[source]¶ Executes query (ex. get) via a dedicated http object.
- Args:
verb (str): Method to execute on the component (ex. get, list). verb_arguments (dict): key-value pairs to be passed to _BuildRequest.
- Returns:
dict: Service Response.
-
execute_search_query
(verb, verb_arguments)[source]¶ Executes query (ex. search) via a dedicated http object.
- Args:
verb (str): Method to execute on the component (ex. search). verb_arguments (dict): key-value pairs to be passed to _BuildRequest.
- Yields:
dict: Service Response.
-
http
¶ A thread local instance of httplib2.Http.
- Returns:
httplib2.Http: An Http instance authorized by the credentials.
-
-
class
c7n_gcp.client.
Session
(credentials=None, quota_max_calls=None, quota_period=None, use_rate_limiter=False, http=None, project_id=None, **kwargs)[source]¶ Bases:
object
Base class for API repository for a specified Cloud API.
c7n_gcp.handler module¶
c7n_gcp.mu module¶
-
class
c7n_gcp.mu.
ApiSubscriber
(session, data)[source]¶ Bases:
c7n_gcp.mu.EventSource
Subscribe to individual api calls
via audit log -> filtered sink -> pub/sub topic -> cloud function.
-
class
c7n_gcp.mu.
BucketEvent
(session, data=None)[source]¶ Bases:
c7n_gcp.mu.EventSource
-
collection_id
= 'cloudfunctions.projects.buckets'¶
-
events
= ['google.storage.object.finalize', 'google.storage.object.archive', 'google.storage.object.delete', 'google.storage.object.metadataUpdate', 'providers/cloud.storage/eventTypes/object.change']¶
-
trigger
= 'google.storage.object.finalize'¶
-
-
class
c7n_gcp.mu.
CloudFunction
(func_data, archive=None)[source]¶ Bases:
object
-
environment
¶
-
events
¶
-
labels
¶
-
max_instances
¶
-
memory_size
¶
-
name
¶
-
network
¶
-
runtime
¶
-
service_account
¶
-
timeout
¶
-
-
class
c7n_gcp.mu.
HTTPEvent
(session, data=None)[source]¶ Bases:
c7n_gcp.mu.EventSource
Internet exposed http endpoint for cloud function
-
class
c7n_gcp.mu.
LogInfo
(name, scope_type, scope_id, id)¶ Bases:
tuple
-
id
¶ Alias for field number 3
-
name
¶ Alias for field number 0
-
scope_id
¶ Alias for field number 2
-
scope_type
¶ Alias for field number 1
-
-
class
c7n_gcp.mu.
LogSubscriber
(session, data)[source]¶ Bases:
c7n_gcp.mu.EventSource
Composite as a log sink
- subscriber = LogSubscriber(dict(
log=’projects/custodian-1291/logs/cloudaudit.googleapis.com%2Factivity’))
function = CloudFunction(dict(name=’log-sub’, events=[subscriber])
-
class
c7n_gcp.mu.
PeriodicEvent
(session, data)[source]¶ Bases:
c7n_gcp.mu.EventSource
Periodic serverless execution.
Supports both http and pub/sub triggers.
Note periodic requires the setup of app engine and is restricted to app engine locations. https://cloud.google.com/scheduler/docs/setup
Schedule can be specified in either cron syntax or app engine schedule expression. https://cloud.google.com/scheduler/docs/configuring/cron-job-schedules
Examples of schedule expressions. https://cloud.google.com/appengine/docs/standard/python/config/cronref
-
target_type
¶
-
-
class
c7n_gcp.mu.
PolicyFunction
(policy, archive=None, events=())[source]¶ Bases:
c7n_gcp.mu.CloudFunction
-
events
¶
-
name
¶
-
c7n_gcp.output module¶
TODO: provider policy execution initialization for outputs
-
class
c7n_gcp.output.
GCPStorageOutput
(ctx, config=None)[source]¶ Bases:
c7n.output.DirectoryOutput
-
type
= 'gs'¶
-
-
class
c7n_gcp.output.
StackDriverLogging
(ctx, config=None)[source]¶ Bases:
c7n.output.LogOutput
-
class
c7n_gcp.output.
StackDriverMetrics
(ctx, config=None)[source]¶ Bases:
c7n.output.Metrics
-
DESCRIPTOR_COMMON
= {'labels': [{'key': 'policy', 'valueType': 'STRING', 'description': 'Custodian Policy'}], 'metricsKind': 'GAUGE'}¶
-
METRICS_DESCRIPTORS
= {'actiontime': {'description': 'Time to perform actions for a given policy', 'displayName': 'Action Time', 'type': '%s/%s', 'units': 's', 'valueType': 'DOUBLE'}, 'resourcecount': {'description': 'Number of resources that matched the given policy', 'displayName': 'Resources', 'type': '%s/%', 'units': 'items', 'valueType': 'INT64'}, 'resourcetime': {'description': 'Time to query the resources for a given policy', 'displayName': 'Query Time', 'type': '%s/%s', 'units': 's', 'valueType': 'DOUBLE'}}¶
-
METRICS_PREFIX
= 'custom.googleapis.com/custodian/policy'¶
-
initialize
()[source]¶ One time initialization of metrics descriptors.
# tbd - unclear if this adding significant value.
-
log
= <Logger c7n_gcp.metrics (INFO)>¶
-
type
= 'gcp'¶
-
c7n_gcp.policy module¶
-
class
c7n_gcp.policy.
ApiAuditMode
(policy)[source]¶ Bases:
c7n_gcp.policy.FunctionMode
Custodian policy execution on gcp api audit logs
-
schema
= {'additionalProperties': False, 'properties': {'environment': {'type': 'object'}, 'execution-options': {'type': 'object'}, 'labels': {'type': 'object'}, 'max-instances': {'type': 'integer'}, 'memory-size': {'type': 'integer'}, 'methods': {'items': {'type': 'string'}, 'type': 'array'}, 'network': {'type': 'string'}, 'region': {'type': 'string'}, 'service-account': {'type': 'string'}, 'timeout': {'type': 'string'}, 'type': {'enum': ['gcp-audit']}}, 'required': ['methods', 'type'], 'type': 'object'}¶
-
type
= 'gcp-audit'¶
-
-
class
c7n_gcp.policy.
FunctionMode
(policy)[source]¶ Bases:
c7n.policy.ServerlessExecutionMode
-
schema
= {'additionalProperties': False, 'properties': {'environment': {'type': 'object'}, 'execution-options': {'type': 'object'}, 'labels': {'type': 'object'}, 'max-instances': {'type': 'integer'}, 'memory-size': {'type': 'integer'}, 'network': {'type': 'string'}, 'region': {'type': 'string'}, 'service-account': {'type': 'string'}, 'timeout': {'type': 'string'}, 'type': {'enum': ['gcp']}}, 'required': ['type'], 'type': 'object'}¶
-
-
class
c7n_gcp.policy.
PeriodicMode
(policy)[source]¶ Bases:
c7n_gcp.policy.FunctionMode
,c7n.policy.PullMode
-
schema
= {'additionalProperties': False, 'properties': {'environment': {'type': 'object'}, 'execution-options': {'type': 'object'}, 'labels': {'type': 'object'}, 'max-instances': {'type': 'integer'}, 'memory-size': {'type': 'integer'}, 'network': {'type': 'string'}, 'region': {'type': 'string'}, 'schedule': {'type': 'string'}, 'service-account': {'type': 'string'}, 'timeout': {'type': 'string'}, 'trigger-type': {'enum': ['http', 'pubsub']}, 'type': {'enum': ['gcp-periodic']}, 'tz': {'type': 'string'}}, 'required': ['schedule', 'type'], 'type': 'object'}¶
-
type
= 'gcp-periodic'¶
-
c7n_gcp.provider module¶
-
class
c7n_gcp.provider.
GoogleCloud
[source]¶ Bases:
c7n.provider.Provider
-
initialize_policies
(policy_collection, options)[source]¶ Perform any initialization of policies.
Common usage is expanding policy collection for per region execution and filtering policies for applicable regions.
-
resource_prefix
= 'gcp'¶
-
resources
= <c7n.registry.PluginRegistry object>¶
-
type
= 'gcp'¶
-
c7n_gcp.query module¶
-
class
c7n_gcp.query.
ChildResourceManager
(data, options)[source]¶ Bases:
c7n_gcp.query.QueryResourceManager
-
action_registry
= <c7n.actions.core.ActionRegistry object>¶
-
filter_registry
= <c7n.filters.core.FilterRegistry object>¶
-
-
class
c7n_gcp.query.
ChildTypeInfo
[source]¶ Bases:
c7n_gcp.query.TypeInfo
-
parent_spec
= None¶
-
-
class
c7n_gcp.query.
QueryMeta
[source]¶ Bases:
type
metaclass to have consistent action/filter registry for new resources.
-
class
c7n_gcp.query.
QueryResourceManager
(data, options)[source]¶ Bases:
c7n.manager.ResourceManager
-
action_registry
= <c7n.actions.core.ActionRegistry object>¶
-
filter_registry
= <c7n.filters.core.FilterRegistry object>¶
-
source_type
¶
-