Luxon comes with a policy engine. Policy rule sets can be written in Json and will be compiled to Python.
luxon.core.policy.compiler.
compiler
()[source]¶Policy Rules Compiler.
Compiles rule set into python executable machine code for enhanced performance during conditional matching.
Example of rule_set in dict format:
{ 'role:admin': '"admin" in role_kwarg', 'user:login': '"login_kwarg" is True', 'match:both': '$role:admin or $system:login' }The syntax for the rule is exactly as per python conditional statements. Note these statements can be nested using braces ().
Parameters: | dict_rule_set (dict) – Rule Set loaded from JSON file for example. |
---|
luxon.core.policy.policy.
Policy
(rule_set=None, **kwargs)[source]¶Policy Rule Engine interface.
Used to validate rules against environmental arguements provided as kwargs.
rule_set can be provided which will be compiled for better performance.
Example of rule_set in dict format:
{ 'role:admin': '"admin" in role_kwarg', 'user:login': '"login_kwarg" is True', 'match:both': 'role:admin or system:login' }The syntax for the rule is exactly as per python conditional statements. Note these statements can be nested using braces ().
- By default following kwargs are given to policy runtime in wsgi:
- req being equel to the Request Object for the request.
Keyword Arguments: | |
---|---|
rule_set (dict) – Rule Set in dict loaded from JSON file for example. |
A helper function can be used to create Policy objects