Skip to content

Commit

Permalink
feat: add enforcer EnableAcceptJsonRequest feature, upgrade casbin to…
Browse files Browse the repository at this point in the history
… v2.100.0 (#29)

Upgraded go and casbin module versions then added enforcer EnableAcceptJsonRequest feature

Changes:
- Upgraded go version to 1.19
- Upgraded the version of the "Casbin" module to 2.100.0
- Added EnableAcceptJsonRequest field to the config structure to make a new enforcer from this config.
- Added EnableAcceptJsonRequest field to NewEnforcer test case
  • Loading branch information
ali-shokoohi authored Oct 5, 2024
1 parent 2f9c0f9 commit 4b320ca
Show file tree
Hide file tree
Showing 4 changed files with 409 additions and 122 deletions.
14 changes: 8 additions & 6 deletions client/enforce.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,11 @@ import (

// Config contains data needed to create an enforcer.
type Config struct {
DriverName string
ConnectString string
ModelText string
DbSpecified bool
DriverName string
ConnectString string
ModelText string
DbSpecified bool
EnableAcceptJsonRequest bool
}

// Enforcer is the main interface for authorization enforcement and policy management.
Expand Down Expand Up @@ -61,8 +62,9 @@ func (c *Client) NewEnforcer(ctx context.Context, config Config) (*Enforcer, err
}

e, err := c.remoteClient.NewEnforcer(ctx, &pb.NewEnforcerRequest{
ModelText: config.ModelText,
AdapterHandle: adapterHandler,
ModelText: config.ModelText,
AdapterHandle: adapterHandler,
EnableAcceptJsonRequest: config.EnableAcceptJsonRequest,
})
if err != nil {
return enforcer, err
Expand Down
2 changes: 1 addition & 1 deletion client/enforce_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ func testNewEnforcer(t *testing.T) {

ctx, cancel = context.WithTimeout(context.Background(), time.Second)
defer cancel()
e, err = cc.NewEnforcer(ctx, Config{ModelText: ""})
e, err = cc.NewEnforcer(ctx, Config{ModelText: "", EnableAcceptJsonRequest: true})
if err != nil {
t.Fatalf("NewEnforcer() error: %v", err)
}
Expand Down
60 changes: 55 additions & 5 deletions go.mod
Original file line number Diff line number Diff line change
@@ -1,10 +1,60 @@
module github.com/casbin/casbin-go-client

go 1.15
go 1.19

require (
github.com/casbin/casbin-server v0.0.0-20210215093047-8fcf00d431b3
github.com/casbin/casbin/v2 v2.0.2
github.com/kr/pretty v0.2.1 // indirect
google.golang.org/grpc v1.35.0
github.com/casbin/casbin-server v1.17.0
github.com/casbin/casbin/v2 v2.100.0
google.golang.org/grpc v1.42.0
)

require (
github.com/bmatcuk/doublestar/v4 v4.6.1 // indirect
github.com/casbin/gorm-adapter/v3 v3.14.0 // indirect
github.com/casbin/govaluate v1.2.0 // indirect
github.com/casbin/mongodb-adapter/v3 v3.7.0 // indirect
github.com/glebarez/go-sqlite v1.19.1 // indirect
github.com/glebarez/sqlite v1.5.0 // indirect
github.com/go-sql-driver/mysql v1.6.0 // indirect
github.com/golang-sql/civil v0.0.0-20220223132316-b832511892a9 // indirect
github.com/golang-sql/sqlexp v0.1.0 // indirect
github.com/golang/protobuf v1.5.0 // indirect
github.com/golang/snappy v0.0.1 // indirect
github.com/google/uuid v1.3.0 // indirect
github.com/jackc/chunkreader/v2 v2.0.1 // indirect
github.com/jackc/pgconn v1.13.0 // indirect
github.com/jackc/pgio v1.0.0 // indirect
github.com/jackc/pgpassfile v1.0.0 // indirect
github.com/jackc/pgproto3/v2 v2.3.1 // indirect
github.com/jackc/pgservicefile v0.0.0-20200714003250-2b9c44734f2b // indirect
github.com/jackc/pgtype v1.12.0 // indirect
github.com/jackc/pgx/v4 v4.17.2 // indirect
github.com/jinzhu/inflection v1.0.0 // indirect
github.com/jinzhu/now v1.1.5 // indirect
github.com/klauspost/compress v1.13.6 // indirect
github.com/mattn/go-isatty v0.0.16 // indirect
github.com/microsoft/go-mssqldb v0.17.0 // indirect
github.com/montanaflynn/stats v0.6.6 // indirect
github.com/remyoudompheng/bigfft v0.0.0-20200410134404-eec4a21b6bb0 // indirect
github.com/xdg-go/pbkdf2 v1.0.0 // indirect
github.com/xdg-go/scram v1.1.2 // indirect
github.com/xdg-go/stringprep v1.0.4 // indirect
github.com/youmark/pkcs8 v0.0.0-20181117223130-1be2e3e5546d // indirect
go.mongodb.org/mongo-driver v1.12.0 // indirect
golang.org/x/crypto v0.0.0-20221005025214-4161e89ecf1b // indirect
golang.org/x/net v0.0.0-20220722155237-a158d28d115b // indirect
golang.org/x/sync v0.0.0-20220722155255-886fb9371eb4 // indirect
golang.org/x/sys v0.0.0-20220811171246-fbc7d0a398ab // indirect
golang.org/x/text v0.7.0 // indirect
google.golang.org/genproto v0.0.0-20200526211855-cb27e3aa2013 // indirect
google.golang.org/protobuf v1.27.1 // indirect
gorm.io/driver/mysql v1.4.1 // indirect
gorm.io/driver/postgres v1.4.4 // indirect
gorm.io/driver/sqlserver v1.4.1 // indirect
gorm.io/gorm v1.24.0 // indirect
gorm.io/plugin/dbresolver v1.3.0 // indirect
modernc.org/libc v1.19.0 // indirect
modernc.org/mathutil v1.5.0 // indirect
modernc.org/memory v1.4.0 // indirect
modernc.org/sqlite v1.19.1 // indirect
)
Loading

0 comments on commit 4b320ca

Please sign in to comment.