model

package
v2.87.1 Latest Latest
Warning

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

Go to latest
Published: Apr 7, 2024 License: Apache-2.0 Imports: 14 Imported by: 589

Documentation

Index

Constants

View Source
const DefaultSep = ","

Variables

This section is empty.

Functions

This section is empty.

Types

type Assertion

type Assertion struct {
	Key           string
	Value         string
	Tokens        []string
	ParamsTokens  []string
	Policy        [][]string
	PolicyMap     map[string]int
	RM            rbac.RoleManager
	CondRM        rbac.ConditionalRoleManager
	FieldIndexMap map[string]int
	// contains filtered or unexported fields
}

Assertion represents an expression in a section of the model. For example: r = sub, obj, act.

type AssertionMap

type AssertionMap map[string]*Assertion

AssertionMap is the collection of assertions, can be "r", "p", "g", "e", "m".

type FunctionMap

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

FunctionMap represents the collection of Function.

func LoadFunctionMap

func LoadFunctionMap() FunctionMap

LoadFunctionMap loads an initial function map.

func (*FunctionMap) AddFunction

func (fm *FunctionMap) AddFunction(name string, function govaluate.ExpressionFunction)

AddFunction adds an expression function.

func (*FunctionMap) GetFunctions added in v2.8.0

func (fm *FunctionMap) GetFunctions() map[string]govaluate.ExpressionFunction

GetFunctions return a map with all the functions.

type Model

type Model map[string]AssertionMap

Model represents the whole access control model.

func NewModel added in v2.0.1

func NewModel() Model

NewModel creates an empty model.

func NewModelFromFile added in v2.0.1

func NewModelFromFile(path string) (Model, error)

NewModelFromFile creates a model from a .CONF file.

func NewModelFromString added in v2.0.1

func NewModelFromString(text string) (Model, error)

NewModelFromString creates a model from a string which contains model text.

func (Model) AddDef

func (model Model) AddDef(sec string, key string, value string) bool

AddDef adds an assertion to the model.

func (Model) AddPolicies added in v2.2.2

func (model Model) AddPolicies(sec string, ptype string, rules [][]string)

AddPolicies adds policy rules to the model.

func (Model) AddPoliciesWithAffected added in v2.20.2

func (model Model) AddPoliciesWithAffected(sec string, ptype string, rules [][]string) [][]string

AddPoliciesWithAffected adds policy rules to the model, and returns affected rules.

func (Model) AddPolicy

func (model Model) AddPolicy(sec string, ptype string, rule []string)

AddPolicy adds a policy rule to the model.

func (model Model) BuildConditionalRoleLinks(condRmMap map[string]rbac.ConditionalRoleManager) error

BuildConditionalRoleLinks initializes the roles in RBAC.

func (model Model) BuildIncrementalConditionalRoleLinks(condRmMap map[string]rbac.ConditionalRoleManager, op PolicyOp, sec string, ptype string, rules [][]string) error

BuildIncrementalConditionalRoleLinks provides incremental build the role inheritance relations.

func (model Model) BuildIncrementalRoleLinks(rmMap map[string]rbac.RoleManager, op PolicyOp, sec string, ptype string, rules [][]string) error

BuildIncrementalRoleLinks provides incremental build the role inheritance relations.

func (model Model) BuildRoleLinks(rmMap map[string]rbac.RoleManager) error

BuildRoleLinks initializes the roles in RBAC.

func (Model) ClearPolicy

func (model Model) ClearPolicy()

ClearPolicy clears all current policy.

func (Model) Copy added in v2.31.8

func (model Model) Copy() Model

func (Model) GetFieldIndex added in v2.48.0

func (model Model) GetFieldIndex(ptype string, field string) (int, error)

func (Model) GetFilteredPolicy

func (model Model) GetFilteredPolicy(sec string, ptype string, fieldIndex int, fieldValues ...string) [][]string

GetFilteredPolicy gets rules based on field filters from a policy.

func (Model) GetLogger added in v2.16.0

func (model Model) GetLogger() log.Logger

GetLogger returns the model's logger.

func (Model) GetPolicy

func (model Model) GetPolicy(sec string, ptype string) [][]string

GetPolicy gets all rules in a policy.

func (Model) GetValuesForFieldInPolicy

func (model Model) GetValuesForFieldInPolicy(sec string, ptype string, fieldIndex int) []string

GetValuesForFieldInPolicy gets all values for a field for all rules in a policy, duplicated values are removed.

func (Model) GetValuesForFieldInPolicyAllTypes added in v2.1.0

func (model Model) GetValuesForFieldInPolicyAllTypes(sec string, fieldIndex int) []string

GetValuesForFieldInPolicyAllTypes gets all values for a field for all rules in a policy of all ptypes, duplicated values are removed.

func (Model) HasPolicies added in v2.6.12

func (model Model) HasPolicies(sec string, ptype string, rules [][]string) bool

HasPolicies determines whether a model has any of the specified policies. If one is found we return true.

func (Model) HasPolicy

func (model Model) HasPolicy(sec string, ptype string, rule []string) bool

HasPolicy determines whether a model has the specified policy rule.

func (Model) HasPolicyEx added in v2.49.0

func (model Model) HasPolicyEx(sec string, ptype string, rule []string) (bool, error)

HasPolicyEx determines whether a model has the specified policy rule with error.

func (Model) LoadModel

func (model Model) LoadModel(path string) error

LoadModel loads the model from model CONF file.

func (Model) LoadModelFromText

func (model Model) LoadModelFromText(text string) error

LoadModelFromText loads the model from the text.

func (Model) PrintModel

func (model Model) PrintModel()

PrintModel prints the model to the log.

func (Model) PrintPolicy

func (model Model) PrintPolicy()

PrintPolicy prints the policy to log.

func (Model) RemoveFilteredPolicy

func (model Model) RemoveFilteredPolicy(sec string, ptype string, fieldIndex int, fieldValues ...string) (bool, [][]string)

RemoveFilteredPolicy removes policy rules based on field filters from the model.

func (Model) RemovePolicies added in v2.2.2

func (model Model) RemovePolicies(sec string, ptype string, rules [][]string) bool

RemovePolicies removes policy rules from the model.

func (Model) RemovePoliciesWithAffected added in v2.53.0

func (model Model) RemovePoliciesWithAffected(sec string, ptype string, rules [][]string) [][]string

RemovePoliciesWithAffected removes policy rules from the model, and returns affected rules.

func (Model) RemovePolicy

func (model Model) RemovePolicy(sec string, ptype string, rule []string) bool

RemovePolicy removes a policy rule from the model. Deprecated: Using AddPoliciesWithAffected instead.

func (Model) SetLogger added in v2.16.0

func (model Model) SetLogger(logger log.Logger)

SetLogger sets the model's logger.

func (Model) SortPoliciesByPriority added in v2.24.0

func (model Model) SortPoliciesByPriority() error

func (Model) SortPoliciesBySubjectHierarchy added in v2.33.0

func (model Model) SortPoliciesBySubjectHierarchy() error

func (Model) ToText added in v2.26.1

func (model Model) ToText() string

func (Model) UpdatePolicies added in v2.22.0

func (model Model) UpdatePolicies(sec string, ptype string, oldRules, newRules [][]string) bool

UpdatePolicies updates a policy rule from the model.

func (Model) UpdatePolicy added in v2.14.0

func (model Model) UpdatePolicy(sec string, ptype string, oldRule []string, newRule []string) bool

UpdatePolicy updates a policy rule from the model.

type PolicyOp added in v2.6.0

type PolicyOp int
const (
	PolicyAdd PolicyOp = iota
	PolicyRemove
)

Jump to

Keyboard shortcuts

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