tba-concrete-authorization-policy-rules 0.4.0.dev2__py3-none-any.whl
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.
- tba_concrete_authorization_policy_rules/__init__.py +120 -0
- tba_concrete_authorization_policy_rules/py.typed +0 -0
- tba_concrete_authorization_policy_rules-0.4.0.dev2.dist-info/METADATA +35 -0
- tba_concrete_authorization_policy_rules-0.4.0.dev2.dist-info/RECORD +5 -0
- tba_concrete_authorization_policy_rules-0.4.0.dev2.dist-info/WHEEL +4 -0
|
@@ -0,0 +1,120 @@
|
|
|
1
|
+
from __future__ import annotations
|
|
2
|
+
|
|
3
|
+
from dataclasses import dataclass, field
|
|
4
|
+
from typing import Any, Mapping
|
|
5
|
+
|
|
6
|
+
from tba_bases_authorization_policy import PolicyRuleBase
|
|
7
|
+
from tba_contracts_identity.policy.conditions import DynamicCondition
|
|
8
|
+
from tba_contracts_identity.policy.kinds import PolicyKind
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
def _clean_tuple(values: tuple[str, ...] | list[str]) -> tuple[str, ...]:
|
|
12
|
+
return tuple(str(value).strip() for value in values if str(value).strip())
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
@dataclass(frozen=True, slots=True, kw_only=True)
|
|
16
|
+
class RolePolicy(PolicyRuleBase):
|
|
17
|
+
kind: PolicyKind = field(default=PolicyKind.RBAC, init=False)
|
|
18
|
+
role: str
|
|
19
|
+
permissions: tuple[str, ...]
|
|
20
|
+
|
|
21
|
+
def __post_init__(self) -> None:
|
|
22
|
+
role = str(self.role).strip()
|
|
23
|
+
if not role:
|
|
24
|
+
raise ValueError("role policy requires role")
|
|
25
|
+
object.__setattr__(self, "role", role)
|
|
26
|
+
object.__setattr__(self, "policy_id", self.policy_id or role)
|
|
27
|
+
object.__setattr__(self, "permissions", _clean_tuple(self.permissions))
|
|
28
|
+
PolicyRuleBase.__post_init__(self)
|
|
29
|
+
|
|
30
|
+
|
|
31
|
+
@dataclass(frozen=True, slots=True, kw_only=True)
|
|
32
|
+
class AttributePolicy(PolicyRuleBase):
|
|
33
|
+
kind: PolicyKind = field(default=PolicyKind.ABAC, init=False)
|
|
34
|
+
required_attributes: Mapping[str, Any]
|
|
35
|
+
action: str = ""
|
|
36
|
+
name: str = ""
|
|
37
|
+
permission: str = ""
|
|
38
|
+
dynamic_conditions: tuple[DynamicCondition, ...] = ()
|
|
39
|
+
client_id: str | None = None
|
|
40
|
+
|
|
41
|
+
def __post_init__(self) -> None:
|
|
42
|
+
policy_id = self.policy_id or self.name
|
|
43
|
+
action = self.action or self.permission
|
|
44
|
+
name = self.name or policy_id
|
|
45
|
+
permission = self.permission or action
|
|
46
|
+
if not policy_id:
|
|
47
|
+
raise ValueError("attribute policy requires policy_id or name")
|
|
48
|
+
if not action:
|
|
49
|
+
raise ValueError("attribute policy requires action or permission")
|
|
50
|
+
object.__setattr__(self, "policy_id", str(policy_id).strip())
|
|
51
|
+
object.__setattr__(self, "action", str(action).strip())
|
|
52
|
+
object.__setattr__(self, "name", str(name).strip())
|
|
53
|
+
object.__setattr__(self, "permission", str(permission).strip())
|
|
54
|
+
object.__setattr__(self, "required_attributes", dict(self.required_attributes))
|
|
55
|
+
object.__setattr__(self, "dynamic_conditions", tuple(self.dynamic_conditions))
|
|
56
|
+
PolicyRuleBase.__post_init__(self)
|
|
57
|
+
|
|
58
|
+
|
|
59
|
+
@dataclass(frozen=True, slots=True, kw_only=True)
|
|
60
|
+
class PermissionPolicy(PolicyRuleBase):
|
|
61
|
+
kind: PolicyKind = field(default=PolicyKind.PBAC, init=False)
|
|
62
|
+
policy_id: str
|
|
63
|
+
permissions: tuple[str, ...]
|
|
64
|
+
|
|
65
|
+
def __post_init__(self) -> None:
|
|
66
|
+
if not str(self.policy_id).strip():
|
|
67
|
+
raise ValueError("permission policy requires policy_id")
|
|
68
|
+
object.__setattr__(self, "permissions", _clean_tuple(self.permissions))
|
|
69
|
+
PolicyRuleBase.__post_init__(self)
|
|
70
|
+
|
|
71
|
+
|
|
72
|
+
@dataclass(frozen=True, slots=True, kw_only=True)
|
|
73
|
+
class DelegationPolicy(PolicyRuleBase):
|
|
74
|
+
kind: PolicyKind = field(default=PolicyKind.DELEGATION, init=False)
|
|
75
|
+
delegate: str
|
|
76
|
+
delegator: str
|
|
77
|
+
tenant_ids: tuple[str, ...]
|
|
78
|
+
actions: tuple[str, ...]
|
|
79
|
+
|
|
80
|
+
def __post_init__(self) -> None:
|
|
81
|
+
delegate = str(self.delegate).strip()
|
|
82
|
+
delegator = str(self.delegator).strip()
|
|
83
|
+
if not delegate:
|
|
84
|
+
raise ValueError("delegation policy requires delegate")
|
|
85
|
+
if not delegator:
|
|
86
|
+
raise ValueError("delegation policy requires delegator")
|
|
87
|
+
object.__setattr__(self, "delegate", delegate)
|
|
88
|
+
object.__setattr__(self, "delegator", delegator)
|
|
89
|
+
object.__setattr__(self, "policy_id", self.policy_id or f"{delegator}->{delegate}")
|
|
90
|
+
object.__setattr__(self, "tenant_ids", _clean_tuple(self.tenant_ids))
|
|
91
|
+
object.__setattr__(self, "actions", _clean_tuple(self.actions))
|
|
92
|
+
PolicyRuleBase.__post_init__(self)
|
|
93
|
+
|
|
94
|
+
|
|
95
|
+
@dataclass(frozen=True, slots=True, kw_only=True)
|
|
96
|
+
class AdminPolicy(PolicyRuleBase):
|
|
97
|
+
kind: PolicyKind = field(default=PolicyKind.ADMIN, init=False)
|
|
98
|
+
subject: str
|
|
99
|
+
tenant_ids: tuple[str, ...]
|
|
100
|
+
actions: tuple[str, ...]
|
|
101
|
+
superuser: bool = False
|
|
102
|
+
|
|
103
|
+
def __post_init__(self) -> None:
|
|
104
|
+
subject = str(self.subject).strip()
|
|
105
|
+
if not subject:
|
|
106
|
+
raise ValueError("admin policy requires subject")
|
|
107
|
+
object.__setattr__(self, "subject", subject)
|
|
108
|
+
object.__setattr__(self, "policy_id", self.policy_id or subject)
|
|
109
|
+
object.__setattr__(self, "tenant_ids", _clean_tuple(self.tenant_ids))
|
|
110
|
+
object.__setattr__(self, "actions", _clean_tuple(self.actions))
|
|
111
|
+
PolicyRuleBase.__post_init__(self)
|
|
112
|
+
|
|
113
|
+
|
|
114
|
+
__all__ = [
|
|
115
|
+
"AdminPolicy",
|
|
116
|
+
"AttributePolicy",
|
|
117
|
+
"DelegationPolicy",
|
|
118
|
+
"PermissionPolicy",
|
|
119
|
+
"RolePolicy",
|
|
120
|
+
]
|
|
File without changes
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: tba-concrete-authorization-policy-rules
|
|
3
|
+
Version: 0.4.0.dev2
|
|
4
|
+
Summary: Concrete authorization policy rule variants.
|
|
5
|
+
License-Expression: Apache-2.0
|
|
6
|
+
Keywords: tigrbl,identity,auth,security
|
|
7
|
+
Requires-Python: >=3.10,<3.15
|
|
8
|
+
Classifier: Development Status :: 3 - Alpha
|
|
9
|
+
Classifier: Intended Audience :: Developers
|
|
10
|
+
Classifier: License :: OSI Approved :: Apache Software License
|
|
11
|
+
Classifier: Programming Language :: Python :: 3
|
|
12
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
13
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
14
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
15
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
16
|
+
Classifier: Programming Language :: Python :: 3.14
|
|
17
|
+
Classifier: Programming Language :: Python :: 3 :: Only
|
|
18
|
+
Classifier: Typing :: Typed
|
|
19
|
+
Classifier: Topic :: Security
|
|
20
|
+
Classifier: Topic :: Software Development :: Libraries :: Python Modules
|
|
21
|
+
Requires-Dist: tba-bases-authorization-policy (==0.4.0.dev2)
|
|
22
|
+
Requires-Dist: tba-contracts-identity (==0.4.0.dev2)
|
|
23
|
+
Project-URL: Homepage, https://github.com/tigrbl/tigrbl_auth
|
|
24
|
+
Project-URL: PyPI, https://pypi.org/project/tba-concrete-authorization-policy-rules/
|
|
25
|
+
Project-URL: Repository, https://github.com/tigrbl/tigrbl_auth
|
|
26
|
+
Project-URL: Source, https://github.com/tigrbl/tigrbl_auth/tree/master/pkgs/10-concrete/tba-concrete-authorization-policy-rules
|
|
27
|
+
Project-URL: SSOT, https://github.com/tigrbl/tigrbl_auth/blob/master/.ssot/registry.json
|
|
28
|
+
Description-Content-Type: text/markdown
|
|
29
|
+
|
|
30
|
+
# tba-concrete-authorization-policy-rules
|
|
31
|
+
|
|
32
|
+
Concrete authorization policy rule variants.
|
|
33
|
+
|
|
34
|
+
Import root: `tba_concrete_authorization_policy_rules`.
|
|
35
|
+
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
tba_concrete_authorization_policy_rules/__init__.py,sha256=jtPOIWJzPVgw2VuI8qO0kcYLgoqHTQsr9V5_qXxdlsM,4643
|
|
2
|
+
tba_concrete_authorization_policy_rules/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
3
|
+
tba_concrete_authorization_policy_rules-0.4.0.dev2.dist-info/METADATA,sha256=pnbNbQ1xCMyRUxUeGl89wnN-msmz6p6cOCJvP4Mi_Ws,1611
|
|
4
|
+
tba_concrete_authorization_policy_rules-0.4.0.dev2.dist-info/WHEEL,sha256=L-WvLdSBvJWHXv5zrQxDvNRnIgoBzLUpcbuiw19KCuQ,88
|
|
5
|
+
tba_concrete_authorization_policy_rules-0.4.0.dev2.dist-info/RECORD,,
|