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

Treat tag search as case insensitive #298

Open
nyetsche opened this issue Jul 20, 2016 · 5 comments
Open

Treat tag search as case insensitive #298

nyetsche opened this issue Jul 20, 2016 · 5 comments

Comments

@nyetsche
Copy link
Contributor

It'd be useful to have a flag that when filtering on tags, can match case-insensitively. Ideally everyone follows the rules...but it's also easy enough to get a mix of cases.

It seems that c7n/filters/core.py is where to fix that:

279         elif self.op:
280             op = OPERATORS[self.op]
281             return op(r, v)
282         elif r == self.v:
283             return True

but I'm not sure the best way to make that a parameter/flag. Add an element to the 'properties' definition, 'type': 'boolean'?

@kapilt
Copy link
Collaborator

kapilt commented Jul 20, 2016

value_type is where we're moving to do pre transforms before compares

@kapilt
Copy link
Collaborator

kapilt commented Jul 21, 2016

did you want case insensitive on the tag key or value or both

@nyetsche
Copy link
Contributor Author

Both I suppose. If I understand your previous comment, it's going to be something like:

value_type = [ string, string_insenstive, bool ]

in the configuration file? (Very loose pseudocode there)

@kapilt
Copy link
Collaborator

kapilt commented Jul 22, 2016

so for now (its mixed up in some other work on a pull request #299), its just doing the value. syntax looks like

 type: value
 key: "tag:SomeTag"
 value: rabbit
 value_type: normalize

would match "Rabbit "

@nyetsche
Copy link
Contributor Author

If there are tags that are not being searched for, this code:

        if self.k.startswith('tag:'):
            tk = self.k.split(':', 1)[1]
            r = None
            for t in i.get("Tags", []):
                if t.get('Key') == tk:
                    r = t.get('Value')
                    break

sets r to None, which then causes an attribute error on value:

    def process_value_type(self, sentinel, value):
        if self.vtype == 'normalize':
            return sentinel, value.strip().lower()

My fix was to change that to:

        if self.vtype == 'normalize':
            try:
                return sentinel, value.strip().lower()
            except AttributeError:
                return sentinel, None

Is a pull request better?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants