DStore-ACL is a Security Layer for DStore.
Installing
DStore-ACL is available from the PyPi repository.
This means that all you have to do to install DStore-ACL is run the following in a console:
$ pip install dstore-acl
Minimal Example
from dstore import MemoryStore, Model, var, mod
from dstore_acl import ACL, Role, UserRole, AccessDenied
class UserAccount( Model ):
_namespace = "users.account"
_vars = [
var.RowID,
var.String( "name", 32, mods = [ mod.NotNull() ])
]
_acl_rules = dict(
add_own = dict( default = True ),
add_others = dict( default = True ),
read_own = dict( allow = [ "admin", "member" ] ),
read_others = dict( allow = [ "admin" ] ),
update_own = dict( allow = [ "admin", "member" ] ),
delete_own = dict( allow = [ "admin" ] ),
delete_others = dict( allow = [ "admin" ] ),
empty = dict( allow = [ "admin" ])
)
class Car( Model ):
_namespace = "cars.make"
_vars = [
var.RowID,
var.String( "manufacturer", 32, mods = [ mod.NotNull() ] ),
var.String( "make", 32, mods = [ mod.NotNull() ] ),
var.Number( "year", mods = [ mod.NotNull(), mod.Min( 1950 ), mod.Max( 2017 ) ] ),
]
_acl_rules = dict(
add = dict( allow = [ "admin" ]),
read = dict( default = True ),
update = dict( allow = [ "admin" ]),
delete = dict( allow = [ "admin" ]),
empty = dict( allow = [ "admin" ])
)
users = {}
current_user = "admin"
# Create the MemoryStore instance, and add Models to it
store = MemoryStore( [ Car ] )
acl = ACL(
data_store = store,
get_user = get_user,
user_model = UserAccount
)
store.init_app()
store.connect()
store.create_all()
# Create the user accounts
for name in [ "admin", "member" ]:
users[ name ] = UserAccount( name = name ).add()
role = Role.filter( name = name )[0]
UserRole( user_id = users[ name ].id, acl_role_id = role.id ).add()
# Admin can add new cars
Car( manufacturer = "Holden", make = "Commodore", year = 2009 ).add()
# Member cannot add new cars
current_user = "member"
try:
Car( manufacturer = "Holden", make = "Commodore", year = 2010 ).add()
except AccessDenied:
pass
# Destroy all instances and shut down the application
store.destroy_all()
store.disconnect()
store.destroy_app()
def get_user():
return users[ current_user ]
Documentation: ReadTheDocs
Source Code: GitHub
Release files for DStore-ACL 0.1.1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| DStore-ACL-0.1.1.tar.gz | 6.1 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| DStore_ACL-0.1.1-py2.py3-none-any.whl | Python 2, Python 3 | none | any | Details |
Total release size: 17.0 kB
Release files / DStore-ACL-0.1.1.tar.gz
| Download URL | DStore-ACL-0.1.1.tar.gz |
|---|---|
| Size | 6.1 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
150b45e9405be83661e3f4e28a3dd124d4a729ed4c2af577f94ab80622559a2b
|
|
BLAKE2b-256 checksum How to use checksums |
0381422b89141aad187ec42ff7efe16a9199055c8d5d71a261c2520bf5d55773
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
Release files / DStore_ACL-0.1.1-py2.py3-none-any.whl
| Download URL | DStore_ACL-0.1.1-py2.py3-none-any.whl |
|---|---|
| Size | 10.9 kB |
| Tags | Python 2 Python 3 |
|
SHA-256 checksum How to use checksums |
de8f7d3b2993a7cc64597b548f84de930a08d5365579f175bfe32b95fead5e87
|
|
BLAKE2b-256 checksum How to use checksums |
b6564e8121afbca083083619e2042787bc1a37844df580d4de9d7fe9861d0310
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |