-
Notifications
You must be signed in to change notification settings - Fork 26
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
Modified action.py in order to have filters in a more conveinent way #109
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -221,6 +221,19 @@ def do_method(self, module_path, cls, action, **kwargs): | |
method_fqdn = '%s.%s.%s' % (module_path, cls, action) | ||
self.logger.debug('Calling method "%s" with kwargs: %s' % (method_fqdn, str(kwargs))) | ||
|
||
if 'Filters' in kwargs.keys(): | ||
boto3_compliant_filters = [] | ||
for specified_filter in kwargs['Filters']: | ||
keyval = specified_filter.split('=') | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Does this mean its not possible to filter on anything with a = in the value now, as it will get split? For example what happens if I can give an AWS resource a tag or value with an = in? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yeah you're right, I haven't thought of that. It seems that the equal sign is an allowed character in both tag names and values... There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. suggestion, make |
||
vals = [] | ||
for entry in boto3_compliant_filters: | ||
if entry['Name'] == keyval[0]: | ||
vals = entry['Values'] | ||
boto3_compliant_filters.remove(entry) | ||
vals.append(keyval[1]) | ||
boto3_compliant_filters.append({'Name': keyval[0], 'Values': vals}) | ||
kwargs['Filters'] = boto3_compliant_filters | ||
|
||
resultset = getattr(obj, action)(**kwargs) | ||
formatted = self.resultsets.formatter(resultset) | ||
return formatted if isinstance(formatted, list) else [formatted] | ||
|
@@ -232,5 +245,17 @@ def do_function(self, module_path, action, **kwargs): | |
function_fqdn = '%s.%s' % (module_path, action) | ||
self.logger.debug('Calling function "%s" with kwargs: %s' % (function_fqdn, | ||
str(kwargs))) | ||
if 'Filters' in kwargs.keys(): | ||
boto3_compliant_filters = [] | ||
for specified_filter in kwargs['Filters']: | ||
keyval = specified_filter.split('=') | ||
vals = [] | ||
for entry in boto3_compliant_filters: | ||
if entry['Name'] == keyval[0]: | ||
vals = entry['Values'] | ||
boto3_compliant_filters.remove(entry) | ||
vals.append(keyval[1]) | ||
boto3_compliant_filters.append({'Name': keyval[0], 'Values': vals}) | ||
kwargs['Filters'] = boto3_compliant_filters | ||
|
||
return getattr(module, action)(**kwargs) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks like this is the same copy/paste code below. Please make this a function.