Casbin role watcher to be used for monitoring updates to policies for PyCasbin
Project description
postgresql-watcher
Casbin watcher based on PostgreSQL for monitoring updates to casbin policies.
Installation
pip install casbin-postgresql-watcher
Basic Usage Example
from flask_authz import CasbinEnforcer
from postgresql_watcher import PostgresqlWatcher
from flask import Flask
from casbin.persist.adapters import FileAdapter
casbin_enforcer = CasbinEnforcer(app, adapter)
watcher = PostgresqlWatcher(host=HOST, port=PORT, user=USER, password=PASSWORD, dbname=DBNAME)
watcher.set_update_callback(casbin_enforcer.load_policy)
casbin_enforcer.set_watcher(watcher)
# Call should_reload before every call of enforce to make sure
# the policy is update to date
watcher.should_reload()
if casbin_enforcer.enforce("alice", "data1", "read"):
# permit alice to read data1
pass
else:
# deny the request, show an error
pass
alternatively, if you need more control
from flask_authz import CasbinEnforcer
from postgresql_watcher import PostgresqlWatcher
from flask import Flask
from casbin.persist.adapters import FileAdapter
casbin_enforcer = CasbinEnforcer(app, adapter)
watcher = PostgresqlWatcher(host=HOST, port=PORT, user=USER, password=PASSWORD, dbname=DBNAME)
casbin_enforcer.set_watcher(watcher)
# Call should_reload before every call of enforce to make sure
# the policy is update to date
if watcher.should_reload():
casbin_enforcer.load_policy()
if casbin_enforcer.enforce("alice", "data1", "read"):
# permit alice to read data1
pass
else:
# deny the request, show an error
pass
Basic Usage Example With SSL Enabled
See PostgresQL documentation for full details of SSL parameters.
...
watcher = PostgresqlWatcher(host=HOST, port=PORT, user=USER, password=PASSWORD, dbname=DBNAME, sslmode="verify_full", sslcert=SSLCERT, sslrootcert=SSLROOTCERT, sslkey=SSLKEY)
...
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
Close
Hashes for casbin_postgresql_watcher-1.1.1.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | 491bf362c5311da80ce701806e9473b1d50b6e701150b494ff15fcf7db4d15f2 |
|
MD5 | b540854c9f6dee9d9aa49659051f9fb9 |
|
BLAKE2b-256 | ce37402bb8f698608a0309fe7b26dba3f4b9d562707e626b886e70f070070c61 |
Close
Hashes for casbin_postgresql_watcher-1.1.1-py2.py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | e483b1d635d92966e52cb78893731ccd11c51aaa8426f077fc65ac2ec0a94397 |
|
MD5 | 424d4162acfd468af6b3fb6298c50079 |
|
BLAKE2b-256 | 2ef30890752f17457adbb81cafbbeb89f2cb7ac614ae95081c43944a0a8395c3 |