rbac2fast-core 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.
- rbac2fast_core-0.1.0/LICENSE +21 -0
- rbac2fast_core-0.1.0/MANIFEST.in +6 -0
- rbac2fast_core-0.1.0/PKG-INFO +111 -0
- rbac2fast_core-0.1.0/README.md +64 -0
- rbac2fast_core-0.1.0/pyproject.toml +54 -0
- rbac2fast_core-0.1.0/setup.cfg +4 -0
- rbac2fast_core-0.1.0/src/rbac2fast_core/__init__.py +11 -0
- rbac2fast_core-0.1.0/src/rbac2fast_core/__version__.py +1 -0
- rbac2fast_core-0.1.0/src/rbac2fast_core/protocols/__init__.py +27 -0
- rbac2fast_core-0.1.0/src/rbac2fast_core/protocols/models.py +42 -0
- rbac2fast_core-0.1.0/src/rbac2fast_core/protocols/services.py +31 -0
- rbac2fast_core-0.1.0/src/rbac2fast_core/schemas/__init__.py +53 -0
- rbac2fast_core-0.1.0/src/rbac2fast_core/schemas/permission_category_schema.py +11 -0
- rbac2fast_core-0.1.0/src/rbac2fast_core/schemas/permission_schema.py +42 -0
- rbac2fast_core-0.1.0/src/rbac2fast_core/schemas/role_schema.py +44 -0
- rbac2fast_core-0.1.0/src/rbac2fast_core/schemas/route_schema.py +12 -0
- rbac2fast_core-0.1.0/src/rbac2fast_core.egg-info/PKG-INFO +111 -0
- rbac2fast_core-0.1.0/src/rbac2fast_core.egg-info/SOURCES.txt +19 -0
- rbac2fast_core-0.1.0/src/rbac2fast_core.egg-info/dependency_links.txt +1 -0
- rbac2fast_core-0.1.0/src/rbac2fast_core.egg-info/requires.txt +1 -0
- rbac2fast_core-0.1.0/src/rbac2fast_core.egg-info/top_level.txt +1 -0
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Angel Daniel Sanchez Castillo
|
|
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.
|
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: rbac2fast-core
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: Core design package for RBAC: protocols and pydantic schemas
|
|
5
|
+
Author-email: Angel Daniel Sanchez Castillo <angeldaniel.sanchezcastillo@gmail.com>
|
|
6
|
+
License: MIT License
|
|
7
|
+
|
|
8
|
+
Copyright (c) 2026 Angel Daniel Sanchez Castillo
|
|
9
|
+
|
|
10
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
11
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
12
|
+
in the Software without restriction, including without limitation the rights
|
|
13
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
14
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
15
|
+
furnished to do so, subject to the following conditions:
|
|
16
|
+
|
|
17
|
+
The above copyright notice and this permission notice shall be included in all
|
|
18
|
+
copies or substantial portions of the Software.
|
|
19
|
+
|
|
20
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
21
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
22
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
23
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
24
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
25
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
26
|
+
SOFTWARE.
|
|
27
|
+
|
|
28
|
+
Project-URL: Homepage, https://github.com/AngelDanielSanchezCastillo/rbac2fast-core
|
|
29
|
+
Project-URL: Repository, https://github.com/AngelDanielSanchezCastillo/rbac2fast-core
|
|
30
|
+
Project-URL: Issues, https://github.com/AngelDanielSanchezCastillo/rbac2fast-core/issues
|
|
31
|
+
Keywords: permissions,rbac,authorization,access control
|
|
32
|
+
Classifier: Development Status :: 3 - Alpha
|
|
33
|
+
Classifier: Intended Audience :: Developers
|
|
34
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
35
|
+
Classifier: Programming Language :: Python :: 3
|
|
36
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
37
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
38
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
39
|
+
Classifier: Framework :: FastAPI
|
|
40
|
+
Classifier: Topic :: Security
|
|
41
|
+
Classifier: Topic :: Software Development :: Libraries :: Python Modules
|
|
42
|
+
Requires-Python: >=3.10
|
|
43
|
+
Description-Content-Type: text/markdown
|
|
44
|
+
License-File: LICENSE
|
|
45
|
+
Requires-Dist: pydantic>=2.0
|
|
46
|
+
Dynamic: license-file
|
|
47
|
+
|
|
48
|
+
# rbac2fast-core
|
|
49
|
+
|
|
50
|
+
🚀 Core abstract package for Role-Based Access Control (RBAC) in Python/FastAPI. Contains Protocols and Pydantic schemas without database logic.
|
|
51
|
+
|
|
52
|
+
> [!WARNING]
|
|
53
|
+
> **Internal Use Notice**
|
|
54
|
+
>
|
|
55
|
+
> This package is designed and maintained by the **Solautyc Team** for internal use. While it is publicly available, it may not work as expected in all environments or use cases outside of our specific infrastructure. We do not provide support or guarantees for external usage, and we are not responsible for any issues that may arise from using this package in other contexts.
|
|
56
|
+
>
|
|
57
|
+
> Use at your own risk. Contributions and feedback are welcome, but compatibility with external environments is not guaranteed.
|
|
58
|
+
|
|
59
|
+
## Features
|
|
60
|
+
|
|
61
|
+
- 🧩 **Abstract Interfaces**: Defines standard `Protocols` for RBAC models and services.
|
|
62
|
+
- 📦 **Pydantic Schemas**: Pre-defined base models for validation and serialization of Roles, Permissions, Routes, and Assignments.
|
|
63
|
+
- 🪶 **Lightweight**: Zero database dependencies; relies solely on standard Python abstractions and `pydantic`.
|
|
64
|
+
- 🔌 **Pluggable Architecture**: Allows multiple concrete implementations (e.g., standard global RBAC or multi-tenant RBAC) to share a standardized API contract.
|
|
65
|
+
|
|
66
|
+
## Installation
|
|
67
|
+
|
|
68
|
+
```bash
|
|
69
|
+
pip install rbac2fast-core
|
|
70
|
+
```
|
|
71
|
+
|
|
72
|
+
## Structure
|
|
73
|
+
|
|
74
|
+
This package exposes abstract definitions that concrete implementations (like `permissions2fast-fastapi`) will fulfill.
|
|
75
|
+
|
|
76
|
+
### Protocols (`rbac2fast_core.protocols`)
|
|
77
|
+
|
|
78
|
+
Defines minimal structural requirements that underlying models must fulfill:
|
|
79
|
+
- `RoleProtocol`, `PermissionProtocol`, `RouteProtocol`
|
|
80
|
+
...
|
|
81
|
+
|
|
82
|
+
### Schemas (`rbac2fast_core.schemas`)
|
|
83
|
+
|
|
84
|
+
Provides validation schemas:
|
|
85
|
+
- `RoleBase`, `RoleCreate`, `RoleRead`
|
|
86
|
+
- `PermissionBase`, `PermissionCreate`
|
|
87
|
+
...
|
|
88
|
+
|
|
89
|
+
## Usage
|
|
90
|
+
|
|
91
|
+
This package is not meant to be used standalone to handle permissions, but rather to be imported as a dependency by actual implementation packages or application layers that need to adhere to the standard RBAC design.
|
|
92
|
+
|
|
93
|
+
Example of implementing a protocol in your ORM model:
|
|
94
|
+
|
|
95
|
+
```python
|
|
96
|
+
from sqlmodel import SQLModel, Field
|
|
97
|
+
from rbac2fast_core.protocols.models import RoleProtocol
|
|
98
|
+
|
|
99
|
+
class Role(SQLModel, table=True):
|
|
100
|
+
# This class structurally fulfills RoleProtocol
|
|
101
|
+
id: int | None = Field(default=None, primary_key=True)
|
|
102
|
+
name: str = Field(unique=True, index=True)
|
|
103
|
+
description: str | None = None
|
|
104
|
+
is_active: bool = True
|
|
105
|
+
```
|
|
106
|
+
|
|
107
|
+
## License
|
|
108
|
+
|
|
109
|
+
This project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details.
|
|
110
|
+
|
|
111
|
+
Copyright (c) 2026 Angel Daniel Sanchez Castillo
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
# rbac2fast-core
|
|
2
|
+
|
|
3
|
+
🚀 Core abstract package for Role-Based Access Control (RBAC) in Python/FastAPI. Contains Protocols and Pydantic schemas without database logic.
|
|
4
|
+
|
|
5
|
+
> [!WARNING]
|
|
6
|
+
> **Internal Use Notice**
|
|
7
|
+
>
|
|
8
|
+
> This package is designed and maintained by the **Solautyc Team** for internal use. While it is publicly available, it may not work as expected in all environments or use cases outside of our specific infrastructure. We do not provide support or guarantees for external usage, and we are not responsible for any issues that may arise from using this package in other contexts.
|
|
9
|
+
>
|
|
10
|
+
> Use at your own risk. Contributions and feedback are welcome, but compatibility with external environments is not guaranteed.
|
|
11
|
+
|
|
12
|
+
## Features
|
|
13
|
+
|
|
14
|
+
- 🧩 **Abstract Interfaces**: Defines standard `Protocols` for RBAC models and services.
|
|
15
|
+
- 📦 **Pydantic Schemas**: Pre-defined base models for validation and serialization of Roles, Permissions, Routes, and Assignments.
|
|
16
|
+
- 🪶 **Lightweight**: Zero database dependencies; relies solely on standard Python abstractions and `pydantic`.
|
|
17
|
+
- 🔌 **Pluggable Architecture**: Allows multiple concrete implementations (e.g., standard global RBAC or multi-tenant RBAC) to share a standardized API contract.
|
|
18
|
+
|
|
19
|
+
## Installation
|
|
20
|
+
|
|
21
|
+
```bash
|
|
22
|
+
pip install rbac2fast-core
|
|
23
|
+
```
|
|
24
|
+
|
|
25
|
+
## Structure
|
|
26
|
+
|
|
27
|
+
This package exposes abstract definitions that concrete implementations (like `permissions2fast-fastapi`) will fulfill.
|
|
28
|
+
|
|
29
|
+
### Protocols (`rbac2fast_core.protocols`)
|
|
30
|
+
|
|
31
|
+
Defines minimal structural requirements that underlying models must fulfill:
|
|
32
|
+
- `RoleProtocol`, `PermissionProtocol`, `RouteProtocol`
|
|
33
|
+
...
|
|
34
|
+
|
|
35
|
+
### Schemas (`rbac2fast_core.schemas`)
|
|
36
|
+
|
|
37
|
+
Provides validation schemas:
|
|
38
|
+
- `RoleBase`, `RoleCreate`, `RoleRead`
|
|
39
|
+
- `PermissionBase`, `PermissionCreate`
|
|
40
|
+
...
|
|
41
|
+
|
|
42
|
+
## Usage
|
|
43
|
+
|
|
44
|
+
This package is not meant to be used standalone to handle permissions, but rather to be imported as a dependency by actual implementation packages or application layers that need to adhere to the standard RBAC design.
|
|
45
|
+
|
|
46
|
+
Example of implementing a protocol in your ORM model:
|
|
47
|
+
|
|
48
|
+
```python
|
|
49
|
+
from sqlmodel import SQLModel, Field
|
|
50
|
+
from rbac2fast_core.protocols.models import RoleProtocol
|
|
51
|
+
|
|
52
|
+
class Role(SQLModel, table=True):
|
|
53
|
+
# This class structurally fulfills RoleProtocol
|
|
54
|
+
id: int | None = Field(default=None, primary_key=True)
|
|
55
|
+
name: str = Field(unique=True, index=True)
|
|
56
|
+
description: str | None = None
|
|
57
|
+
is_active: bool = True
|
|
58
|
+
```
|
|
59
|
+
|
|
60
|
+
## License
|
|
61
|
+
|
|
62
|
+
This project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details.
|
|
63
|
+
|
|
64
|
+
Copyright (c) 2026 Angel Daniel Sanchez Castillo
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
[build-system]
|
|
2
|
+
requires = ["setuptools>=61.0", "wheel"]
|
|
3
|
+
build-backend = "setuptools.build_meta"
|
|
4
|
+
|
|
5
|
+
[project]
|
|
6
|
+
name = "rbac2fast-core"
|
|
7
|
+
version = "0.1.0"
|
|
8
|
+
description = "Core design package for RBAC: protocols and pydantic schemas"
|
|
9
|
+
readme = "README.md"
|
|
10
|
+
requires-python = ">=3.10"
|
|
11
|
+
license = {file = "LICENSE"}
|
|
12
|
+
authors = [
|
|
13
|
+
{name = "Angel Daniel Sanchez Castillo", email = "angeldaniel.sanchezcastillo@gmail.com"}
|
|
14
|
+
]
|
|
15
|
+
keywords = ["permissions", "rbac", "authorization", "access control"]
|
|
16
|
+
classifiers = [
|
|
17
|
+
"Development Status :: 3 - Alpha",
|
|
18
|
+
"Intended Audience :: Developers",
|
|
19
|
+
"License :: OSI Approved :: MIT License",
|
|
20
|
+
"Programming Language :: Python :: 3",
|
|
21
|
+
"Programming Language :: Python :: 3.10",
|
|
22
|
+
"Programming Language :: Python :: 3.11",
|
|
23
|
+
"Programming Language :: Python :: 3.12",
|
|
24
|
+
"Framework :: FastAPI",
|
|
25
|
+
"Topic :: Security",
|
|
26
|
+
"Topic :: Software Development :: Libraries :: Python Modules",
|
|
27
|
+
]
|
|
28
|
+
|
|
29
|
+
dependencies = [
|
|
30
|
+
"pydantic>=2.0",
|
|
31
|
+
]
|
|
32
|
+
|
|
33
|
+
[dependency-groups]
|
|
34
|
+
dev = [
|
|
35
|
+
"black",
|
|
36
|
+
"ruff",
|
|
37
|
+
"build",
|
|
38
|
+
"twine",
|
|
39
|
+
]
|
|
40
|
+
test = [
|
|
41
|
+
"pytest>=7.0.0",
|
|
42
|
+
]
|
|
43
|
+
|
|
44
|
+
[project.urls]
|
|
45
|
+
Homepage = "https://github.com/AngelDanielSanchezCastillo/rbac2fast-core"
|
|
46
|
+
Repository = "https://github.com/AngelDanielSanchezCastillo/rbac2fast-core"
|
|
47
|
+
Issues = "https://github.com/AngelDanielSanchezCastillo/rbac2fast-core/issues"
|
|
48
|
+
|
|
49
|
+
[tool.setuptools]
|
|
50
|
+
package-dir = {"" = "src"}
|
|
51
|
+
|
|
52
|
+
[tool.setuptools.packages.find]
|
|
53
|
+
where = ["src"]
|
|
54
|
+
include = ["rbac2fast_core*"]
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
__version__ = "0.1.0"
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
from .models import (
|
|
2
|
+
RoleProtocol,
|
|
3
|
+
PermissionProtocol,
|
|
4
|
+
PermissionCategoryProtocol,
|
|
5
|
+
RouteProtocol,
|
|
6
|
+
UserRoleProtocol,
|
|
7
|
+
PermissionAssignmentProtocol,
|
|
8
|
+
PermissionRouteProtocol,
|
|
9
|
+
)
|
|
10
|
+
from .services import (
|
|
11
|
+
RoleServiceProtocol,
|
|
12
|
+
PermissionServiceProtocol,
|
|
13
|
+
AccessServiceProtocol,
|
|
14
|
+
)
|
|
15
|
+
|
|
16
|
+
__all__ = [
|
|
17
|
+
"RoleProtocol",
|
|
18
|
+
"PermissionProtocol",
|
|
19
|
+
"PermissionCategoryProtocol",
|
|
20
|
+
"RouteProtocol",
|
|
21
|
+
"UserRoleProtocol",
|
|
22
|
+
"PermissionAssignmentProtocol",
|
|
23
|
+
"PermissionRouteProtocol",
|
|
24
|
+
"RoleServiceProtocol",
|
|
25
|
+
"PermissionServiceProtocol",
|
|
26
|
+
"AccessServiceProtocol",
|
|
27
|
+
]
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
from typing import Protocol, List, Optional
|
|
2
|
+
from datetime import datetime
|
|
3
|
+
|
|
4
|
+
class RoleProtocol(Protocol):
|
|
5
|
+
id: int
|
|
6
|
+
name: str
|
|
7
|
+
description: Optional[str]
|
|
8
|
+
is_active: bool
|
|
9
|
+
created_at: Optional[datetime]
|
|
10
|
+
updated_at: Optional[datetime]
|
|
11
|
+
|
|
12
|
+
class PermissionCategoryProtocol(Protocol):
|
|
13
|
+
id: int
|
|
14
|
+
name: str
|
|
15
|
+
|
|
16
|
+
class PermissionProtocol(Protocol):
|
|
17
|
+
id: int
|
|
18
|
+
name: str
|
|
19
|
+
permission_category_id: int
|
|
20
|
+
created_at: Optional[datetime]
|
|
21
|
+
updated_at: Optional[datetime]
|
|
22
|
+
|
|
23
|
+
class RouteProtocol(Protocol):
|
|
24
|
+
id: int
|
|
25
|
+
name: str
|
|
26
|
+
is_active: bool
|
|
27
|
+
|
|
28
|
+
class UserRoleProtocol(Protocol):
|
|
29
|
+
id: int
|
|
30
|
+
user_id: int
|
|
31
|
+
role_id: int
|
|
32
|
+
|
|
33
|
+
class PermissionAssignmentProtocol(Protocol):
|
|
34
|
+
id: int
|
|
35
|
+
permission_id: int
|
|
36
|
+
entity_type: str
|
|
37
|
+
entity_id: int
|
|
38
|
+
|
|
39
|
+
class PermissionRouteProtocol(Protocol):
|
|
40
|
+
id: int
|
|
41
|
+
permission_id: int
|
|
42
|
+
route_id: int
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
from typing import Protocol, Any, List, Optional
|
|
2
|
+
from .models import RoleProtocol, PermissionProtocol, PermissionCategoryProtocol, RouteProtocol, UserRoleProtocol, PermissionAssignmentProtocol, PermissionRouteProtocol
|
|
3
|
+
|
|
4
|
+
class RoleServiceProtocol(Protocol):
|
|
5
|
+
async def create_role(self, role_data: Any, session: Any) -> RoleProtocol: ...
|
|
6
|
+
async def get_role(self, role_id: int, session: Any) -> Optional[RoleProtocol]: ...
|
|
7
|
+
async def list_roles(self, session: Any, skip: int = 0, limit: int = 100) -> List[RoleProtocol]: ...
|
|
8
|
+
async def update_role(self, role_id: int, role_data: Any, session: Any) -> Optional[RoleProtocol]: ...
|
|
9
|
+
async def delete_role(self, role_id: int, session: Any) -> bool: ...
|
|
10
|
+
async def add_role_permission(self, role_id: int, permission_id: int, session: Any) -> PermissionAssignmentProtocol: ...
|
|
11
|
+
async def list_role_permissions(self, role_id: int, session: Any) -> List[PermissionProtocol]: ...
|
|
12
|
+
async def delete_role_permission(self, role_id: int, permission_id: int, session: Any) -> bool: ...
|
|
13
|
+
async def assign_user_role(self, user_id: int, role_id: int, session: Any) -> UserRoleProtocol: ...
|
|
14
|
+
async def list_user_roles(self, user_id: int, session: Any) -> List[RoleProtocol]: ...
|
|
15
|
+
async def remove_user_role(self, user_id: int, role_id: int, session: Any) -> bool: ...
|
|
16
|
+
|
|
17
|
+
class PermissionServiceProtocol(Protocol):
|
|
18
|
+
async def create_category(self, category_data: Any, session: Any) -> PermissionCategoryProtocol: ...
|
|
19
|
+
async def list_categories(self, session: Any, skip: int = 0, limit: int = 100) -> List[PermissionCategoryProtocol]: ...
|
|
20
|
+
async def create_permission(self, permission_data: Any, session: Any) -> PermissionProtocol: ...
|
|
21
|
+
async def get_permission(self, permission_id: int, session: Any) -> Optional[PermissionProtocol]: ...
|
|
22
|
+
async def list_permissions(self, session: Any, skip: int = 0, limit: int = 100) -> List[PermissionProtocol]: ...
|
|
23
|
+
async def update_permission(self, permission_id: int, permission_data: Any, session: Any) -> Optional[PermissionProtocol]: ...
|
|
24
|
+
async def delete_permission(self, permission_id: int, session: Any) -> bool: ...
|
|
25
|
+
async def add_permission_route(self, permission_id: int, route_id: int, session: Any) -> PermissionRouteProtocol: ...
|
|
26
|
+
async def assign_user_permission(self, user_id: int, permission_id: int, session: Any) -> PermissionAssignmentProtocol: ...
|
|
27
|
+
async def list_user_permissions(self, user_id: int, session: Any) -> List[PermissionProtocol]: ...
|
|
28
|
+
async def remove_user_permission(self, user_id: int, permission_id: int, session: Any) -> bool: ...
|
|
29
|
+
|
|
30
|
+
class AccessServiceProtocol(Protocol):
|
|
31
|
+
async def check_user_access(self, user_id: int, route_path: str, method: str, session: Any) -> bool: ...
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
"""Schemas for rbac2fast-core"""
|
|
2
|
+
|
|
3
|
+
from .role_schema import (
|
|
4
|
+
RoleBase,
|
|
5
|
+
RoleCreate,
|
|
6
|
+
RoleUpdate,
|
|
7
|
+
RoleRead,
|
|
8
|
+
RolePermissionCreate,
|
|
9
|
+
UserRoleCreate,
|
|
10
|
+
UserRoleRead,
|
|
11
|
+
)
|
|
12
|
+
from .permission_schema import (
|
|
13
|
+
PermissionBase,
|
|
14
|
+
PermissionCreate,
|
|
15
|
+
PermissionRead,
|
|
16
|
+
PermissionUpdate,
|
|
17
|
+
PermissionRouteCreate,
|
|
18
|
+
UserPermissionCreate,
|
|
19
|
+
UserPermissionRead,
|
|
20
|
+
)
|
|
21
|
+
from .permission_category_schema import (
|
|
22
|
+
PermissionCategoryBase,
|
|
23
|
+
PermissionCategoryCreate,
|
|
24
|
+
PermissionCategoryRead,
|
|
25
|
+
)
|
|
26
|
+
from .route_schema import (
|
|
27
|
+
RouteBase,
|
|
28
|
+
RouteCreate,
|
|
29
|
+
RouteRead,
|
|
30
|
+
)
|
|
31
|
+
|
|
32
|
+
__all__ = [
|
|
33
|
+
"RoleBase",
|
|
34
|
+
"RoleCreate",
|
|
35
|
+
"RoleUpdate",
|
|
36
|
+
"RoleRead",
|
|
37
|
+
"RolePermissionCreate",
|
|
38
|
+
"UserRoleCreate",
|
|
39
|
+
"UserRoleRead",
|
|
40
|
+
"PermissionBase",
|
|
41
|
+
"PermissionCreate",
|
|
42
|
+
"PermissionRead",
|
|
43
|
+
"PermissionUpdate",
|
|
44
|
+
"PermissionRouteCreate",
|
|
45
|
+
"UserPermissionCreate",
|
|
46
|
+
"UserPermissionRead",
|
|
47
|
+
"PermissionCategoryBase",
|
|
48
|
+
"PermissionCategoryCreate",
|
|
49
|
+
"PermissionCategoryRead",
|
|
50
|
+
"RouteBase",
|
|
51
|
+
"RouteCreate",
|
|
52
|
+
"RouteRead",
|
|
53
|
+
]
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
from pydantic import BaseModel, ConfigDict
|
|
2
|
+
|
|
3
|
+
class PermissionCategoryBase(BaseModel):
|
|
4
|
+
model_config = ConfigDict(from_attributes=True)
|
|
5
|
+
name: str
|
|
6
|
+
|
|
7
|
+
class PermissionCategoryCreate(PermissionCategoryBase):
|
|
8
|
+
pass
|
|
9
|
+
|
|
10
|
+
class PermissionCategoryRead(PermissionCategoryBase):
|
|
11
|
+
id: int
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
from datetime import datetime
|
|
2
|
+
from pydantic import BaseModel, ConfigDict
|
|
3
|
+
|
|
4
|
+
|
|
5
|
+
class PermissionBase(BaseModel):
|
|
6
|
+
model_config = ConfigDict(from_attributes=True)
|
|
7
|
+
name: str
|
|
8
|
+
permission_category_id: int
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
class PermissionCreate(PermissionBase):
|
|
12
|
+
pass
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
class PermissionUpdate(BaseModel):
|
|
16
|
+
name: str | None = None
|
|
17
|
+
permission_category_id: int | None = None
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
class PermissionRead(PermissionBase):
|
|
21
|
+
id: int
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
# Assignment Schemas
|
|
25
|
+
|
|
26
|
+
class PermissionRouteCreate(BaseModel):
|
|
27
|
+
model_config = ConfigDict(from_attributes=True)
|
|
28
|
+
permission_id: int
|
|
29
|
+
route_id: int
|
|
30
|
+
|
|
31
|
+
|
|
32
|
+
class UserPermissionCreate(BaseModel):
|
|
33
|
+
model_config = ConfigDict(from_attributes=True)
|
|
34
|
+
user_id: int
|
|
35
|
+
permission_id: int
|
|
36
|
+
|
|
37
|
+
|
|
38
|
+
class UserPermissionRead(BaseModel):
|
|
39
|
+
model_config = ConfigDict(from_attributes=True)
|
|
40
|
+
permission_id: int
|
|
41
|
+
entity_type: str
|
|
42
|
+
entity_id: int
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
from datetime import datetime
|
|
2
|
+
from pydantic import BaseModel, ConfigDict
|
|
3
|
+
|
|
4
|
+
|
|
5
|
+
class RoleBase(BaseModel):
|
|
6
|
+
model_config = ConfigDict(from_attributes=True)
|
|
7
|
+
name: str
|
|
8
|
+
description: str | None = None
|
|
9
|
+
is_active: bool = True
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
class RoleCreate(RoleBase):
|
|
13
|
+
pass
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
class RoleUpdate(BaseModel):
|
|
17
|
+
name: str | None = None
|
|
18
|
+
description: str | None = None
|
|
19
|
+
is_active: bool | None = None
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
class RoleRead(RoleBase):
|
|
23
|
+
id: int
|
|
24
|
+
created_at: datetime | None = None
|
|
25
|
+
updated_at: datetime | None = None
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
# Assignment Schemas
|
|
29
|
+
|
|
30
|
+
class RolePermissionCreate(BaseModel):
|
|
31
|
+
model_config = ConfigDict(from_attributes=True)
|
|
32
|
+
permission_id: int
|
|
33
|
+
|
|
34
|
+
|
|
35
|
+
class UserRoleCreate(BaseModel):
|
|
36
|
+
model_config = ConfigDict(from_attributes=True)
|
|
37
|
+
user_id: int
|
|
38
|
+
role_id: int
|
|
39
|
+
|
|
40
|
+
|
|
41
|
+
class UserRoleRead(BaseModel):
|
|
42
|
+
model_config = ConfigDict(from_attributes=True)
|
|
43
|
+
user_id: int
|
|
44
|
+
role_id: int
|
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: rbac2fast-core
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: Core design package for RBAC: protocols and pydantic schemas
|
|
5
|
+
Author-email: Angel Daniel Sanchez Castillo <angeldaniel.sanchezcastillo@gmail.com>
|
|
6
|
+
License: MIT License
|
|
7
|
+
|
|
8
|
+
Copyright (c) 2026 Angel Daniel Sanchez Castillo
|
|
9
|
+
|
|
10
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
11
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
12
|
+
in the Software without restriction, including without limitation the rights
|
|
13
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
14
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
15
|
+
furnished to do so, subject to the following conditions:
|
|
16
|
+
|
|
17
|
+
The above copyright notice and this permission notice shall be included in all
|
|
18
|
+
copies or substantial portions of the Software.
|
|
19
|
+
|
|
20
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
21
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
22
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
23
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
24
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
25
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
26
|
+
SOFTWARE.
|
|
27
|
+
|
|
28
|
+
Project-URL: Homepage, https://github.com/AngelDanielSanchezCastillo/rbac2fast-core
|
|
29
|
+
Project-URL: Repository, https://github.com/AngelDanielSanchezCastillo/rbac2fast-core
|
|
30
|
+
Project-URL: Issues, https://github.com/AngelDanielSanchezCastillo/rbac2fast-core/issues
|
|
31
|
+
Keywords: permissions,rbac,authorization,access control
|
|
32
|
+
Classifier: Development Status :: 3 - Alpha
|
|
33
|
+
Classifier: Intended Audience :: Developers
|
|
34
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
35
|
+
Classifier: Programming Language :: Python :: 3
|
|
36
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
37
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
38
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
39
|
+
Classifier: Framework :: FastAPI
|
|
40
|
+
Classifier: Topic :: Security
|
|
41
|
+
Classifier: Topic :: Software Development :: Libraries :: Python Modules
|
|
42
|
+
Requires-Python: >=3.10
|
|
43
|
+
Description-Content-Type: text/markdown
|
|
44
|
+
License-File: LICENSE
|
|
45
|
+
Requires-Dist: pydantic>=2.0
|
|
46
|
+
Dynamic: license-file
|
|
47
|
+
|
|
48
|
+
# rbac2fast-core
|
|
49
|
+
|
|
50
|
+
🚀 Core abstract package for Role-Based Access Control (RBAC) in Python/FastAPI. Contains Protocols and Pydantic schemas without database logic.
|
|
51
|
+
|
|
52
|
+
> [!WARNING]
|
|
53
|
+
> **Internal Use Notice**
|
|
54
|
+
>
|
|
55
|
+
> This package is designed and maintained by the **Solautyc Team** for internal use. While it is publicly available, it may not work as expected in all environments or use cases outside of our specific infrastructure. We do not provide support or guarantees for external usage, and we are not responsible for any issues that may arise from using this package in other contexts.
|
|
56
|
+
>
|
|
57
|
+
> Use at your own risk. Contributions and feedback are welcome, but compatibility with external environments is not guaranteed.
|
|
58
|
+
|
|
59
|
+
## Features
|
|
60
|
+
|
|
61
|
+
- 🧩 **Abstract Interfaces**: Defines standard `Protocols` for RBAC models and services.
|
|
62
|
+
- 📦 **Pydantic Schemas**: Pre-defined base models for validation and serialization of Roles, Permissions, Routes, and Assignments.
|
|
63
|
+
- 🪶 **Lightweight**: Zero database dependencies; relies solely on standard Python abstractions and `pydantic`.
|
|
64
|
+
- 🔌 **Pluggable Architecture**: Allows multiple concrete implementations (e.g., standard global RBAC or multi-tenant RBAC) to share a standardized API contract.
|
|
65
|
+
|
|
66
|
+
## Installation
|
|
67
|
+
|
|
68
|
+
```bash
|
|
69
|
+
pip install rbac2fast-core
|
|
70
|
+
```
|
|
71
|
+
|
|
72
|
+
## Structure
|
|
73
|
+
|
|
74
|
+
This package exposes abstract definitions that concrete implementations (like `permissions2fast-fastapi`) will fulfill.
|
|
75
|
+
|
|
76
|
+
### Protocols (`rbac2fast_core.protocols`)
|
|
77
|
+
|
|
78
|
+
Defines minimal structural requirements that underlying models must fulfill:
|
|
79
|
+
- `RoleProtocol`, `PermissionProtocol`, `RouteProtocol`
|
|
80
|
+
...
|
|
81
|
+
|
|
82
|
+
### Schemas (`rbac2fast_core.schemas`)
|
|
83
|
+
|
|
84
|
+
Provides validation schemas:
|
|
85
|
+
- `RoleBase`, `RoleCreate`, `RoleRead`
|
|
86
|
+
- `PermissionBase`, `PermissionCreate`
|
|
87
|
+
...
|
|
88
|
+
|
|
89
|
+
## Usage
|
|
90
|
+
|
|
91
|
+
This package is not meant to be used standalone to handle permissions, but rather to be imported as a dependency by actual implementation packages or application layers that need to adhere to the standard RBAC design.
|
|
92
|
+
|
|
93
|
+
Example of implementing a protocol in your ORM model:
|
|
94
|
+
|
|
95
|
+
```python
|
|
96
|
+
from sqlmodel import SQLModel, Field
|
|
97
|
+
from rbac2fast_core.protocols.models import RoleProtocol
|
|
98
|
+
|
|
99
|
+
class Role(SQLModel, table=True):
|
|
100
|
+
# This class structurally fulfills RoleProtocol
|
|
101
|
+
id: int | None = Field(default=None, primary_key=True)
|
|
102
|
+
name: str = Field(unique=True, index=True)
|
|
103
|
+
description: str | None = None
|
|
104
|
+
is_active: bool = True
|
|
105
|
+
```
|
|
106
|
+
|
|
107
|
+
## License
|
|
108
|
+
|
|
109
|
+
This project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details.
|
|
110
|
+
|
|
111
|
+
Copyright (c) 2026 Angel Daniel Sanchez Castillo
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
LICENSE
|
|
2
|
+
MANIFEST.in
|
|
3
|
+
README.md
|
|
4
|
+
pyproject.toml
|
|
5
|
+
src/rbac2fast_core/__init__.py
|
|
6
|
+
src/rbac2fast_core/__version__.py
|
|
7
|
+
src/rbac2fast_core.egg-info/PKG-INFO
|
|
8
|
+
src/rbac2fast_core.egg-info/SOURCES.txt
|
|
9
|
+
src/rbac2fast_core.egg-info/dependency_links.txt
|
|
10
|
+
src/rbac2fast_core.egg-info/requires.txt
|
|
11
|
+
src/rbac2fast_core.egg-info/top_level.txt
|
|
12
|
+
src/rbac2fast_core/protocols/__init__.py
|
|
13
|
+
src/rbac2fast_core/protocols/models.py
|
|
14
|
+
src/rbac2fast_core/protocols/services.py
|
|
15
|
+
src/rbac2fast_core/schemas/__init__.py
|
|
16
|
+
src/rbac2fast_core/schemas/permission_category_schema.py
|
|
17
|
+
src/rbac2fast_core/schemas/permission_schema.py
|
|
18
|
+
src/rbac2fast_core/schemas/role_schema.py
|
|
19
|
+
src/rbac2fast_core/schemas/route_schema.py
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
pydantic>=2.0
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
rbac2fast_core
|