Skip to main content

ormar casbin adapter

Project description

ormar Adapter for PyCasbin

Statistics

GitHub Workflow Status Codecov Code Climate maintainability Dependabot

GitHub

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

PyPI

Version PyPI - Wheel Python Versions PyPI - Format PyPI - Status PyPI PyPI - Downloads Download 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.1.tar.gz (8.6 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.1-py3-none-any.whl (12.2 kB view details)

Uploaded Python 3

File details

Details for the file ormar-casbin-adapter-0.0.1.tar.gz.

File metadata

  • Download URL: ormar-casbin-adapter-0.0.1.tar.gz
  • Upload date:
  • Size: 8.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.1.13 CPython/3.10.2 Darwin/21.3.0

File hashes

Hashes for ormar-casbin-adapter-0.0.1.tar.gz
Algorithm Hash digest
SHA256 09c5d6581ea121f70349c50e1eeced7b5b55ecf4cd738346c44514514782f2f9
MD5 c03f52c0869132995fe0d94240a20689
BLAKE2b-256 9c77f29c24bb992385877f2554e44840069e9d116ff0a08775752f6f3a476eb3

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for ormar_casbin_adapter-0.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 d6cbaaed6ce837d75fcb8dd39da136b54db41b3fbd48cb3ec96185020f1fb3e9
MD5 bf9143c088b1e515cd2fd9dc12b4d73f
BLAKE2b-256 9f6fe5fc8056034a0a6f9f2fb251eff92cdee7276496091e7f35b89e36746a4f

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