core

package
v0.3.0 Latest Latest
Warning

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

Go to latest
Published: Apr 28, 2023 License: MIT Imports: 10 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrNotFoundMatcher                   = errors.New("not found specified matcher")
	ErrInvalidAssertionSchema            = errors.New("invalid assertion schema")
	ErrInvalidAssertion                  = errors.New("invalid assertion")
	ErrInvalidMatchersConfig             = errors.New("invalid matchers config")
	ErrInvalidRoleTypeDefinition         = errors.New("invalid role type definition")
	ErrRoleMappingMismatchRoleType       = errors.New("role mapping mismatch role type")
	ErrUnknownAssertionType              = errors.New("unknown assertion type")
	ErrNotFoundSpecifiedRoleMappingGroup = errors.New("not found role mapping group")
	ErrUnexpectedEvalResult              = errors.New("expected eval result")
)

Functions

func RoleDomainMatchEqual

func RoleDomainMatchEqual(request, mapping string) bool

Types

type Assertion

type Assertion map[string]string

Assertion is an assertion. May be a request or a policy.

type AssertionSchema

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

AssertionSchema is assertion schema definition.

Define the fields that the assertion has.

func NewAssertionSchema

func NewAssertionSchema(line string) (schema AssertionSchema, err error)

NewAssertionSchema constructes an assertion schema from a casbin definition line.

func (AssertionSchema) CreateAssertion

func (s AssertionSchema) CreateAssertion(vals []string) (assertion Assertion, err error)

CreateAssertion creates an assertion.

CreateAssertion would verify if the input vals is matched with the schema.

func (AssertionSchema) CreateAssertions added in v0.2.0

func (s AssertionSchema) CreateAssertions(policies [][]string) (assertions Policies, err error)

CreateAssertions creates a list of assertion from raw policies.

func (*AssertionSchema) Has

func (s *AssertionSchema) Has(key string) bool

Has returns if the assertion schema has a field with the specified key.

type Effector

type Effector interface {
	Execute(eval PolicyEvalFunc, policies Policies) (allow bool, err error)
}

Effector interface.

type ExtensionFunc

type ExtensionFunc struct {
	Decl     *exprpb.Decl
	Overload *functions.Overload
}

type LoadIterator

type LoadIterator interface {
	// Next returns next policy or role mapping.
	//
	// The `key` may be `p` or a role mapping key like `g`.
	// If `ok` is false. There is no more data or an error.
	Next() (ok bool, key string, vals []string)

	// Error returns the error that has occurred in `Next()` calling.
	Error() (err error)
}

The iterator interface for loading policies and role mappings.

type Matcher

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

func (*Matcher) Program

func (m *Matcher) Program(
	vars map[string]interface{},
	roleMappings RoleMappings,
	moreGraphs map[string][]*graph.Graph,
) (prg cel.Program, err error)

type Matchers

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

func (Matchers) Get

func (m Matchers) Get(key string) (matcher Matcher, err error)

type MatchersConfig

type MatchersConfig struct {
	Roles          RolesSchema
	Define         map[string]string
	ExtensionFuncs []ExtensionFunc
}

func (MatchersConfig) New

func (c MatchersConfig) New() (m Matchers, err error)

type Model

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

Model is casbin model schema.

func NewModel

func NewModel(
	policy, request AssertionSchema,
	roles RolesSchema,
	effector Effector,
	matchers Matchers,
) (m *Model)

NewModel constructes a new Model.

func (*Model) Effector

func (m *Model) Effector() Effector

Effector returns the effector.

func (*Model) Load

func (m *Model) Load(itr LoadIterator) (
	policies Policies, roleMappings RoleMappings, err error,
)

Load load and returns the policies and role mappings by an assertion iterator.

Load would check the loaded data if it is matched with the model.

func (*Model) Matchers

func (m *Model) Matchers() Matchers

Request returns the matcherx.

func (*Model) Policy

func (m *Model) Policy() AssertionSchema

Policy returns the policy assertion schema.

func (*Model) Request

func (m *Model) Request() AssertionSchema

Request returns the request assertion schema.

type Policies

type Policies []Assertion

type PolicyEvalFunc

type PolicyEvalFunc func(policy Assertion) (allow bool, err error)

type RoleDomainMatchFunc

type RoleDomainMatchFunc func(request string, mapping string) (matched bool)

type RoleMapping

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

func NewRoleMapping

func NewRoleMapping(key string, domainMatch RoleDomainMatchFunc) *RoleMapping

func (*RoleMapping) GenerateGFunc

func (rg *RoleMapping) GenerateGFunc(moreGraphs ...*graph.Graph) (overload *functions.Overload)

func (*RoleMapping) Key

func (rg *RoleMapping) Key() string

type RoleMappings

type RoleMappings map[string]*RoleMapping

func (RoleMappings) GenerateGFuncs

func (rg RoleMappings) GenerateGFuncs(
	moreGraphs map[string][]*graph.Graph,
) (funcs []*functions.Overload)

type RoleSchema

type RoleSchema struct {
	Type            RoleType
	DomainMatchFunc RoleDomainMatchFunc
}

type RoleType

type RoleType int

Role mapping type.

const (
	// Invalid role mapping type.
	RoleTypeInvalid RoleType = iota
	// Role mapping without domain.
	RoleTypeWithoutDomain
	// Role mapping with domain.
	RoleTypeWithDomain
)

func RoleTypeFromLine

func RoleTypeFromLine(line string) (RoleType, error)

Get the role type from the definition in official casbin format.

* "_, _" is without domain. * "_, _, _" is with domain.

type RolesSchema

type RolesSchema map[string]RoleSchema

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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