scopie 0.1.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- scopie-0.1.0/LICENSE +21 -0
- scopie-0.1.0/PKG-INFO +26 -0
- scopie-0.1.0/README.md +2 -0
- scopie-0.1.0/pyproject.toml +34 -0
- scopie-0.1.0/setup.cfg +4 -0
- scopie-0.1.0/src/scopie/__init__.py +0 -0
- scopie-0.1.0/src/scopie/scopie.py +124 -0
- scopie-0.1.0/src/scopie.egg-info/PKG-INFO +26 -0
- scopie-0.1.0/src/scopie.egg-info/SOURCES.txt +9 -0
- scopie-0.1.0/src/scopie.egg-info/dependency_links.txt +1 -0
- scopie-0.1.0/src/scopie.egg-info/top_level.txt +1 -0
scopie-0.1.0/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2024 Ronnie
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
scopie-0.1.0/PKG-INFO
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: scopie
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: Authorization engine providing fine grained access while you control the data. Aimed at being easy to use and implement without overtaking other parts of your system.
|
|
5
|
+
Author-email: Ronnie Smith <miniscruff@hey.com>
|
|
6
|
+
License-Expression: MIT
|
|
7
|
+
Project-URL: Homepage, https://github.com/miniscruff/scopie-py
|
|
8
|
+
Project-URL: Documentation, https://github.com/miniscruff/scopie-py
|
|
9
|
+
Project-URL: Repository, https://github.com/miniscruff/scopie-py.git
|
|
10
|
+
Project-URL: Issues, https://github.com/miniscruff/scopie-py/issues
|
|
11
|
+
Project-URL: Changelog, https://github.com/miniscruff/scopie-py/blob/main/CHANGELOG.md
|
|
12
|
+
Keywords: authorization
|
|
13
|
+
Classifier: Development Status :: 3 - Alpha
|
|
14
|
+
Classifier: Intended Audience :: Developers
|
|
15
|
+
Classifier: Programming Language :: Python :: 3
|
|
16
|
+
Classifier: Programming Language :: Python :: 3.9
|
|
17
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
18
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
19
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
20
|
+
Requires-Python: >=3.9
|
|
21
|
+
Description-Content-Type: text/markdown
|
|
22
|
+
License-File: LICENSE
|
|
23
|
+
Dynamic: license-file
|
|
24
|
+
|
|
25
|
+
# scopie-py
|
|
26
|
+
Python implementation of scopie
|
scopie-0.1.0/README.md
ADDED
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
[build-system]
|
|
2
|
+
requires = ["setuptools >= 61.0"]
|
|
3
|
+
build-backend = "setuptools.build_meta"
|
|
4
|
+
|
|
5
|
+
[project]
|
|
6
|
+
name = "scopie"
|
|
7
|
+
version = "v0.1.0"
|
|
8
|
+
authors = [
|
|
9
|
+
{name = "Ronnie Smith", email = "miniscruff@hey.com"},
|
|
10
|
+
]
|
|
11
|
+
description = "Authorization engine providing fine grained access while you control the data. Aimed at being easy to use and implement without overtaking other parts of your system."
|
|
12
|
+
readme = "README.md"
|
|
13
|
+
license = "MIT"
|
|
14
|
+
license-files = ["LICENSE"]
|
|
15
|
+
requires-python = ">=3.9"
|
|
16
|
+
keywords = ["authorization"]
|
|
17
|
+
classifiers = [
|
|
18
|
+
"Development Status :: 3 - Alpha",
|
|
19
|
+
"Intended Audience :: Developers",
|
|
20
|
+
"Programming Language :: Python :: 3",
|
|
21
|
+
"Programming Language :: Python :: 3.9",
|
|
22
|
+
"Programming Language :: Python :: 3.10",
|
|
23
|
+
"Programming Language :: Python :: 3.11",
|
|
24
|
+
"Programming Language :: Python :: 3.12",
|
|
25
|
+
]
|
|
26
|
+
[project.urls]
|
|
27
|
+
Homepage = "https://github.com/miniscruff/scopie-py"
|
|
28
|
+
Documentation = "https://github.com/miniscruff/scopie-py"
|
|
29
|
+
Repository = "https://github.com/miniscruff/scopie-py.git"
|
|
30
|
+
Issues = "https://github.com/miniscruff/scopie-py/issues"
|
|
31
|
+
Changelog = "https://github.com/miniscruff/scopie-py/blob/main/CHANGELOG.md"
|
|
32
|
+
|
|
33
|
+
[tool.setuptools.packages.find]
|
|
34
|
+
where = ["src"]
|
scopie-0.1.0/setup.cfg
ADDED
|
File without changes
|
|
@@ -0,0 +1,124 @@
|
|
|
1
|
+
from typing import List, Dict
|
|
2
|
+
from itertools import zip_longest
|
|
3
|
+
|
|
4
|
+
array_seperator = "|"
|
|
5
|
+
block_seperator = "/"
|
|
6
|
+
wildcard = "*"
|
|
7
|
+
var_prefix = "@"
|
|
8
|
+
|
|
9
|
+
allow_permission = "allow"
|
|
10
|
+
deny_permission = "deny"
|
|
11
|
+
|
|
12
|
+
allowed_extra_chars = {"_", "-", var_prefix, wildcard}
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
class ScopieError(Exception):
|
|
16
|
+
def __init__(self, msg: str):
|
|
17
|
+
self.msg = msg
|
|
18
|
+
|
|
19
|
+
def __eq__(self, other) -> bool:
|
|
20
|
+
return isinstance(other, ScopieError) and self.msg == other.msg
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
def is_valid_char(char: str) -> bool:
|
|
24
|
+
if char >= "a" and char <= "z":
|
|
25
|
+
return True
|
|
26
|
+
|
|
27
|
+
if char >= "A" and char <= "Z":
|
|
28
|
+
return True
|
|
29
|
+
|
|
30
|
+
if char >= "0" and char <= "9":
|
|
31
|
+
return True
|
|
32
|
+
|
|
33
|
+
return char in allowed_extra_chars
|
|
34
|
+
|
|
35
|
+
|
|
36
|
+
def compare_rule_to_scope(rule: str, scope: str, vars: dict) -> bool:
|
|
37
|
+
rule_blocks = rule.split(block_seperator)
|
|
38
|
+
scope_blocks = scope.split(block_seperator)
|
|
39
|
+
for i, (rule_block, scope_block) in enumerate(
|
|
40
|
+
zip_longest(rule_blocks[1:], scope_blocks)
|
|
41
|
+
):
|
|
42
|
+
if scope_block == "":
|
|
43
|
+
raise ScopieError("scopie-106 in scope: scope was empty")
|
|
44
|
+
|
|
45
|
+
if rule_block == "":
|
|
46
|
+
raise ScopieError("scopie-106 in rule: rule was empty")
|
|
47
|
+
|
|
48
|
+
if not scope_block or not rule_block:
|
|
49
|
+
return False
|
|
50
|
+
|
|
51
|
+
if rule_block == wildcard:
|
|
52
|
+
continue
|
|
53
|
+
|
|
54
|
+
if len(rule_block) == 2 and rule_block == wildcard + wildcard:
|
|
55
|
+
if i < len(rule_blocks) - 2:
|
|
56
|
+
raise ScopieError("scopie-105: super wildcard not in the last block")
|
|
57
|
+
|
|
58
|
+
return rule_blocks[0] == allow_permission
|
|
59
|
+
|
|
60
|
+
if rule_block[0] == var_prefix:
|
|
61
|
+
var_name = rule_block[1:]
|
|
62
|
+
if var_name not in vars:
|
|
63
|
+
raise ScopieError(f"scopie-104: variable '{var_name}' not found")
|
|
64
|
+
if vars[var_name] != scope_block:
|
|
65
|
+
return False
|
|
66
|
+
else:
|
|
67
|
+
rules_split = rule_block.split(array_seperator)
|
|
68
|
+
|
|
69
|
+
for rule_split in rules_split:
|
|
70
|
+
if rule_split[0] == var_prefix:
|
|
71
|
+
raise ScopieError(
|
|
72
|
+
f"scopie-101: variable '{rule_split[1:]}' found in array block"
|
|
73
|
+
)
|
|
74
|
+
|
|
75
|
+
if (
|
|
76
|
+
rule_split[0] == wildcard
|
|
77
|
+
and len(rule_split) > 1
|
|
78
|
+
and rule_split[1] == wildcard
|
|
79
|
+
):
|
|
80
|
+
raise ScopieError("scopie-103: super wildcard found in array block")
|
|
81
|
+
|
|
82
|
+
if rule_split[0] == wildcard:
|
|
83
|
+
raise ScopieError("scopie-102: wildcard found in array block")
|
|
84
|
+
|
|
85
|
+
for c in rule_split:
|
|
86
|
+
if not is_valid_char(c):
|
|
87
|
+
raise ScopieError(
|
|
88
|
+
f"scopie-100 in rule: invalid character '{c}'"
|
|
89
|
+
)
|
|
90
|
+
|
|
91
|
+
for c in scope_block:
|
|
92
|
+
if not is_valid_char(c):
|
|
93
|
+
raise ScopieError(f"scopie-100 in scope: invalid character '{c}'")
|
|
94
|
+
|
|
95
|
+
if scope_block not in rules_split:
|
|
96
|
+
return False
|
|
97
|
+
|
|
98
|
+
return True
|
|
99
|
+
|
|
100
|
+
|
|
101
|
+
def is_allowed(
|
|
102
|
+
scopes: List[str],
|
|
103
|
+
rules: List[str],
|
|
104
|
+
**vars: Dict[str, str],
|
|
105
|
+
) -> bool:
|
|
106
|
+
has_been_allowed = False
|
|
107
|
+
if not rules:
|
|
108
|
+
return False
|
|
109
|
+
|
|
110
|
+
if rules[0] == "":
|
|
111
|
+
raise ScopieError("scopie-106 in rule: rule was empty")
|
|
112
|
+
|
|
113
|
+
if len(scopes) == 0:
|
|
114
|
+
raise ScopieError("scopie-106 in scope: scopes was empty")
|
|
115
|
+
|
|
116
|
+
for rule in rules:
|
|
117
|
+
for scope in scopes:
|
|
118
|
+
match = compare_rule_to_scope(rule, scope, vars)
|
|
119
|
+
if match and rule.startswith(deny_permission):
|
|
120
|
+
return False
|
|
121
|
+
elif match:
|
|
122
|
+
has_been_allowed = True
|
|
123
|
+
|
|
124
|
+
return has_been_allowed
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: scopie
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: Authorization engine providing fine grained access while you control the data. Aimed at being easy to use and implement without overtaking other parts of your system.
|
|
5
|
+
Author-email: Ronnie Smith <miniscruff@hey.com>
|
|
6
|
+
License-Expression: MIT
|
|
7
|
+
Project-URL: Homepage, https://github.com/miniscruff/scopie-py
|
|
8
|
+
Project-URL: Documentation, https://github.com/miniscruff/scopie-py
|
|
9
|
+
Project-URL: Repository, https://github.com/miniscruff/scopie-py.git
|
|
10
|
+
Project-URL: Issues, https://github.com/miniscruff/scopie-py/issues
|
|
11
|
+
Project-URL: Changelog, https://github.com/miniscruff/scopie-py/blob/main/CHANGELOG.md
|
|
12
|
+
Keywords: authorization
|
|
13
|
+
Classifier: Development Status :: 3 - Alpha
|
|
14
|
+
Classifier: Intended Audience :: Developers
|
|
15
|
+
Classifier: Programming Language :: Python :: 3
|
|
16
|
+
Classifier: Programming Language :: Python :: 3.9
|
|
17
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
18
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
19
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
20
|
+
Requires-Python: >=3.9
|
|
21
|
+
Description-Content-Type: text/markdown
|
|
22
|
+
License-File: LICENSE
|
|
23
|
+
Dynamic: license-file
|
|
24
|
+
|
|
25
|
+
# scopie-py
|
|
26
|
+
Python implementation of scopie
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
scopie
|