Skip to content

Commit

Permalink
Merge pull request #118 from closetool/pg
Browse files Browse the repository at this point in the history
fix: delete dependency of jackc/pgconn
  • Loading branch information
hsluoyz authored Jul 10, 2021
2 parents e966503 + b94bdbb commit b1c6689
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 5 deletions.
3 changes: 1 addition & 2 deletions adapter.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ import (

"github.com/casbin/casbin/v2/model"
"github.com/casbin/casbin/v2/persist"
"github.com/jackc/pgconn"
"gorm.io/driver/mysql"
"gorm.io/driver/postgres"

Expand Down Expand Up @@ -292,7 +291,7 @@ func (a *Adapter) createDatabase() error {
if a.driverName == "postgres" {
if err = db.Exec("CREATE DATABASE " + a.databaseName).Error; err != nil {
// 42P04 is duplicate_database
if err.(*pgconn.PgError).Code == "42P04" {
if strings.Contains(fmt.Sprintf("%s", err), "42P04") {
return nil
}
}
Expand Down
5 changes: 3 additions & 2 deletions adapter_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,15 @@
package gormadapter

import (
"fmt"
"log"
"os"
"strings"
"testing"

"github.com/casbin/casbin/v2"
"github.com/casbin/casbin/v2/util"
_ "github.com/go-sql-driver/mysql"
"github.com/jackc/pgconn"
_ "github.com/lib/pq"
"github.com/stretchr/testify/assert"
"gorm.io/driver/mysql"
Expand Down Expand Up @@ -332,7 +333,7 @@ func TestAdapterWithCustomTable(t *testing.T) {

if err = db.Exec("CREATE DATABASE casbin_custom_table").Error; err != nil {
// 42P04 is duplicate_database
if err.(*pgconn.PgError).Code != "42P04" {
if !strings.Contains(fmt.Sprintf("%s", err), "42P04") {
panic(err)
}
}
Expand Down
14 changes: 14 additions & 0 deletions examples/rbac_with_domains_model.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
[request_definition]
r = sub, dom, obj, act

[policy_definition]
p = sub, dom, obj, act

[role_definition]
g = _, _, _

[policy_effect]
e = some(where (p.eft == allow))

[matchers]
m = g(r.sub, p.sub, r.dom) && r.dom == p.dom && r.obj == p.obj && r.act == p.act
6 changes: 6 additions & 0 deletions examples/rbac_with_domains_policy.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
p, admin, domain1, data1, read
p, admin, domain1, data1, write
p, admin, domain2, data2, read
p, admin, domain2, data2, write
g, alice, admin, domain1
g, bob, admin, domain2
1 change: 0 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ go 1.14
require (
github.com/casbin/casbin/v2 v2.28.3
github.com/go-sql-driver/mysql v1.5.0
github.com/jackc/pgconn v1.8.0
github.com/lib/pq v1.8.0
github.com/stretchr/testify v1.6.1
gorm.io/driver/mysql v1.0.3
Expand Down

0 comments on commit b1c6689

Please sign in to comment.