Skip to content

Commit adbe112

Browse files
committed
add adapter loading option
1 parent c8c47c9 commit adbe112

2 files changed

Lines changed: 6 additions & 1 deletion

File tree

casbin_adapter/enforcer.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55
from casbin import Enforcer
66

77
from .adapter import Adapter
8+
from .utils import import_class
9+
810

911

1012
class ProxyEnforcer(Enforcer):
@@ -19,7 +21,10 @@ def _load(self):
1921
self._initialized = True
2022
model = getattr(settings, 'CASBIN_MODEL')
2123
enable_log = getattr(settings, 'CASBIN_LOG_ENABLED', False)
22-
adapter = Adapter()
24+
adapter_loc = getattr(settings, 'CASBIN_ADAPTER', 'casbin_adapter.adapter.Adapter')
25+
adapter_args = getattr(settings, 'CASBIN_ADAPTER_ARGS', (,))
26+
Adapter = import_class(adapter_loc)
27+
adapter = adapter_class(*adapter_args)
2328

2429
super().__init__(model, adapter, enable_log)
2530

casbin_adapter/utils.py

Whitespace-only changes.

0 commit comments

Comments
 (0)