tacker.api.common.attribute_filter module

class tacker.api.common.attribute_filter.ParseState

Bases: object

Implement the core of parsing the policy language.

Uses a greedy reduction algorithm to reduce a sequence of tokens into a single terminal, the value of which will be the root of the Filter tree.

Note

Error reporting is rather lacking. The best we can get with this parser formulation is an overall “parse failed” error. Fortunately, the policy language is simple enough that this shouldn’t be that big a problem.

reduce()

Perform a greedy reduction of the token stream.

If a reducer method matches, it will be executed, then the reduce() method will be called recursively to search for any more possible reductions.

reducers = [(['(', 'and_expr', ')'], '_wrap_check'), (['(', 'filter', ')'], '_wrap_check'), (['filter', 'and', 'filter'], '_make_and_expr'), (['and_expr', 'and', 'filter'], '_extend_and_expr')]
property result

Obtain the final result of the parse.

Raises:

ValueError – If the parse failed to reduce to a single result.

shift(tok, value)

Adds one more token to the state.

Calls reduce().

class tacker.api.common.attribute_filter.ParseStateMeta(name, bases, cls_dict)

Bases: type

Metaclass for the ParseState class.

Facilitates identifying reduction methods.

tacker.api.common.attribute_filter.parse_filter_rule(filter_rule, target=None)

Parses filter query parameter to the tree.

Translates a filter written in the filter language into a tree of Filter objects.

tacker.api.common.attribute_filter.reducer(*tokens)

Decorator for reduction methods.

Arguments are a sequence of tokens, in order, which should trigger running this reduction method.