flask-casbin-redis-watcher
Project description
Flask-Casbin-Redis-Watcher
Casbin role watcher to be used for monitoring updates to casbin policies
Installation
pip install flask-casbin-redis-watcher
Basic Usage
from flask_casbin import CasbinEnforcer
from flask_casbin_redis_watcher import RedisWatcher
casbin_enforcer = CasbinEnforcer(app, adapter)
watcher=RedisWatcher(redis_hostname, redis_port)
watcher.set_update_callback(casbin_enforcer.e.load_policy)
casbin_enforcer.set_watcher(watcher)
Using alongside UWSGI
This redis-watcher module starts separate processes which subscribe to a redis channel, and listens for updates to the casbin policy on that channel. When running within WSGI contexts (like uwsgi) you may want to start these processes as a postfork action. As is depicted below:
try:
from uwsgidecorators import postfork
print("Running in uwsgi context")
except ModuleNotFoundError:
print("Not running in uwsgi context")
postfork = None
if postfork:
@postfork
def load_watcher():
global casbin_enforcer
watcher = RedisWatcher(redis_info.hostname, redis_info.port)
watcher.set_update_callback(casbin_enforcer.e.load_policy)
casbin_enforcer.set_watcher(watcher)
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 Distributions
No source distribution files available for this release.See tutorial on generating distribution archives.
Built Distribution
File details
Details for the file flask_casbin_redis_watcher-0.1.0-py3-none-any.whl
.
File metadata
- Download URL: flask_casbin_redis_watcher-0.1.0-py3-none-any.whl
- Upload date:
- Size: 3.9 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.1.1 pkginfo/1.4.2 requests/2.23.0 setuptools/45.2.0 requests-toolbelt/0.9.1 tqdm/4.26.0 CPython/3.7.2
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | c4decec2431c91459f9225dbbf4217dbc63ee855882575eca8c694efbe1c2a2c |
|
MD5 | 60a76261ffeec0f0ae82e3936688a479 |
|
BLAKE2b-256 | 263ffc801ad656bb83972a802f725400dc999e01108973ba7993093cbd358cdf |