Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
View Source
var ( ErrPermissionDenied = errors.New("permission denied") ErrPolicyNotFound = errors.New("not found") )
Functions ¶
This section is empty.
Types ¶
type CheckOption ¶
type CheckOption func(*CheckOptions)
func WithCheckFuncMatcher ¶
func WithCheckFuncMatcher(matcher FuncMatcher) CheckOption
func WithCheckMatcher ¶
func WithCheckMatcher(matcher Matcher) CheckOption
type CheckOptions ¶
type CheckOptions struct {
// contains filtered or unexported fields
}
type FuncMatcher ¶
type FuncMatcher func(ctx context.Context, request *Request, policyStorage PolicyStorageFinder) ([]*Policy, error)
func (FuncMatcher) Match ¶
func (f FuncMatcher) Match(ctx context.Context, request *Request, policyStorage PolicyStorageFinder) ([]*Policy, error)
type Matcher ¶
type Matcher interface {
Match(ctx context.Context, request *Request, policyStorage PolicyStorageFinder) ([]*Policy, error)
}
Matcher 策略储存匹配器, 从策略存储中匹配出符合条件的策略
func NewEqualMatcher ¶
func NewEqualMatcher() Matcher
func NewOrMatcher ¶
type Option ¶
type Option func(*Options)
func WithFuncMatcher ¶
func WithFuncMatcher(matcher FuncMatcher) Option
func WithMatcher ¶
type Permission ¶
type Permission struct {
// contains filtered or unexported fields
}
func NewPermission ¶
func NewPermission(policyStorage PolicyStorage, opts ...Option) *Permission
func (*Permission) Check ¶
func (p *Permission) Check(ctx context.Context, request *Request, opts ...CheckOption) error
Check 检查权限
func (*Permission) QueryPolicies ¶
func (p *Permission) QueryPolicies(ctx context.Context, request *Request, opts ...CheckOption) ([]*Policy, error)
QueryPolicies 查询出符合条件的策略
type Policy ¶
type Policy struct {
ID string // 策略id
Subject string // 访问者
Resource string // 资源信息
Actions []string // 策略的操作类型
Effect PolicyEffect // 结果
Priority int // 优先级
}
Policy 策略
type PolicyEffect ¶
type PolicyEffect string
const ( Allow PolicyEffect = "allow" Deny PolicyEffect = "deny" )
type PolicyStorage ¶
type PolicyStorage interface {
PolicyStorageFinder
AddPolicy(ctx context.Context, policy *Policy) error
RemovePolicy(ctx context.Context, policy *Policy) error
UpdatePolicy(ctx context.Context, policy *Policy) error
}
PolicyStorage 策略存储
Click to show internal directories.
Click to hide internal directories.