Skip to main content

ormar casbin adapter

Project description

ormar Adapter for PyCasbin

Repo

GitHub Workflow Status Codecov Code Climate maintainability Dependabot

GitHub

GitHub tag (latest SemVer) GitHub tag (latest by date) GitHub last commit

PyPI

PyPI - Version PyPI - Python Versions PyPI - Python Wheel PyPI - Format PyPI - Status PyPI - Downloads PyPI - License

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


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

ormar-casbin-adapter-0.0.2.tar.gz (8.5 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

ormar_casbin_adapter-0.0.2-py3-none-any.whl (12.1 kB view details)

Uploaded Python 3

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

Hashes for ormar-casbin-adapter-0.0.2.tar.gz
Algorithm Hash digest
SHA256 18e49ceb2f0546cf80a21b0b01648c6edd50d9de76032e0ae90676a71796ac3f
MD5 b653bf89435ce7833bc08fbca611c1e7
BLAKE2b-256 54f8ed934a14c9472fcd14dbeef0bd381dd48592807f99ba7a0b3bc671dd5f10

See more details on using hashes here.

File details

Details for the file ormar_casbin_adapter-0.0.2-py3-none-any.whl.

File metadata

File hashes

Hashes for ormar_casbin_adapter-0.0.2-py3-none-any.whl
Algorithm Hash digest
SHA256 4511b89540d24a5b32f67683bc59f557e61e9e512f3e6f0846bd63c80a20a2cb
MD5 ae31849f35a92c7b0eed2322baf0fe45
BLAKE2b-256 48be8153f9c540538f6a2fadca9d7aa2e583f45c7458e72ee820e258c1f14d72

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page