Coverage for src/lexigram/auth/policies/store.py: 100%
15 statements
« prev ^ index » next coverage.py v7.15.4, created at 2026-08-25 12:26 +0800
« prev ^ index » next coverage.py v7.15.4, created at 2026-08-25 12:26 +0800
1"""Policy store protocols for ABAC policy persistence."""
3from __future__ import annotations
5from typing import TYPE_CHECKING, Protocol, runtime_checkable
7if TYPE_CHECKING:
8 from lexigram.auth.policies.types import Policy
11@runtime_checkable
12class PolicyStoreProtocol(Protocol):
13 """Protocol for policy storage backends.
15 Implement this protocol to provide custom policy storage
16 (database, file, remote service, etc.).
17 """
19 async def get_all(self) -> list[Policy]:
20 """Get all policies from the store.
22 Returns:
23 List of all policies.
24 """
25 ...
27 async def get_by_id(self, policy_id: str) -> Policy | None:
28 """Get a policy by its ID.
30 Args:
31 policy_id: The policy ID.
33 Returns:
34 The policy if found, None otherwise.
35 """
36 ...
38 async def get_by_name(self, name: str) -> Policy | None:
39 """Get a policy by its name.
41 Args:
42 name: The policy name.
44 Returns:
45 The policy if found, None otherwise.
46 """
47 ...
49 async def save(self, policy: Policy) -> None:
50 """Save a policy to the store.
52 Args:
53 policy: The policy to save.
54 """
55 ...
57 async def delete(self, policy_id: str) -> bool:
58 """Delete a policy from the store.
60 Args:
61 policy_id: The policy ID to delete.
63 Returns:
64 True if deleted, False if not found.
65 """
66 ...
68 async def exists(self, policy_id: str) -> bool:
69 """Check if a policy exists.
71 Args:
72 policy_id: The policy ID.
74 Returns:
75 True if exists, False otherwise.
76 """
77 ...
80@runtime_checkable
81class PolicyLoader(Protocol):
82 """Protocol for loading policies from various sources.
84 Used to load policies from files, databases, or remote services.
85 """
87 async def load(self) -> list[Policy]:
88 """Load policies from the source.
90 Returns:
91 List of loaded policies.
92 """
93 ...
95 async def reload(self) -> list[Policy]:
96 """Reload policies from the source.
98 Returns:
99 List of reloaded policies.
100 """
101 ...
104__all__ = [
105 "PolicyLoader",
106 "PolicyStoreProtocol",
107]