Show last authors
1 = Introduction =
2
3 Provides simple access control based on key+principals (all strings).
4
5 = Examples =
6
7 By role:
8
9 {{code language="py" linenumbers="true"}}
10 import kbac
11
12 ac = kbac.KBAC()
13 ac.add("viewer", ["bob", "joe"])
14 ac.add("manager", ["lucy", "rick"])
15
16 print(ac.is_allowed(["viewer"], ["lucy"]))
17 print(ac.is_allowed(["manager"], ["lucy"]))
18 print(ac.is_allowed(["viewer", "manager"], ["rick"]))
19 {{/code}}
20
21 Notes:
22
23 * add individual settings using KBAC.add()
24 * test if lucy is a viewer
25 * test if lucy is a manager
26 * test if rick is a viewer or manager
27
28 By service:
29
30 {{code language="py" linenumbers="true"}}
31 import kbac
32
33 acdict = {
34 "list": "dudley, al, jeffrey",
35 "create": "dudley, jill",
36 "delete": "dudley",
37 }
38
39 ac = kbac.KBAC()
40 ac.load(acdict.items())
41
42 principals = ["dudley"]
43 print "principals (%s)" % (principals,)
44 for key in acdict:
45 print("key (%s) allowed (%s)" % (key, ac.is_allowed([key], principals)))
46 {{/code}}
47
48 Notes:
49
50 * load KBAC object from dictionary
51 * test which keys/services dudley is allowed
52
53 Display settings:
54
55 {{code language="py" linenumbers="true"}}
56 import kbac
57
58 acdict = {
59 "list": "dudley, al",
60 "create": "dudley, brittany",
61 "delete": "dudley",
62 }
63
64 ac = kbac.KBAC()
65 ac.load(acdict.items())
66
67 for key in ac.keys():
68 print("key (%s) principals (%s)\n" % (key, sorted(ac.principals(key))))
69 {{/code}}
70
71 Notes:
72
73 * extract settings using KBAC.keys() and KBAC.principals()

Contact

About

Requirements:

Python

License:

BSD-3

Repository:

https://bitbucket.org/johnmdev/kbac

Email:

expldotinfo@gmail.com