Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Sign in / Register
Toggle navigation
C
casbin-pg-adapter
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Locked Files
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Packages
Packages
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Abby Cin
casbin-pg-adapter
Commits
38a27228
Commit
38a27228
authored
5 years ago
by
khoipham
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
add documentation
parent
e91692c9
master
v0.1.6
v0.1.5
v0.1.4
v0.1.3
v0.1.1
v0.1.0
No related merge requests found
Changes
4
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
52 additions
and
139 deletions
+52
-139
README.md
README.md
+33
-1
go.mod
go.mod
+0
-1
go.sum
go.sum
+5
-135
main.go
pgexample/main.go
+14
-2
No files found.
README.md
View file @
38a27228
...
...
@@ -15,7 +15,7 @@ import (
"os"
pgadapter
"github.com/pckhoi/casbin-pg-adapter"
"github.com/casbin/casbin"
"github.com/casbin/casbin
/v2
"
)
func
main
()
{
...
...
@@ -23,6 +23,12 @@ func main() {
// The adapter will use the Postgres database named "casbin".
// If it doesn't exist, the adapter will create it automatically.
a
,
_
:=
pgadapter
.
NewAdapter
(
os
.
Getenv
(
"PG_CONN"
))
// Your driver and data source.
// Alternatively, you can construct an adapter instance with *pg.Options:
// a, _ := pgadapter.NewAdapter(&pg.Options{
// Database: "...",
// User: "...",
// Password: "...",
// })
// Or you can use an existing DB "abc" like this:
// The adapter will use the table named "casbin_rule".
...
...
@@ -45,6 +51,32 @@ func main() {
}
```
## Support for FilteredAdapter interface
You can
[
load a subset of policies
](
https://casbin.org/docs/en/policy-subset-loading
)
with this adapter:
```
go
package
main
import
(
"os"
"github.com/casbin/casbin/v2"
pgadapter
"github.com/pckhoi/casbin-pg-adapter"
)
func
main
()
{
a
,
_
:=
pgadapter
.
NewAdapter
(
os
.
Getenv
(
"PG_CONN"
))
e
,
_
:=
casbin
.
NewEnforcer
(
"examples/rbac_model.conf"
,
a
)
e
.
LoadFilteredPolicy
(
&
pgadapter
.
Filter
{
P
:
[]
string
{
""
,
"data1"
},
G
:
[]
string
{
"alice"
},
})
...
}
```
## Run all tests
docker-compose run --rm go
...
...
This diff is collapsed.
Click to expand it.
go.mod
View file @
38a27228
...
...
@@ -8,5 +8,4 @@ require (
github.com/go-pg/pg/v9 v9.1.0
github.com/mmcloughlin/meow v0.0.0-20181112033425-871e50784daf
github.com/stretchr/testify v1.4.0
golang.org/x/crypto v0.0.0-20191206172530-e9b2fee46413
)
This diff is collapsed.
Click to expand it.
go.sum
View file @
38a27228
This diff is collapsed.
Click to expand it.
pgexample/main.go
View file @
38a27228
...
...
@@ -3,7 +3,7 @@ package main
import
(
"os"
"github.com/casbin/casbin"
"github.com/casbin/casbin
/v2
"
pgadapter
"github.com/pckhoi/casbin-pg-adapter"
)
...
...
@@ -12,16 +12,28 @@ func main() {
// The adapter will use the Postgres database named "casbin".
// If it doesn't exist, the adapter will create it automatically.
a
,
_
:=
pgadapter
.
NewAdapter
(
os
.
Getenv
(
"PG_CONN"
))
// Your driver and data source.
// Alternatively, you can construct an adapter instance with *pg.Options:
// a, _ := pgadapter.NewAdapter(&pg.Options{
// Database: "...",
// User: "...",
// Password: "...",
// })
// Or you can use an existing DB "abc" like this:
// The adapter will use the table named "casbin_rule".
// If it doesn't exist, the adapter will create it automatically.
e
:=
casbin
.
NewEnforcer
(
"examples/rbac_model.conf"
,
a
)
e
,
_
:=
casbin
.
NewEnforcer
(
"examples/rbac_model.conf"
,
a
)
// Load the policy from DB.
e
.
LoadPolicy
()
// Alternatively load a subset of policy as demonstrated at https://casbin.org/docs/en/policy-subset-loading
// e.LoadFilteredPolicy(&pgadapter.Filter{
// P: []string{"", "data1"},
// G: []string{"alice"},
// })
// Check the permission.
e
.
Enforce
(
"alice"
,
"data1"
,
"read"
)
...
...
This diff is collapsed.
Click to expand it.
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment