ormar casbin adapter
Project description
ormar Adapter for PyCasbin
Repo
GitHub
PyPI
ormar Adapter is the ormar adapter for PyCasbin. With this library, Casbin can load policy from ormar supported database or save policy to it.
Based on Officially Supported Databases, The current supported databases are:
- PostgreSQL
- MySQL
- SQLite
Installation
pip install ormar_casbin_adapter
or
poetry add ormar-casbin-adapter
Simple Example
import casbin
import databases
import ormar
from ormar_casbin_adapter import DatabasesAdapter
import sqlalchemy
database = Database("sqlite://", force_rollback=True)
metadata = sqlalchemy.MetaData()
class CasbinRule(ormar.Model):
class Meta:
database = database
metadata = metadata
tablename = "casbin_rules"
id: int = ormar.Integer(primary_key=True)
ptype: str = ormar.String(max_length=255)
v0: str = ormar.String(max_length=255)
v1: str = ormar.String(max_length=255)
v2: str = ormar.String(max_length=255, nullable=True)
v3: str = ormar.String(max_length=255, nullable=True)
v4: str = ormar.String(max_length=255, nullable=True)
v5: str = ormar.String(max_length=255, nullable=True)
adapter = DatabasesAdapter(model=CasbinRule)
e = casbin.Enforcer("path/to/model.conf", adapter, True)
sub = "alice" # the user that wants to access a resource.
obj = "data1" # the resource that is going to be accessed.
act = "read" # the operation that the user performs on the resource.
if e.enforce(sub, obj, act):
# permit alice to read data1ormar_casbin_adapter
pass
else:
# deny the request, show an error
pass
Getting Help
License
This project is licensed under the Apache 2.0 license.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file ormar-casbin-adapter-0.0.2.tar.gz.
File metadata
- Download URL: ormar-casbin-adapter-0.0.2.tar.gz
- Upload date:
- Size: 8.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.1.13 CPython/3.10.2 Darwin/21.4.0
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
18e49ceb2f0546cf80a21b0b01648c6edd50d9de76032e0ae90676a71796ac3f
|
|
| MD5 |
b653bf89435ce7833bc08fbca611c1e7
|
|
| BLAKE2b-256 |
54f8ed934a14c9472fcd14dbeef0bd381dd48592807f99ba7a0b3bc671dd5f10
|
File details
Details for the file ormar_casbin_adapter-0.0.2-py3-none-any.whl.
File metadata
- Download URL: ormar_casbin_adapter-0.0.2-py3-none-any.whl
- Upload date:
- Size: 12.1 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.1.13 CPython/3.10.2 Darwin/21.4.0
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
4511b89540d24a5b32f67683bc59f557e61e9e512f3e6f0846bd63c80a20a2cb
|
|
| MD5 |
ae31849f35a92c7b0eed2322baf0fe45
|
|
| BLAKE2b-256 |
48be8153f9c540538f6a2fadca9d7aa2e583f45c7458e72ee820e258c1f14d72
|