Coverage for /pythoncovmergedfiles/medio/medio/usr/local/lib/python3.8/site-packages/c7n_gcp/resources/function.py: 90%
39 statements
« prev ^ index » next coverage.py v7.3.2, created at 2023-12-08 06:51 +0000
« prev ^ index » next coverage.py v7.3.2, created at 2023-12-08 06:51 +0000
1# Copyright The Cloud Custodian Authors.
2# SPDX-License-Identifier: Apache-2.0
4from c7n.utils import type_schema
6from c7n_gcp.actions import MethodAction
7from c7n_gcp.filters import IamPolicyFilter
8from c7n_gcp.provider import resources
9from c7n_gcp.query import QueryResourceManager, TypeInfo
12@resources.register('function')
13class Function(QueryResourceManager):
15 class resource_type(TypeInfo):
16 service = 'cloudfunctions'
17 version = 'v1'
18 component = 'projects.locations.functions'
19 enum_spec = ('list', 'functions[]', None)
20 scope = 'project'
21 scope_key = 'parent'
22 scope_template = "projects/{}/locations/-"
23 name = id = "name"
24 metric_key = "resource.labels.function_name"
25 default_report_fields = [
26 'name', 'runtime', 'eventTrigger.eventType', 'status', 'updateTime']
28 events = {
29 'create': 'google.cloud.functions.v1.CloudFunctionsService.CreateFunction',
30 'delete': 'google.cloud.functions.v1.CloudFunctionsService.DeleteFunction',
31 'update': 'google.cloud.functions.v1.CloudFunctionsService.UpdateFunction'}
32 urn_component = "function"
33 asset_type = "cloudfunctions.googleapis.com/CloudFunction"
35 @staticmethod
36 def get(client, resource_info):
37 return client.execute_command(
38 'get', {'name': (
39 'projects/{project_id}/locations/'
40 '{location_id}/functions/{function_name}').format(
41 **resource_info)})
43 @classmethod
44 def _get_location(cls, resource):
45 "The region is the fourth segment of the name."
46 return resource["name"].split('/')[3]
48 @classmethod
49 def _get_urn_id(cls, resource):
50 "The id is the last segment of the name ."
51 return resource["name"].split('/', 6)[-1]
54@Function.filter_registry.register('iam-policy')
55class FunctionIamPolicyFilter(IamPolicyFilter):
56 """
57 Overrides the base implementation to process function resources correctly.
58 """
59 permissions = ('cloudfunctions.functions.getIamPolicy',)
62@Function.action_registry.register('delete')
63class Delete(MethodAction):
65 schema = type_schema('delete')
66 method_spec = {'op': 'delete'}
68 def get_resource_params(self, model, resource):
69 return {'name': resource['name']}