diff options
author | Frederick Muriuki Muriithi | 2025-07-22 17:03:37 -0500 |
---|---|---|
committer | Frederick Muriuki Muriithi | 2025-07-22 17:03:37 -0500 |
commit | 7522a8eb4232a4fcb03c1af41b70e3f9c25702ca (patch) | |
tree | 626edd84870917ee5900251c97b03037d5bd0b9d /gn_libs | |
parent | 2fae0c6811fe53494e0cfbffc93b15450ecf5423 (diff) | |
download | gn-libs-7522a8eb4232a4fcb03c1af41b70e3f9c25702ca.tar.gz |
Begin working on simple DSL for privileges checking.
Diffstat (limited to 'gn_libs')
-rw-r--r-- | gn_libs/privileges.py | 28 |
1 files changed, 28 insertions, 0 deletions
diff --git a/gn_libs/privileges.py b/gn_libs/privileges.py new file mode 100644 index 0000000..47cb735 --- /dev/null +++ b/gn_libs/privileges.py @@ -0,0 +1,28 @@ +"""Utilities for handling privileges.""" +from typing import Union, TypeAlias + +PrivilegesList = tuple[str, ...] +CheckObj = tuple[str, PrivilegesList] # where the first item is either "OR" or "AND" +Checks: TypeAlias = Union[ + CheckObj, + tuple[str, tuple['Checks', ...]]] + + +class SpecificationValueError(ValueError): + """Raised when there is an error in the specification string.""" + pass + + +def parse(spec: str) -> Checks: + """Parse a string specification for privileges and return a tree of data + objects of the form (<operator> (<check>))""" + # if(spec.strip() == ""): + # raise SpecificationValueError( + # "You passed an empty specification. I do not know what to do.") + + return tuple() + + +def check(spec: str, privileges: tuple[str, ...]) -> bool: + """Check that the sequence of `privileges` satisfies `spec`.""" + return False |