Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

core - allow providers to customize resource registry including basic filters/actions #6490

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 3 additions & 1 deletion c7n/filters/core.py
Expand Up @@ -430,6 +430,7 @@ class ValueFilter(BaseValueFilter):
schema_alias = True
annotate = True
required_keys = {'value', 'key'}
value_resolver_class = ValuesFrom

def _validate_resource_count(self):
""" Specific validation for `resource_count` type
Expand Down Expand Up @@ -544,7 +545,8 @@ def match(self, i):
self.k = self.data.get('key')
self.op = self.data.get('op')
if 'value_from' in self.data:
values = ValuesFrom(self.data['value_from'], self.manager)
values = self.value_resolver_class(
self.data['value_from'], self.manager)
self.v = values.get_values()
else:
self.v = self.data.get('value')
Expand Down
7 changes: 7 additions & 0 deletions c7n/provider.py
Expand Up @@ -42,10 +42,17 @@ def initialize_policies(self, policy_collection, options):
region execution and filtering policies for applicable regions.
"""


@abc.abstractmethod
def get_session_factory(self, options):
"""Get a credential/session factory for api usage."""

@staticmethod
def initialize_resource(resource_class):
"""Perform initialize provider specific filter/action registry
registrations.
"""

@classmethod
def get_resource_types(cls, resource_types):
"""Return the resource classes for the given type names"""
Expand Down
16 changes: 16 additions & 0 deletions c7n/resources/aws.py
Expand Up @@ -511,6 +511,17 @@ def upload_file(self, path, key):
'ServerSideEncryption': 'AES256'})


class AwsValuesFrom(ValueFrom):
"""Support provider specific data sources.
"""


class AwsValueFilter(Value):

value_resolver_class = AwsValuesFrom



@clouds.register('aws')
class AWS(Provider):

Expand Down Expand Up @@ -538,6 +549,11 @@ def get_session_factory(self, options):
options.assume_role,
options.external_id)

@staticmethod
def initialize_resource(resource_class):
"""static method to initialize provider specific filter/actions"""
resource_class.filter_registry.register('value', AwsValueFilter)

def initialize_policies(self, policy_collection, options):
"""Return a set of policies targetted to the given regions.

Expand Down