model

package
v0.1.1 Latest Latest
Warning

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

Go to latest
Published: Jan 6, 2023 License: Apache-2.0 Imports: 13 Imported by: 0

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
	Policy    [][]string
	PolicyMap *sync.Map
	RM        rbac.RoleManager
	// 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 struct {
	sync.Map
}

AssertionMap is the collection of assertions, can be "r", "p", "g", "e", "m". type AssertionMap map[string]*Assertion

func (*AssertionMap) GetKey

func (as *AssertionMap) GetKey(ptype string) (*Assertion, bool)

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

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

GetFunctions return a map with all the functions

type Model

type Model struct {
	sync.Map
}

Model represents the whole access control model. type Model map[string]AssertionMap

func NewModel

func NewModel() *Model

NewModel creates an empty model.

func NewModelFromFile

func NewModelFromFile(path string) (*Model, error)

NewModelFromFile creates a model from a .CONF file.

func NewModelFromString

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

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

AddPolicies adds policy rules to the model.

func (*Model) AddPoliciesWithAffected

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

AddPoliciesWithAffected adds policy rules to the model, and returns effected 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) 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) (err error)

BuildRoleLinks initializes the roles in RBAC.

func (*Model) ClearPolicy

func (model *Model) ClearPolicy()

ClearPolicy clears all current policy.

func (*Model) Copy

func (model *Model) Copy() *Model

func (*Model) GetAstBySecPType

func (model *Model) GetAstBySecPType(sec, ptype string) (*Assertion, bool)

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) GetKey

func (model *Model) GetKey(sec string) (*AssertionMap, bool)

func (*Model) GetLogger

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

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

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) 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

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

RemovePolicies removes policy rules from the model.

func (*Model) RemovePoliciesWithEffected

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

RemovePoliciesWithEffected removes policy rules from the model, and returns effected 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

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

SetLogger sets the model's logger.

func (*Model) SortPoliciesByPriority

func (model *Model) SortPoliciesByPriority() error

func (*Model) SortPoliciesBySubjectHierarchy

func (model *Model) SortPoliciesBySubjectHierarchy() (err error)

func (*Model) ToText

func (model *Model) ToText() string

func (*Model) UpdatePolicies

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

UpdatePolicies updates a policy rule from the model.

func (*Model) UpdatePolicy

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

UpdatePolicy updates a policy rule from the model.

type PolicyOp

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