tba-concrete-authorization-policy-rules 0.4.0.dev2__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.
@@ -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
2
+
3
+ Concrete authorization policy rule variants.
4
+
5
+ Import root: `tba_concrete_authorization_policy_rules`.
@@ -0,0 +1,41 @@
1
+ [project]
2
+ name = "tba-concrete-authorization-policy-rules"
3
+ version = "0.4.0.dev2"
4
+ description = "Concrete authorization policy rule variants."
5
+ readme = "README.md"
6
+ requires-python = ">=3.10,<3.15"
7
+ license = "Apache-2.0"
8
+ keywords = ["tigrbl", "identity", "auth", "security"]
9
+ classifiers = [
10
+ "Development Status :: 3 - Alpha",
11
+ "Intended Audience :: Developers",
12
+ "License :: OSI Approved :: Apache Software License",
13
+ "Programming Language :: Python :: 3",
14
+ "Programming Language :: Python :: 3.10",
15
+ "Programming Language :: Python :: 3.11",
16
+ "Programming Language :: Python :: 3.12",
17
+ "Programming Language :: Python :: 3.13",
18
+ "Programming Language :: Python :: 3.14",
19
+ "Programming Language :: Python :: 3 :: Only",
20
+ "Typing :: Typed",
21
+ "Topic :: Security",
22
+ "Topic :: Software Development :: Libraries :: Python Modules",
23
+ ]
24
+ dependencies = [
25
+ "tba-bases-authorization-policy==0.4.0.dev2",
26
+ "tba-contracts-identity==0.4.0.dev2",
27
+ ]
28
+
29
+ [project.urls]
30
+ Homepage = "https://github.com/tigrbl/tigrbl_auth"
31
+ Repository = "https://github.com/tigrbl/tigrbl_auth"
32
+ Source = "https://github.com/tigrbl/tigrbl_auth/tree/master/pkgs/10-concrete/tba-concrete-authorization-policy-rules"
33
+ SSOT = "https://github.com/tigrbl/tigrbl_auth/blob/master/.ssot/registry.json"
34
+ PyPI = "https://pypi.org/project/tba-concrete-authorization-policy-rules/"
35
+
36
+ [build-system]
37
+ requires = ["poetry-core>=1.0.0"]
38
+ build-backend = "poetry.core.masonry.api"
39
+
40
+ [tool.poetry]
41
+ packages = [{ include = "tba_concrete_authorization_policy_rules", from = "src" }]
@@ -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
+ ]