FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
casbin-python-sqlobject-adapter/sqlobject_adapter/adapter.py at master · apache/casbin-python-sqlobject-adapter · GitHub
Uh oh!
There was an error while loading.
Please reload this page
.
apache
/
casbin-python-sqlobject-adapter
Public
Notifications
You must be signed in to change notification settings
Fork
1
Star
0
Code
Issues
0
Pull requests
1
Actions
Projects
Security and quality
0
Insights
Additional navigation options
Code
Issues
Pull requests
Actions
Projects
Security and quality
Insights
Expand file tree
Breadcrumbs
casbin-python-sqlobject-adapter
/
sqlobject_adapter
/
adapter.py
Copy path
More file actions
More file actions
Latest commit
History
History
History
72 lines (56 loc) · 2.27 KB
Breadcrumbs
casbin-python-sqlobject-adapter
/
sqlobject_adapter
/
adapter.py
Copy path
File metadata and controls
72 lines (56 loc) · 2.27 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
from
casbin
import
persist
from
sqlobject
import
SQLObject
,
StringCol
,
sqlhub
,
connectionForURI
class
CasbinRule
(
SQLObject
):
class
sqlmeta
:
table
=
"casbin_rule"
ptype
=
StringCol
(
length
=
255
)
v0
=
StringCol
(
length
=
255
,
default
=
None
)
v1
=
StringCol
(
length
=
255
,
default
=
None
)
v2
=
StringCol
(
length
=
255
,
default
=
None
)
v3
=
StringCol
(
length
=
255
,
default
=
None
)
v4
=
StringCol
(
length
=
255
,
default
=
None
)
v5
=
StringCol
(
length
=
255
,
default
=
None
)
def
__str__
(
self
):
arr
=
[
self
.
ptype
]
for
v
in
(
self
.
v0
,
self
.
v1
,
self
.
v2
,
self
.
v3
,
self
.
v4
,
self
.
v5
):
if
v
is
None
:
break
arr
.
append
(
v
)
return
", "
.
join
(
arr
)
def
__repr__
(
self
):
return
'<CasbinRule {}: "{}">'
.
format
(
self
.
id
,
str
(
self
))
class
Adapter
(
persist
.
Adapter
):
"""the interface for Casbin adapters."""
def
__init__
(
self
,
connection_string
):
self
.
_conhandler
=
connectionForURI
(
connection_string
)
sqlhub
.
processConnection
=
self
.
_conhandler
def
load_policy
(
self
,
model
):
"""loads all policy rules from the storage."""
count
=
CasbinRule
.
select
().
count
()
for
i
in
range
(
1
,
1
+
count
):
line
=
CasbinRule
.
get
(
i
)
persist
.
load_policy_line
(
str
(
line
),
model
)
def
_save_policy_line
(
self
,
ptype
,
rule
):
line
=
CasbinRule
.
selectBy
(
ptype
=
ptype
)
for
i
,
v
in
enumerate
(
rule
):
setattr
(
line
,
"v{}"
.
format
(
i
),
v
)
def
save_policy
(
self
,
model
):
"""saves all policy rules to the storage."""
for
sec
in
[
"p"
,
"g"
]:
if
sec
not
in
model
.
model
.
keys
():
continue
for
ptype
,
ast
in
model
.
model
[
sec
].
items
():
for
rule
in
ast
.
policy
:
self
.
_save_policy_line
(
ptype
,
rule
)
return
True
def
add_policy
(
self
,
sec
,
ptype
,
rule
):
"""adds a policy rule to the storage."""
self
.
_save_policy_line
(
ptype
,
rule
)
def
remove_policy
(
self
,
sec
,
ptype
,
rule
):
"""removes a policy rule from the storage."""
pass
def
remove_filtered_policy
(
self
,
sec
,
ptype
,
field_index
,
*
field_values
):
"""removes policy rules that match the filter from the storage.
This is part of the Auto-Save feature.
"""
pass
Back
|
FazBrowse Home
|
New Git URL