Documentation ¶
Index ¶
- Variables
- func NewAdapter(options ...adapterOption) (persist.Adapter, error)
- func OpAutocreate(autocreate bool) func(*adapter)
- func OpBasicAuthCredentials(user, passwd string) func(*adapter)
- func OpCollectionName(collectionName string) func(*adapter)
- func OpDatabaseName(dbName string) func(*adapter)
- func OpEndpoints(endpoints ...string) func(*adapter)
- func OpFieldMapping(mapping ...string) func(*adapter)
Examples ¶
Constants ¶
This section is empty.
Variables ¶
Functions ¶
func NewAdapter ¶
NewAdapter creates new instance of adapter. If called with no argument default options are applied. Options may reconfigure all or some parameters to different values. See description of each Option for details.
Example ¶
a, err := NewAdapter( OpCollectionName("casbinrules_example"), OpFieldMapping("p", "sub", "obj", "act")) if err != nil { fmt.Printf("Adapter creation error! %s\n", err) return } m, err := model.NewModelFromString(` [request_definition] r = sub, obj, act [policy_definition] p = sub, obj, act [policy_effect] e = some(where (p.eft == allow)) [matchers] m = r.sub == p.sub && r.obj == p.obj && r.act == p.act `) if err != nil { fmt.Printf("Enforcer creation error! %s\n", err) return } e, err := casbin.NewEnforcer(m, a) if err != nil { fmt.Printf("Enforcer creation error! %s\n", err) return } err = e.LoadPolicy() if err != nil { fmt.Printf("Load policy error! %s\n", err) return } sub, obj, act := "adam", "data1", "read" _, _ = e.AddPolicy("adam", "data1", "read") _ = e.SavePolicy() r, err := e.Enforce(sub, obj, act) if err != nil { fmt.Printf("Failed to enforce! %s\n", err) return } if !r { fmt.Printf("%s %s %s: Forbidden!\n", sub, obj, act) } else { fmt.Printf("%s %s %s: Access granted\n", sub, obj, act) }
Output: adam data1 read: Access granted
func OpAutocreate ¶
func OpAutocreate(autocreate bool) func(*adapter)
OpAutocreate enables autocreate mode - both database and collection will be created by adapter if not exist. Should be used with care as each structure is created with driver default options set.
func OpBasicAuthCredentials ¶
func OpBasicAuthCredentials(user, passwd string) func(*adapter)
OpBasicAuthCredentials configures username and password of database used; default is ""
func OpCollectionName ¶
func OpCollectionName(collectionName string) func(*adapter)
OpCollectionName configures name of collection used; default is "casbin_rules"
func OpDatabaseName ¶
func OpDatabaseName(dbName string) func(*adapter)
OpDatabaseName configures name of database used; default is "casbin"
func OpEndpoints ¶
func OpEndpoints(endpoints ...string) func(*adapter)
OpEndpoints configures list of endpoints used to connect to ArangoDB; default is: http://127.0.0.1:8529
func OpFieldMapping ¶
func OpFieldMapping(mapping ...string) func(*adapter)
OpFieldMapping configures mapping to fields used by adapter; default is same used by MongoDB (for eaasy migration): "PType", "V0", "V1", ..., "V6"
Types ¶
This section is empty.