casbin-async-django-orm-adapter 1.0.0__py3-none-any.whl
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.
- async_casbin_adapter/__init__.py +0 -0
- async_casbin_adapter/adapter.py +100 -0
- async_casbin_adapter/apps.py +24 -0
- async_casbin_adapter/enforcer.py +81 -0
- async_casbin_adapter/migrations/0001_initial.py +37 -0
- async_casbin_adapter/migrations/__init__.py +0 -0
- async_casbin_adapter/models.py +48 -0
- async_casbin_adapter/utils.py +25 -0
- casbin_async_django_orm_adapter-1.0.0.dist-info/METADATA +116 -0
- casbin_async_django_orm_adapter-1.0.0.dist-info/RECORD +74 -0
- casbin_async_django_orm_adapter-1.0.0.dist-info/WHEEL +5 -0
- casbin_async_django_orm_adapter-1.0.0.dist-info/licenses/LICENSE +201 -0
- casbin_async_django_orm_adapter-1.0.0.dist-info/top_level.txt +3 -0
- node_modules/npm/node_modules/node-gyp/gyp/gyp_main.py +45 -0
- node_modules/npm/node_modules/node-gyp/gyp/pylib/gyp/MSVSNew.py +365 -0
- node_modules/npm/node_modules/node-gyp/gyp/pylib/gyp/MSVSProject.py +206 -0
- node_modules/npm/node_modules/node-gyp/gyp/pylib/gyp/MSVSSettings.py +1272 -0
- node_modules/npm/node_modules/node-gyp/gyp/pylib/gyp/MSVSSettings_test.py +1547 -0
- node_modules/npm/node_modules/node-gyp/gyp/pylib/gyp/MSVSToolFile.py +59 -0
- node_modules/npm/node_modules/node-gyp/gyp/pylib/gyp/MSVSUserFile.py +152 -0
- node_modules/npm/node_modules/node-gyp/gyp/pylib/gyp/MSVSUtil.py +270 -0
- node_modules/npm/node_modules/node-gyp/gyp/pylib/gyp/MSVSVersion.py +574 -0
- node_modules/npm/node_modules/node-gyp/gyp/pylib/gyp/__init__.py +704 -0
- node_modules/npm/node_modules/node-gyp/gyp/pylib/gyp/common.py +709 -0
- node_modules/npm/node_modules/node-gyp/gyp/pylib/gyp/common_test.py +173 -0
- node_modules/npm/node_modules/node-gyp/gyp/pylib/gyp/easy_xml.py +169 -0
- node_modules/npm/node_modules/node-gyp/gyp/pylib/gyp/easy_xml_test.py +113 -0
- node_modules/npm/node_modules/node-gyp/gyp/pylib/gyp/flock_tool.py +55 -0
- node_modules/npm/node_modules/node-gyp/gyp/pylib/gyp/generator/__init__.py +0 -0
- node_modules/npm/node_modules/node-gyp/gyp/pylib/gyp/generator/analyzer.py +805 -0
- node_modules/npm/node_modules/node-gyp/gyp/pylib/gyp/generator/android.py +1172 -0
- node_modules/npm/node_modules/node-gyp/gyp/pylib/gyp/generator/cmake.py +1319 -0
- node_modules/npm/node_modules/node-gyp/gyp/pylib/gyp/generator/compile_commands_json.py +128 -0
- node_modules/npm/node_modules/node-gyp/gyp/pylib/gyp/generator/dump_dependency_json.py +104 -0
- node_modules/npm/node_modules/node-gyp/gyp/pylib/gyp/generator/eclipse.py +462 -0
- node_modules/npm/node_modules/node-gyp/gyp/pylib/gyp/generator/gypd.py +89 -0
- node_modules/npm/node_modules/node-gyp/gyp/pylib/gyp/generator/gypsh.py +56 -0
- node_modules/npm/node_modules/node-gyp/gyp/pylib/gyp/generator/make.py +2745 -0
- node_modules/npm/node_modules/node-gyp/gyp/pylib/gyp/generator/msvs.py +3976 -0
- node_modules/npm/node_modules/node-gyp/gyp/pylib/gyp/generator/msvs_test.py +44 -0
- node_modules/npm/node_modules/node-gyp/gyp/pylib/gyp/generator/ninja.py +2965 -0
- node_modules/npm/node_modules/node-gyp/gyp/pylib/gyp/generator/ninja_test.py +67 -0
- node_modules/npm/node_modules/node-gyp/gyp/pylib/gyp/generator/xcode.py +1391 -0
- node_modules/npm/node_modules/node-gyp/gyp/pylib/gyp/generator/xcode_test.py +26 -0
- node_modules/npm/node_modules/node-gyp/gyp/pylib/gyp/input.py +3112 -0
- node_modules/npm/node_modules/node-gyp/gyp/pylib/gyp/input_test.py +99 -0
- node_modules/npm/node_modules/node-gyp/gyp/pylib/gyp/mac_tool.py +767 -0
- node_modules/npm/node_modules/node-gyp/gyp/pylib/gyp/msvs_emulation.py +1260 -0
- node_modules/npm/node_modules/node-gyp/gyp/pylib/gyp/ninja_syntax.py +174 -0
- node_modules/npm/node_modules/node-gyp/gyp/pylib/gyp/simple_copy.py +61 -0
- node_modules/npm/node_modules/node-gyp/gyp/pylib/gyp/win_tool.py +373 -0
- node_modules/npm/node_modules/node-gyp/gyp/pylib/gyp/xcode_emulation.py +1939 -0
- node_modules/npm/node_modules/node-gyp/gyp/pylib/gyp/xcode_emulation_test.py +54 -0
- node_modules/npm/node_modules/node-gyp/gyp/pylib/gyp/xcode_ninja.py +303 -0
- node_modules/npm/node_modules/node-gyp/gyp/pylib/gyp/xcodeproj_file.py +3196 -0
- node_modules/npm/node_modules/node-gyp/gyp/pylib/gyp/xml_fix.py +65 -0
- node_modules/npm/node_modules/node-gyp/gyp/pylib/packaging/__init__.py +15 -0
- node_modules/npm/node_modules/node-gyp/gyp/pylib/packaging/_elffile.py +108 -0
- node_modules/npm/node_modules/node-gyp/gyp/pylib/packaging/_manylinux.py +252 -0
- node_modules/npm/node_modules/node-gyp/gyp/pylib/packaging/_musllinux.py +83 -0
- node_modules/npm/node_modules/node-gyp/gyp/pylib/packaging/_parser.py +359 -0
- node_modules/npm/node_modules/node-gyp/gyp/pylib/packaging/_structures.py +61 -0
- node_modules/npm/node_modules/node-gyp/gyp/pylib/packaging/_tokenizer.py +192 -0
- node_modules/npm/node_modules/node-gyp/gyp/pylib/packaging/markers.py +252 -0
- node_modules/npm/node_modules/node-gyp/gyp/pylib/packaging/metadata.py +825 -0
- node_modules/npm/node_modules/node-gyp/gyp/pylib/packaging/py.typed +0 -0
- node_modules/npm/node_modules/node-gyp/gyp/pylib/packaging/requirements.py +90 -0
- node_modules/npm/node_modules/node-gyp/gyp/pylib/packaging/specifiers.py +1030 -0
- node_modules/npm/node_modules/node-gyp/gyp/pylib/packaging/tags.py +553 -0
- node_modules/npm/node_modules/node-gyp/gyp/pylib/packaging/utils.py +172 -0
- node_modules/npm/node_modules/node-gyp/gyp/pylib/packaging/version.py +563 -0
- node_modules/npm/node_modules/node-gyp/gyp/test_gyp.py +261 -0
- node_modules/semantic-release-pypi/dist/py/set_version.py +32 -0
- node_modules/semantic-release-pypi/dist/py/verify_setup.py +24 -0
File without changes
|
@@ -0,0 +1,100 @@
|
|
1
|
+
# Copyright 2025 The casbin Authors. All Rights Reserved.
|
2
|
+
#
|
3
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
4
|
+
# you may not use this file except in compliance with the License.
|
5
|
+
# You may obtain a copy of the License at
|
6
|
+
#
|
7
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
8
|
+
#
|
9
|
+
# Unless required by applicable law or agreed to in writing, software
|
10
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
11
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
12
|
+
# See the License for the specific language governing permissions and
|
13
|
+
# limitations under the License.
|
14
|
+
|
15
|
+
import logging
|
16
|
+
|
17
|
+
from casbin import persist
|
18
|
+
from casbin.persist.adapters.asyncio import AsyncAdapter
|
19
|
+
from django.db.utils import OperationalError, ProgrammingError
|
20
|
+
|
21
|
+
from .models import CasbinRule
|
22
|
+
|
23
|
+
logger = logging.getLogger(__name__)
|
24
|
+
|
25
|
+
|
26
|
+
class AsyncAdapter(AsyncAdapter):
|
27
|
+
"""the interface for Casbin async adapters."""
|
28
|
+
|
29
|
+
def __init__(self, db_alias="default"):
|
30
|
+
self.db_alias = db_alias
|
31
|
+
|
32
|
+
async def load_policy(self, model):
|
33
|
+
"""loads all policy rules from the storage."""
|
34
|
+
try:
|
35
|
+
lines = CasbinRule.objects.using(self.db_alias).all()
|
36
|
+
|
37
|
+
async for line in lines:
|
38
|
+
persist.load_policy_line(str(line), model)
|
39
|
+
except (OperationalError, ProgrammingError) as error:
|
40
|
+
logger.warning("Could not load policy from database: {}".format(error))
|
41
|
+
|
42
|
+
def _create_policy_line(self, ptype, rule):
|
43
|
+
line = CasbinRule(ptype=ptype)
|
44
|
+
if len(rule) > 0:
|
45
|
+
line.v0 = rule[0]
|
46
|
+
if len(rule) > 1:
|
47
|
+
line.v1 = rule[1]
|
48
|
+
if len(rule) > 2:
|
49
|
+
line.v2 = rule[2]
|
50
|
+
if len(rule) > 3:
|
51
|
+
line.v3 = rule[3]
|
52
|
+
if len(rule) > 4:
|
53
|
+
line.v4 = rule[4]
|
54
|
+
if len(rule) > 5:
|
55
|
+
line.v5 = rule[5]
|
56
|
+
return line
|
57
|
+
|
58
|
+
async def save_policy(self, model):
|
59
|
+
"""saves all policy rules to the storage."""
|
60
|
+
# this will delete all rules
|
61
|
+
await CasbinRule.objects.using(self.db_alias).all().adelete()
|
62
|
+
|
63
|
+
lines = []
|
64
|
+
for sec in ["p", "g"]:
|
65
|
+
if sec not in model.model.keys():
|
66
|
+
continue
|
67
|
+
for ptype, ast in model.model[sec].items():
|
68
|
+
for rule in ast.policy:
|
69
|
+
lines.append(self._create_policy_line(ptype, rule))
|
70
|
+
|
71
|
+
db_alias = self.db_alias if self.db_alias else "default"
|
72
|
+
rows_created = await CasbinRule.objects.using(db_alias).abulk_create(lines)
|
73
|
+
return len(rows_created) > 0
|
74
|
+
|
75
|
+
async def add_policy(self, sec, ptype, rule):
|
76
|
+
"""adds a policy rule to the storage."""
|
77
|
+
line = self._create_policy_line(ptype, rule)
|
78
|
+
await line.asave()
|
79
|
+
|
80
|
+
async def remove_policy(self, sec, ptype, rule):
|
81
|
+
"""removes a policy rule from the storage."""
|
82
|
+
query_params = {"ptype": ptype}
|
83
|
+
for i, v in enumerate(rule):
|
84
|
+
query_params["v{}".format(i)] = v
|
85
|
+
|
86
|
+
rows_deleted, _ = await CasbinRule.objects.using(self.db_alias).filter(**query_params).adelete()
|
87
|
+
return rows_deleted > 0
|
88
|
+
|
89
|
+
async def remove_filtered_policy(self, sec, ptype, field_index, *field_values):
|
90
|
+
"""removes policy rules that match the filter from the storage."""
|
91
|
+
query_params = {"ptype": ptype}
|
92
|
+
if not (0 <= field_index <= 5):
|
93
|
+
return False
|
94
|
+
if not (1 <= field_index + len(field_values) <= 6):
|
95
|
+
return False
|
96
|
+
for i, v in enumerate(field_values):
|
97
|
+
query_params["v{}".format(i + field_index)] = v
|
98
|
+
|
99
|
+
rows_deleted, _ = await CasbinRule.objects.using(self.db_alias).filter(**query_params).adelete()
|
100
|
+
return rows_deleted > 0
|
@@ -0,0 +1,24 @@
|
|
1
|
+
# Copyright 2025 The casbin Authors. All Rights Reserved.
|
2
|
+
#
|
3
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
4
|
+
# you may not use this file except in compliance with the License.
|
5
|
+
# You may obtain a copy of the License at
|
6
|
+
#
|
7
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
8
|
+
#
|
9
|
+
# Unless required by applicable law or agreed to in writing, software
|
10
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
11
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
12
|
+
# See the License for the specific language governing permissions and
|
13
|
+
# limitations under the License.
|
14
|
+
|
15
|
+
from django.apps import AppConfig
|
16
|
+
import logging
|
17
|
+
|
18
|
+
|
19
|
+
logger = logging.getLogger(__name__)
|
20
|
+
|
21
|
+
|
22
|
+
class AsyncCasbinAdapterConfig(AppConfig):
|
23
|
+
default_auto_field = "django.db.models.BigAutoField"
|
24
|
+
name = "async_casbin_adapter"
|
@@ -0,0 +1,81 @@
|
|
1
|
+
# Copyright 2025 The casbin Authors. All Rights Reserved.
|
2
|
+
#
|
3
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
4
|
+
# you may not use this file except in compliance with the License.
|
5
|
+
# You may obtain a copy of the License at
|
6
|
+
#
|
7
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
8
|
+
#
|
9
|
+
# Unless required by applicable law or agreed to in writing, software
|
10
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
11
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
12
|
+
# See the License for the specific language governing permissions and
|
13
|
+
# limitations under the License.
|
14
|
+
|
15
|
+
import logging
|
16
|
+
from django.conf import settings
|
17
|
+
from django.db import connections
|
18
|
+
from asgiref.sync import sync_to_async
|
19
|
+
|
20
|
+
from casbin import AsyncEnforcer
|
21
|
+
|
22
|
+
from .utils import import_class
|
23
|
+
|
24
|
+
|
25
|
+
logger = logging.getLogger(__name__)
|
26
|
+
|
27
|
+
|
28
|
+
def _perform_sync_db_check(db_alias):
|
29
|
+
logger.info(f"Performing synchronous DB check for migration on alias '{db_alias}'...")
|
30
|
+
connection = connections[db_alias]
|
31
|
+
try:
|
32
|
+
with connection.cursor() as cursor:
|
33
|
+
cursor.execute(
|
34
|
+
"""
|
35
|
+
SELECT app, name FROM django_migrations
|
36
|
+
WHERE app = 'async_casbin_adapter' AND name = '0001_initial';
|
37
|
+
"""
|
38
|
+
)
|
39
|
+
row = cursor.fetchone()
|
40
|
+
|
41
|
+
if not row:
|
42
|
+
raise RuntimeError("Async Casbin Adapter initial migration not applied. ")
|
43
|
+
logger.info("Synchronous DB check passed.")
|
44
|
+
return True
|
45
|
+
except Exception as e:
|
46
|
+
logger.error(f"Synchronous DB check failed: {e}")
|
47
|
+
raise
|
48
|
+
|
49
|
+
|
50
|
+
async def get_enforcer(db_alias=None):
|
51
|
+
"""
|
52
|
+
An asynchronous factory function for creating and initializing Casbin AsyncEnforcer
|
53
|
+
"""
|
54
|
+
if db_alias is None:
|
55
|
+
db_alias = getattr(settings, "CASBIN_DB_ALIAS", "default")
|
56
|
+
|
57
|
+
async_db_check = sync_to_async(_perform_sync_db_check, thread_sensitive=True)
|
58
|
+
await async_db_check(db_alias)
|
59
|
+
|
60
|
+
model = getattr(settings, "CASBIN_MODEL")
|
61
|
+
adapter_loc = getattr(settings, "ASYNC_CASBIN_ADAPTER", "async_casbin_adapter.adapter.AsyncAdapter")
|
62
|
+
adapter_args = getattr(settings, "CASBIN_ADAPTER_ARGS", tuple())
|
63
|
+
Adapter = import_class(adapter_loc)
|
64
|
+
adapter = Adapter(db_alias, *adapter_args)
|
65
|
+
|
66
|
+
enforcer = AsyncEnforcer(model, adapter)
|
67
|
+
|
68
|
+
watcher_loc = getattr(settings, "CASBIN_WATCHER", None)
|
69
|
+
if watcher_loc:
|
70
|
+
Watcher = import_class(watcher_loc)
|
71
|
+
enforcer.set_watcher(Watcher())
|
72
|
+
|
73
|
+
role_manager_loc = getattr(settings, "CASBIN_ROLE_MANAGER", None)
|
74
|
+
if role_manager_loc:
|
75
|
+
RoleManager = import_class(role_manager_loc)
|
76
|
+
enforcer.set_role_manager(RoleManager())
|
77
|
+
|
78
|
+
await enforcer.load_policy()
|
79
|
+
|
80
|
+
logger.info("Casbin AsyncEnforcer initialized successfully.")
|
81
|
+
return enforcer
|
@@ -0,0 +1,37 @@
|
|
1
|
+
# Generated by Django 5.2.5 on 2025-09-05 09:40
|
2
|
+
|
3
|
+
from django.db import migrations, models
|
4
|
+
|
5
|
+
|
6
|
+
class Migration(migrations.Migration):
|
7
|
+
|
8
|
+
initial = True
|
9
|
+
|
10
|
+
dependencies = []
|
11
|
+
|
12
|
+
operations = [
|
13
|
+
migrations.CreateModel(
|
14
|
+
name="CasbinRule",
|
15
|
+
fields=[
|
16
|
+
(
|
17
|
+
"id",
|
18
|
+
models.BigAutoField(
|
19
|
+
auto_created=True,
|
20
|
+
primary_key=True,
|
21
|
+
serialize=False,
|
22
|
+
verbose_name="ID",
|
23
|
+
),
|
24
|
+
),
|
25
|
+
("ptype", models.CharField(max_length=255)),
|
26
|
+
("v0", models.CharField(max_length=255)),
|
27
|
+
("v1", models.CharField(max_length=255)),
|
28
|
+
("v2", models.CharField(max_length=255)),
|
29
|
+
("v3", models.CharField(max_length=255)),
|
30
|
+
("v4", models.CharField(max_length=255)),
|
31
|
+
("v5", models.CharField(max_length=255)),
|
32
|
+
],
|
33
|
+
options={
|
34
|
+
"db_table": "casbin_rule",
|
35
|
+
},
|
36
|
+
),
|
37
|
+
]
|
File without changes
|
@@ -0,0 +1,48 @@
|
|
1
|
+
# Copyright 2025 The casbin Authors. All Rights Reserved.
|
2
|
+
#
|
3
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
4
|
+
# you may not use this file except in compliance with the License.
|
5
|
+
# You may obtain a copy of the License at
|
6
|
+
#
|
7
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
8
|
+
#
|
9
|
+
# Unless required by applicable law or agreed to in writing, software
|
10
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
11
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
12
|
+
# See the License for the specific language governing permissions and
|
13
|
+
# limitations under the License.
|
14
|
+
|
15
|
+
from django.db import models
|
16
|
+
|
17
|
+
|
18
|
+
class CasbinRule(models.Model):
|
19
|
+
ptype = models.CharField(max_length=255)
|
20
|
+
v0 = models.CharField(max_length=255)
|
21
|
+
v1 = models.CharField(max_length=255)
|
22
|
+
v2 = models.CharField(max_length=255)
|
23
|
+
v3 = models.CharField(max_length=255)
|
24
|
+
v4 = models.CharField(max_length=255)
|
25
|
+
v5 = models.CharField(max_length=255)
|
26
|
+
|
27
|
+
class Meta:
|
28
|
+
db_table = "casbin_rule"
|
29
|
+
|
30
|
+
def __str__(self):
|
31
|
+
text = self.ptype
|
32
|
+
|
33
|
+
if self.v0:
|
34
|
+
text = text + ", " + self.v0
|
35
|
+
if self.v1:
|
36
|
+
text = text + ", " + self.v1
|
37
|
+
if self.v2:
|
38
|
+
text = text + ", " + self.v2
|
39
|
+
if self.v3:
|
40
|
+
text = text + ", " + self.v3
|
41
|
+
if self.v4:
|
42
|
+
text = text + ", " + self.v4
|
43
|
+
if self.v5:
|
44
|
+
text = text + ", " + self.v5
|
45
|
+
return text
|
46
|
+
|
47
|
+
def __repr__(self):
|
48
|
+
return '<CasbinRule {}: "{}">'.format(self.id, str(self))
|
@@ -0,0 +1,25 @@
|
|
1
|
+
# Copyright 2025 The casbin Authors. All Rights Reserved.
|
2
|
+
#
|
3
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
4
|
+
# you may not use this file except in compliance with the License.
|
5
|
+
# You may obtain a copy of the License at
|
6
|
+
#
|
7
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
8
|
+
#
|
9
|
+
# Unless required by applicable law or agreed to in writing, software
|
10
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
11
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
12
|
+
# See the License for the specific language governing permissions and
|
13
|
+
# limitations under the License.
|
14
|
+
|
15
|
+
import importlib
|
16
|
+
|
17
|
+
|
18
|
+
def import_class(name):
|
19
|
+
"""Import class from string
|
20
|
+
e.g. `package.module.ClassToImport` returns the `ClassToImport` class"""
|
21
|
+
components = name.split(".")
|
22
|
+
module_name = ".".join(components[:-1])
|
23
|
+
class_name = components[-1]
|
24
|
+
module = importlib.import_module(module_name)
|
25
|
+
return getattr(module, class_name)
|
@@ -0,0 +1,116 @@
|
|
1
|
+
Metadata-Version: 2.4
|
2
|
+
Name: casbin-async-django-orm-adapter
|
3
|
+
Version: 1.0.0
|
4
|
+
Summary: Async Django ORM adapter for PyCasbin
|
5
|
+
Author-email: Yang Luo <hsluoyz@qq.com>
|
6
|
+
License: Apache 2.0
|
7
|
+
Project-URL: Home-page, https://github.com/officialpycasbin/async-django-orm-adapter
|
8
|
+
Keywords: async,pycasbin,casbin,adapter,storage-driver,django,orm,django-orm,access-control,authorization
|
9
|
+
Classifier: Programming Language :: Python :: 3.9
|
10
|
+
Classifier: Programming Language :: Python :: 3.10
|
11
|
+
Classifier: Programming Language :: Python :: 3.11
|
12
|
+
Classifier: Programming Language :: Python :: 3.12
|
13
|
+
Classifier: License :: OSI Approved :: Apache Software License
|
14
|
+
Classifier: Operating System :: OS Independent
|
15
|
+
Requires-Python: >=3.7
|
16
|
+
Description-Content-Type: text/markdown
|
17
|
+
License-File: LICENSE
|
18
|
+
Requires-Dist: pycasbin>=2.0.0
|
19
|
+
Requires-Dist: Django
|
20
|
+
Dynamic: license-file
|
21
|
+
|
22
|
+
# async-django-orm-adapter
|
23
|
+
|
24
|
+
[](https://discord.gg/S5UjpzGZjN)
|
25
|
+
|
26
|
+
Asynchronous Django ORM Adapter is the async [Django](https://www.djangoproject.com/) [ORM](https://docs.djangoproject.com/en/3.0/ref/databases/) adapter for [PyCasbin](https://github.com/casbin/pycasbin). With this library, Casbin can load policy from Django ORM supported database or save policy to it.
|
27
|
+
|
28
|
+
Based on [Officially Supported Databases](https://docs.djangoproject.com/en/3.0/ref/databases/), The current supported databases are:
|
29
|
+
|
30
|
+
- PostgreSQL
|
31
|
+
- MariaDB
|
32
|
+
- MySQL
|
33
|
+
- Oracle
|
34
|
+
- SQLite
|
35
|
+
- IBM DB2
|
36
|
+
- Microsoft SQL Server
|
37
|
+
- Firebird
|
38
|
+
- ODBC
|
39
|
+
|
40
|
+
## Installation
|
41
|
+
|
42
|
+
```
|
43
|
+
pip install casbin-async-django-orm-adapter
|
44
|
+
```
|
45
|
+
|
46
|
+
Add `async_casbin_adapter.apps.AsyncCasbinAdapterConfig` to your `INSTALLED_APPS`
|
47
|
+
|
48
|
+
```python
|
49
|
+
# settings.py
|
50
|
+
BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
|
51
|
+
|
52
|
+
INSTALLED_APPS = [
|
53
|
+
...
|
54
|
+
'async_casbin_adapter.apps.AsyncCasbinAdapterConfig',
|
55
|
+
...
|
56
|
+
]
|
57
|
+
|
58
|
+
CASBIN_MODEL = os.path.join(BASE_DIR, 'casbin.conf')
|
59
|
+
```
|
60
|
+
|
61
|
+
To run schema migration, execute `python manage.py migrate async_casbin_adapter`
|
62
|
+
|
63
|
+
## Simple Example
|
64
|
+
|
65
|
+
```python
|
66
|
+
# views.py
|
67
|
+
from async_casbin_adapter.enforcer import get_enforcer
|
68
|
+
|
69
|
+
async def hello(request):
|
70
|
+
sub = "alice" # the user that wants to access a resource.
|
71
|
+
obj = "data1" # the resource that is going to be accessed.
|
72
|
+
act = "read" # the operation that the user performs on the resource.
|
73
|
+
|
74
|
+
enforcer = await get_enforcer()
|
75
|
+
if e.enforce(sub, obj, act):
|
76
|
+
# permit alice to read data1casbin_django_orm_adapter
|
77
|
+
pass
|
78
|
+
else:
|
79
|
+
# deny the request, show an error
|
80
|
+
pass
|
81
|
+
```
|
82
|
+
|
83
|
+
## Configuration
|
84
|
+
|
85
|
+
### `CASBIN_MODEL`
|
86
|
+
A string containing the file location of your casbin model.
|
87
|
+
|
88
|
+
### `CASBIN_ADAPTER`
|
89
|
+
A string containing the adapter import path. Default to the django adapter shipped with this package: `async_casbin_adapter.adapter.AsyncAdapter`
|
90
|
+
|
91
|
+
### `CASBIN_ADAPTER_ARGS`
|
92
|
+
A tuple of arguments to be passed into the constructor of the adapter specified
|
93
|
+
in `CASBIN_ADAPTER`. Refer to adapters to see available arguments.
|
94
|
+
|
95
|
+
E.g. if you wish to use the file adapter
|
96
|
+
set the adapter to `casbin.persist.adapters.FileAdapter` and use
|
97
|
+
`CASBIN_ADAPTER_ARGS = ('path/to/policy_file.csv',)`
|
98
|
+
|
99
|
+
### `CASBIN_DB_ALIAS`
|
100
|
+
The database the adapter uses. Default to "default".
|
101
|
+
|
102
|
+
### `CASBIN_WATCHER`
|
103
|
+
Watcher instance to be set as the watcher on the enforcer instance.
|
104
|
+
|
105
|
+
### `CASBIN_ROLE_MANAGER`
|
106
|
+
Role manager instance to be set as the role manager on the enforcer instance.
|
107
|
+
|
108
|
+
|
109
|
+
### Getting Help
|
110
|
+
|
111
|
+
- [PyCasbin](https://github.com/casbin/pycasbin)
|
112
|
+
|
113
|
+
### License
|
114
|
+
|
115
|
+
This project is licensed under the [Apache 2.0 license](LICENSE).
|
116
|
+
|
@@ -0,0 +1,74 @@
|
|
1
|
+
async_casbin_adapter/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
2
|
+
async_casbin_adapter/adapter.py,sha256=AFwxbGdaJWGsCOcYk1p1bbILSSbHoeI3c9mrJFWNsXs,3686
|
3
|
+
async_casbin_adapter/apps.py,sha256=_Zjst3clp8DPqx9-veI5oomcmsC9ood5iS7ve-tyWkM,830
|
4
|
+
async_casbin_adapter/enforcer.py,sha256=uCudaGGBXQN8MDNePCEtcBUGMTTtHG6fW16pBBiXY4c,2780
|
5
|
+
async_casbin_adapter/models.py,sha256=JsVZQnvmhI1umCivHMY6jmmTlgQ-osk5FubF7CVBlvs,1544
|
6
|
+
async_casbin_adapter/utils.py,sha256=FLLLjXIRgTWfFqjE2SaiTDAil42S_A0M_CTzik0dSKk,956
|
7
|
+
async_casbin_adapter/migrations/0001_initial.py,sha256=_YnYxgP_azDSQWHMo5RieoJUQXB-GyzkhxBDcPZtam4,1095
|
8
|
+
async_casbin_adapter/migrations/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
9
|
+
casbin_async_django_orm_adapter-1.0.0.dist-info/licenses/LICENSE,sha256=xx0jnfkXJvxRnG63LTGOxlggYnIysveWIZ6H3PNdCrQ,11357
|
10
|
+
node_modules/npm/node_modules/node-gyp/gyp/gyp_main.py,sha256=gOsKGUgjDIMvF7-Z8xqHKdVARNgEac_g_srOaeerZqY,1250
|
11
|
+
node_modules/npm/node_modules/node-gyp/gyp/test_gyp.py,sha256=7PWZav30J2V-o0h5VFmqEyxmhPpjUPH9xYBJQnhcF8k,7691
|
12
|
+
node_modules/npm/node_modules/node-gyp/gyp/pylib/gyp/MSVSNew.py,sha256=mzNxGJv3xJz8NLNfPaj1V9Yv1BH38PktL9i7hYphDOo,13029
|
13
|
+
node_modules/npm/node_modules/node-gyp/gyp/pylib/gyp/MSVSProject.py,sha256=6i0lB7o_XoITED062iStKzkGvjAa9dOR8i144Aax4Ls,6732
|
14
|
+
node_modules/npm/node_modules/node-gyp/gyp/pylib/gyp/MSVSSettings.py,sha256=nLWtz6P0eyRyYOBO_S-WGKgQ7xXWNUYX2ZcsyYVY1l0,45452
|
15
|
+
node_modules/npm/node_modules/node-gyp/gyp/pylib/gyp/MSVSSettings_test.py,sha256=02XqIF-1lTV0fAb0zoJPA7hSNVMjyfw7hAVEobLF8pA,74286
|
16
|
+
node_modules/npm/node_modules/node-gyp/gyp/pylib/gyp/MSVSToolFile.py,sha256=iMp0oiweW12S02CpXXFurd9omUPEfxMuVcSlT_PtlOQ,1782
|
17
|
+
node_modules/npm/node_modules/node-gyp/gyp/pylib/gyp/MSVSUserFile.py,sha256=1WnQrXCQWH4ohj4Y4bfLzZl2Pdy2UJ6gO1wF74wh4Fg,5325
|
18
|
+
node_modules/npm/node_modules/node-gyp/gyp/pylib/gyp/MSVSUtil.py,sha256=OkSDMtL1zZQE-epLNBUdrjgQCeDUNaTcwzl__xIL7c8,10230
|
19
|
+
node_modules/npm/node_modules/node-gyp/gyp/pylib/gyp/MSVSVersion.py,sha256=cRWt9bqH-3GffwLXUHyJiwRP2ink-4LwJl3iH1xc5J4,19744
|
20
|
+
node_modules/npm/node_modules/node-gyp/gyp/pylib/gyp/__init__.py,sha256=aRZB6y6u3NDYEJvWmpCZ7v37lkBegdKrJ4tncBZReA4,24562
|
21
|
+
node_modules/npm/node_modules/node-gyp/gyp/pylib/gyp/common.py,sha256=QGWO-e1zBGF1QFs4LbscBlpbrn7GZ9z9oZVpaQVYgAQ,24582
|
22
|
+
node_modules/npm/node_modules/node-gyp/gyp/pylib/gyp/common_test.py,sha256=-emUJeGyMl2bN687KNEyfdX0uDxWDslILAgD0H04wXM,5716
|
23
|
+
node_modules/npm/node_modules/node-gyp/gyp/pylib/gyp/easy_xml.py,sha256=GICY6cjlHnVJ_QkRBy3rljPTvy-Ykkgr2Vy-4Ti0KHs,5425
|
24
|
+
node_modules/npm/node_modules/node-gyp/gyp/pylib/gyp/easy_xml_test.py,sha256=3oc9BPr9cXuGo7erwwTCUNvcaR20Qwku-HqwdBgZ5Y8,3943
|
25
|
+
node_modules/npm/node_modules/node-gyp/gyp/pylib/gyp/flock_tool.py,sha256=NqP4clxE-6pVXVfDnDiW0XAoPhZMU_8-vlnLQ9s5PBo,1886
|
26
|
+
node_modules/npm/node_modules/node-gyp/gyp/pylib/gyp/input.py,sha256=Jyv6gTGKlz1f7Jbw1Ja8iLzG5k-veW8o0OLLbimIXXY,126396
|
27
|
+
node_modules/npm/node_modules/node-gyp/gyp/pylib/gyp/input_test.py,sha256=nCv7azVvSS-vF9Eui11qu_RVT2vPG-_Erj-oUmgazqs,3426
|
28
|
+
node_modules/npm/node_modules/node-gyp/gyp/pylib/gyp/mac_tool.py,sha256=hXtJTTBcn2oWevCHEOVRMLUobrZDOCfbn6CDOTRVABk,30123
|
29
|
+
node_modules/npm/node_modules/node-gyp/gyp/pylib/gyp/msvs_emulation.py,sha256=jzNVLumqNttq4byaADi1PdPJIWMYrqWuw9hthAsWfvk,54122
|
30
|
+
node_modules/npm/node_modules/node-gyp/gyp/pylib/gyp/ninja_syntax.py,sha256=zMHkB8l0O7oRkuYFoaN9dotnbATBHZgErQztwE_W648,5640
|
31
|
+
node_modules/npm/node_modules/node-gyp/gyp/pylib/gyp/simple_copy.py,sha256=2V-wVMJ9TQ94aAQ9Omph4w_4DFCm_UGmG_L4alylB80,1293
|
32
|
+
node_modules/npm/node_modules/node-gyp/gyp/pylib/gyp/win_tool.py,sha256=XKY-2mqlBEfXsGjf6ozAboN64RYWPK7ytI4emK6-CDw,15131
|
33
|
+
node_modules/npm/node_modules/node-gyp/gyp/pylib/gyp/xcode_emulation.py,sha256=2Wl7sy6DHlC843kjRCrEb2ZwkYbrusiV5jV4AACMr_A,81981
|
34
|
+
node_modules/npm/node_modules/node-gyp/gyp/pylib/gyp/xcode_emulation_test.py,sha256=eEphiO1QEl5qdNcuW1e7ogdtDVaTxSN3ZUKlUwCRyrc,1489
|
35
|
+
node_modules/npm/node_modules/node-gyp/gyp/pylib/gyp/xcode_ninja.py,sha256=GP1JKt30Xf3g1PF3-F5VjCbCXTwhGDIkrJqkQPGSyw0,12125
|
36
|
+
node_modules/npm/node_modules/node-gyp/gyp/pylib/gyp/xcodeproj_file.py,sha256=zCvgZdHSGCax46mFdZjUnGlQXZzrDsSeRQbepj0n0kE,135596
|
37
|
+
node_modules/npm/node_modules/node-gyp/gyp/pylib/gyp/xml_fix.py,sha256=-z0nf3UnZa7vNw0uwxYYhISHrN6eSHIEVsGjiEaAuBg,2245
|
38
|
+
node_modules/npm/node_modules/node-gyp/gyp/pylib/gyp/generator/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
39
|
+
node_modules/npm/node_modules/node-gyp/gyp/pylib/gyp/generator/analyzer.py,sha256=Xm-S8jZHwD8FpxKkSypH_7khjm1THgfGSkXgHKr32uI,31540
|
40
|
+
node_modules/npm/node_modules/node-gyp/gyp/pylib/gyp/generator/android.py,sha256=kZWeETJ3fmFKhBzLoNDwhYOagI7BFwQ6pnVoSeAxbAs,49815
|
41
|
+
node_modules/npm/node_modules/node-gyp/gyp/pylib/gyp/generator/cmake.py,sha256=A9J1FnkYf6StVzWU0Qn9ynonSDC0F-AJJdNmJL1-z1g,49203
|
42
|
+
node_modules/npm/node_modules/node-gyp/gyp/pylib/gyp/generator/compile_commands_json.py,sha256=rnoSt5dZZlDWKFUZInaX5Yx2lVJRl4vb790Zt_Ax59g,4849
|
43
|
+
node_modules/npm/node_modules/node-gyp/gyp/pylib/gyp/generator/dump_dependency_json.py,sha256=GEzwTkRQ8dQJfo_AzFeSKyP-uVBbfd1PBKXjgFc23vs,3102
|
44
|
+
node_modules/npm/node_modules/node-gyp/gyp/pylib/gyp/generator/eclipse.py,sha256=v3MaKUMkGRam8aDZKtF-Et8UmTpEwfbWXlW9IRlYuvM,17502
|
45
|
+
node_modules/npm/node_modules/node-gyp/gyp/pylib/gyp/generator/gypd.py,sha256=wVdr3hEBg-mBbJ5ciQb6KlpTmXTbFNJmGrsI4GnNMhw,3505
|
46
|
+
node_modules/npm/node_modules/node-gyp/gyp/pylib/gyp/generator/gypsh.py,sha256=0GIUNSBx_z3M5gI8QnW6SPz08TyhgqunM9FtCs9A4LM,1693
|
47
|
+
node_modules/npm/node_modules/node-gyp/gyp/pylib/gyp/generator/make.py,sha256=5FVgKqu4lkuTDcRwY_Y3ZMh7MbQTp4BL-YVvVcOm8QI,111590
|
48
|
+
node_modules/npm/node_modules/node-gyp/gyp/pylib/gyp/generator/msvs.py,sha256=gvDPjImXGMPT80l4aQs18MUuv8-zCW-rPyEYEhtn8nw,150686
|
49
|
+
node_modules/npm/node_modules/node-gyp/gyp/pylib/gyp/generator/msvs_test.py,sha256=GXwx0VN6YW9UEknU48egK8975dePLagBeEJoEpEtvFU,1263
|
50
|
+
node_modules/npm/node_modules/node-gyp/gyp/pylib/gyp/generator/ninja.py,sha256=0vT2fWyk8vQ4kTXeHUaA4zhxhVoqA1Y-FAdASltrJTY,119547
|
51
|
+
node_modules/npm/node_modules/node-gyp/gyp/pylib/gyp/generator/ninja_test.py,sha256=Iwe3AvH0ZDjGXhJoNCAIkJprR5mQb9uTfIu0UwbQn0U,2416
|
52
|
+
node_modules/npm/node_modules/node-gyp/gyp/pylib/gyp/generator/xcode.py,sha256=wCOq2RCCIG72DYcDZVz0ChSRQw3tItvWSnGAkVn8DPw,66017
|
53
|
+
node_modules/npm/node_modules/node-gyp/gyp/pylib/gyp/generator/xcode_test.py,sha256=PmjE1ka3d8g44YYw16_f1eDJR9wsfYIBCniDp2gm-wY,669
|
54
|
+
node_modules/npm/node_modules/node-gyp/gyp/pylib/packaging/__init__.py,sha256=KgBCfHz9vghN9DtyaCUxyewfe5VrjVDtiatA1m6Ch7Q,501
|
55
|
+
node_modules/npm/node_modules/node-gyp/gyp/pylib/packaging/_elffile.py,sha256=hbmK8OD6Z7fY6hwinHEUcD1by7czkGiNYu7ShnFEk2k,3266
|
56
|
+
node_modules/npm/node_modules/node-gyp/gyp/pylib/packaging/_manylinux.py,sha256=Rq6ppXAxH8XFtNf6tC-B-1SKuvCODPBvcCoSulMtbtk,9526
|
57
|
+
node_modules/npm/node_modules/node-gyp/gyp/pylib/packaging/_musllinux.py,sha256=kgmBGLFybpy8609-KTvzmt2zChCPWYvhp5BWP4JX7dE,2676
|
58
|
+
node_modules/npm/node_modules/node-gyp/gyp/pylib/packaging/_parser.py,sha256=5DhK_zYJE4U4yzSkgEBT4F7tT2xZ6Pkx4gSRKyvXneQ,10382
|
59
|
+
node_modules/npm/node_modules/node-gyp/gyp/pylib/packaging/_structures.py,sha256=q3eVNmbWJGG_S0Dit_S3Ao8qQqz_5PYTXFAKBZe5yr4,1431
|
60
|
+
node_modules/npm/node_modules/node-gyp/gyp/pylib/packaging/_tokenizer.py,sha256=alCtbwXhOFAmFGZ6BQ-wCTSFoRAJ2z-ysIf7__MTJ_k,5292
|
61
|
+
node_modules/npm/node_modules/node-gyp/gyp/pylib/packaging/markers.py,sha256=eH-txS2zq1HdNpTd9LcZUcVIwewAiNU0grmq5wjKnOk,8208
|
62
|
+
node_modules/npm/node_modules/node-gyp/gyp/pylib/packaging/metadata.py,sha256=BX-cG2W29bcNHLKK9M8N62HBnTGfEXepszVl0rhF-HM,33030
|
63
|
+
node_modules/npm/node_modules/node-gyp/gyp/pylib/packaging/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
64
|
+
node_modules/npm/node_modules/node-gyp/gyp/pylib/packaging/requirements.py,sha256=wswG4mXHSgE9w4NjNnlSvgLGo6yYvfHVEFnWhuEmXxg,2952
|
65
|
+
node_modules/npm/node_modules/node-gyp/gyp/pylib/packaging/specifiers.py,sha256=fmOSyM6_1KuFHLXQsRfIg6KiqAa5NyRPeXuxyooPL5A,39969
|
66
|
+
node_modules/npm/node_modules/node-gyp/gyp/pylib/packaging/tags.py,sha256=pkG6gQ28RlhS09VzymVhVpGrWF5doHXfK1VxG9cdhoY,18355
|
67
|
+
node_modules/npm/node_modules/node-gyp/gyp/pylib/packaging/utils.py,sha256=XgdmP3yx9-wQEFjO7OvMj9RjEf5JlR5HFFR69v7SQ9E,5268
|
68
|
+
node_modules/npm/node_modules/node-gyp/gyp/pylib/packaging/version.py,sha256=XjRBLNK17UMDgLeP8UHnqwiY3TdSi03xFQURtec211A,16236
|
69
|
+
node_modules/semantic-release-pypi/dist/py/set_version.py,sha256=D6RdhBLVlnYcSC0TvM_M6wHNXEJmJ2hyaQS-O_QeMhQ,929
|
70
|
+
node_modules/semantic-release-pypi/dist/py/verify_setup.py,sha256=XfLnFRubJ8MP0f9r3MUdxLOFeemG2P0qDbecjzOTfag,624
|
71
|
+
casbin_async_django_orm_adapter-1.0.0.dist-info/METADATA,sha256=aKvKH8D7eev1oXeggpHrfz1lPD1wp8YLypAK_1rYiTo,3599
|
72
|
+
casbin_async_django_orm_adapter-1.0.0.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
|
73
|
+
casbin_async_django_orm_adapter-1.0.0.dist-info/top_level.txt,sha256=D871I-OrXu-Jp9oEAWEHeEklGeSpAh1hKvkJETT_ENk,39
|
74
|
+
casbin_async_django_orm_adapter-1.0.0.dist-info/RECORD,,
|