Coverage for netrun_rbac\__init__.py: 100%

1"""

2 Netrun RBAC - Multi-tenant Role-Based Access Control with PostgreSQL RLS

3

4 Extracted from Intirkast SaaS platform (85% code reuse, 12h time savings)

5

6 Features:

7- Role hierarchy enforcement (owner > admin > member > viewer)

8- FastAPI dependency injection for route protection

9- PostgreSQL Row-Level Security (RLS) policy generators

10- Tenant context management

11- Resource ownership validation

12- Project-agnostic with placeholder configuration

13

14 Usage:

15 from netrun_rbac import require_role, require_roles, TenantContext, RLSPolicyGenerator

16

17 @app.get("/api/admin/dashboard")

18 async def admin_dashboard(user: dict = Depends(require_role("admin"))):

19 return {"message": "Admin access granted"}

20"""

21

22 from .dependencies import (

23 require_role,

24 require_roles,

25 require_owner,

26 require_admin,

27 require_member,

28 check_resource_ownership,

29)

30 from .models import Role, Permission, RoleHierarchy

31 from .policies import RLSPolicyGenerator

32 from .tenant import TenantContext, set_tenant_context, clear_tenant_context

33 from .exceptions import (

34 RBACException,

35 InsufficientPermissionsError,

36 TenantIsolationError,

37 ResourceOwnershipError,

38)

39

40 __version__ = "1.0.0"

41 __all__ = [

42 # Dependencies

43 "require_role",

44 "require_roles",

45 "require_owner",

46 "require_admin",

47 "require_member",

48 "check_resource_ownership",

49 # Models

50 "Role",

51 "Permission",

52 "RoleHierarchy",

53 # Policies

54 "RLSPolicyGenerator",

55 # Tenant Context

56 "TenantContext",

57 "set_tenant_context",

58 "clear_tenant_context",

59 # Exceptions

60 "RBACException",

61 "InsufficientPermissionsError",

62 "TenantIsolationError",

63 "ResourceOwnershipError",

64]