Documentation
¶
Index ¶
- type Adapter
- func (a *Adapter) AddPolicies(sec, ptype string, rules [][]string) error
- func (a *Adapter) AddPoliciesCtx(ctx context.Context, _, ptype string, rules [][]string) error
- func (a *Adapter) AddPolicy(sec, ptype string, rule []string) error
- func (a *Adapter) AddPolicyCtx(ctx context.Context, _, ptype string, rule []string) error
- func (a *Adapter) LoadPolicy(model model.Model) error
- func (a *Adapter) LoadPolicyCtx(ctx context.Context, model model.Model) error
- func (a *Adapter) RemoveFilteredPolicy(sec, ptype string, fieldIndex int, fieldValues ...string) error
- func (a *Adapter) RemoveFilteredPolicyCtx(ctx context.Context, sec, ptype string, fieldIndex int, fieldValues ...string) error
- func (a *Adapter) RemovePolicies(sec, ptype string, rules [][]string) error
- func (a *Adapter) RemovePoliciesCtx(ctx context.Context, _, ptype string, rules [][]string) error
- func (a *Adapter) RemovePolicy(sec, ptype string, rule []string) error
- func (a *Adapter) RemovePolicyCtx(ctx context.Context, _, ptype string, rule []string) error
- func (a *Adapter) SavePolicy(model model.Model) error
- func (a *Adapter) SavePolicyCtx(ctx context.Context, model model.Model) error
- func (a *Adapter) UpdateFilteredPolicies(sec, ptype string, newRules [][]string, fieldIndex int, fieldValues ...string) ([][]string, error)
- func (a *Adapter) UpdateFilteredPoliciesCtx(ctx context.Context, sec, ptype string, newRules [][]string, fieldIndex int, ...) ([][]string, error)
- func (a *Adapter) UpdatePolicies(sec, ptype string, oldRules, newRules [][]string) error
- func (a *Adapter) UpdatePoliciesCtx(ctx context.Context, sec, ptype string, oldRules, newRules [][]string) error
- func (a *Adapter) UpdatePolicy(sec, ptype string, oldRule, newRule []string) error
- func (a *Adapter) UpdatePolicyCtx(ctx context.Context, sec, ptype string, oldRule, newRule []string) error
- type CasbinBunOption
- type CasbinPolicy
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
}
Adapter represents the Bun adapter for policy storage.
func NewAdapter ¶
NewAdapter creates a new Casbin policy adapter using a Bun database connection.
Example:
db := bun.NewDB(sqlDB, pgdialect.New())
adapter, err := NewAdapter(ctx, db, WithAutoCreateTable())
if err != nil {
log.Fatal("Failed to create adapter:", err)
}
enforcer, err := casbin.NewEnforcer("model.conf", adapter)
func (*Adapter) AddPolicies ¶
AddPolicies adds policy rules to the storage. This is part of the Auto-Save feature.
func (*Adapter) AddPoliciesCtx ¶
AddPoliciesCtx adds policy rules to the storage. This is part of the Auto-Save feature.
func (*Adapter) AddPolicy ¶
AddPolicy adds a policy rule to the storage. This is part of the Auto-Save feature.
func (*Adapter) AddPolicyCtx ¶
AddPolicyCtx adds a policy rule to the storage with context. This is part of the Auto-Save feature.
func (*Adapter) LoadPolicy ¶
LoadPolicy loads all policy rules from the storage.
func (*Adapter) LoadPolicyCtx ¶
LoadPolicyCtx loads all policy rules from the storage with context.
func (*Adapter) RemoveFilteredPolicy ¶
func (a *Adapter) RemoveFilteredPolicy( sec, ptype string, fieldIndex int, fieldValues ...string, ) error
RemoveFilteredPolicy removes policy rules that match the filter from the storage. This is part of the Auto-Save feature. This API is explained in the link below: https://casbin.org/docs/management-api/#removefilteredpolicy
func (*Adapter) RemoveFilteredPolicyCtx ¶
func (a *Adapter) RemoveFilteredPolicyCtx( ctx context.Context, sec, ptype string, fieldIndex int, fieldValues ...string, ) error
RemoveFilteredPolicyCtx removes policy rules that match the filter from the storage with context. This is part of the Auto-Save feature.
func (*Adapter) RemovePolicies ¶
RemovePolicies removes policy rules from the storage. This is part of the Auto-Save feature.
func (*Adapter) RemovePoliciesCtx ¶
RemovePoliciesCtx removes policy rules from the storage. This is part of the Auto-Save feature.
func (*Adapter) RemovePolicy ¶
RemovePolicy removes a policy rule from the storage. This is part of the Auto-Save feature.
func (*Adapter) RemovePolicyCtx ¶
RemovePolicyCtx removes a policy rule from the storage with context. This is part of the Auto-Save feature.
func (*Adapter) SavePolicy ¶
SavePolicy saves all policy rules to the storage.
func (*Adapter) SavePolicyCtx ¶
SavePolicyCtx saves all policy rules to the storage with context.
func (*Adapter) UpdateFilteredPolicies ¶
func (a *Adapter) UpdateFilteredPolicies( sec, ptype string, newRules [][]string, fieldIndex int, fieldValues ...string, ) ([][]string, error)
UpdateFilteredPolicies deletes old rules and adds new rules.
func (*Adapter) UpdateFilteredPoliciesCtx ¶
func (a *Adapter) UpdateFilteredPoliciesCtx( ctx context.Context, sec, ptype string, newRules [][]string, fieldIndex int, fieldValues ...string, ) ([][]string, error)
UpdateFilteredPoliciesCtx deletes old rules and adds new rules.
func (*Adapter) UpdatePolicies ¶
UpdatePolicies updates some policy rules to storage, like db, redis.
func (*Adapter) UpdatePoliciesCtx ¶
func (a *Adapter) UpdatePoliciesCtx( ctx context.Context, sec, ptype string, oldRules, newRules [][]string, ) error
UpdatePoliciesCtx updates some policy rules to storage, like db, redis.
func (*Adapter) UpdatePolicy ¶
UpdatePolicy updates a policy rule from storage. This is part of the Auto-Save feature.
type CasbinBunOption ¶
type CasbinBunOption func(*Adapter)
CasbinBunOption defines a functional option type for configuring a BunAdapter. These options are passed to NewAdapter to customize the adapter's behavior.
func DisableAutoCreateTable ¶
func DisableAutoCreateTable() CasbinBunOption
DisableAutoCreateTable disables automatic creation of the Casbin policy storage table during adapter initialization. If used, the policy table must already exist in the database.
Example:
adapter, err := NewAdapter(db, DisableAutoCreateTable())
type CasbinPolicy ¶
type CasbinPolicy struct {
bun.BaseModel `bun:"casbin_policies,alias:cp"`
ID int64 `bun:"id,pk,autoincrement"`
PType string `bun:"ptype,type:varchar(100),notnull"`
V0 string `bun:"v0,type:varchar(100)"`
V1 string `bun:"v1,type:varchar(100)"`
V2 string `bun:"v2,type:varchar(100)"`
V3 string `bun:"v3,type:varchar(100)"`
V4 string `bun:"v4,type:varchar(100)"`
V5 string `bun:"v5,type:varchar(100)"`
}
CasbinPolicy defines the storage format following the definition below: https://casbin.org/docs/policy-storage#database-storage-format