zormadapter

package module
v0.0.0-...-01f3cc0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 12, 2023 License: Apache-2.0 Imports: 5 Imported by: 1

README

casbin-zorm-adapter

Casbin ZORM Adapter is the ZORM Adapter for Casbin. With this library, Casbin can load policy from ZORM supported database or save policy to it.

Based on ZORM Drivers Support, the current supported databases are:

Installation

go get -u github.com/workits/casbin-zorm-adapter

Usage example

dbConfig := &zorm.DataSourceConfig{
    DSN:        "root:password@tcp(127.0.0.1:3306)/casbin?charset=utf8&parseTime=true&loc=Local",
    DriverName: "mysql",
    Dialect:    "mysql",
	// ... more configurations
}
dbDao, err := zorm.NewDBDao(dbConfig)
if err != nil {
	panic(err)
}

a := NewAdapter(dbDao) // you can also use: NewAdapter(dbDao, "your_casbin_rule_table")
e, err := casbin.NewEnforcer("examples/rbac_model.conf", a)
if err != nil {
	panic(err)
}

// ... do your things

Thanks

Special thanks to Casbin Organization, they provide a superb authorization library.

Special thanks to ZORM, a lightweight ORM.

And SQLX Adapter@memwey, which testcase I used.

License

This project is under Apache 2.0 License. See the LICENSE file for the full license text.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Adapter

type Adapter struct {
	// contains filtered or unexported fields
}

func NewAdapter

func NewAdapter(dbDao *zorm.DBDao, tableName ...string) (*Adapter, error)

NewAdapter get a zorm-adapter instance

func NewAdapterWithContext

func NewAdapterWithContext(ctx context.Context, dbDao *zorm.DBDao, tableName ...string) (*Adapter, error)

NewAdapterWithContext get a zorm-adapter instance with context

func (*Adapter) AddPolicy

func (a *Adapter) AddPolicy(sec string, ptype string, rule []string) error

AddPolicy adds a policy rule to database

func (*Adapter) LoadPolicy

func (a *Adapter) LoadPolicy(model model.Model) error

LoadPolicy loads all policies rules from database

func (*Adapter) RemoveFilteredPolicy

func (a *Adapter) RemoveFilteredPolicy(sec string, ptype string, fieldIndex int, fieldValues ...string) error

RemoveFilteredPolicy removes policy rules that match the filter from database

func (*Adapter) RemovePolicy

func (a *Adapter) RemovePolicy(sec string, ptype string, rule []string) error

RemovePolicy removes a policy rule from database

func (*Adapter) SavePolicy

func (a *Adapter) SavePolicy(model model.Model) error

SavePolicy saves all policies rules to database

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL