Documentation ¶
Index ¶
- Constants
- func Interceptor(store Vanguard, pf PermissionsFunc, opt *InterceptorOptions) grpc.UnaryServerInterceptor
- func WithLevelMatcher(m LevelMatcher) option
- func WithResourceMatcher(m ResourceMatcher) option
- func WithRoles(rl []Level) option
- type BitMaskLevelMatcher
- type ErrorLogger
- type ExactLevelMatcher
- type ExactResourceMatcher
- type GlobResourceMatcher
- type InterceptorOptions
- type Level
- type LevelMatcher
- type MultiError
- type OrderedLevelMatcher
- type Permission
- type PermissionsFunc
- type PrefixResourceMatcher
- type RegexResourceMatcher
- type ResourceMatcher
- type Vanguard
Constants ¶
const ( LevelOwner = 1 LevelManager = 5 LevelEditor = 10 LevelViewer = 15 )
Variables ¶
This section is empty.
Functions ¶
func Interceptor ¶
func Interceptor(store Vanguard, pf PermissionsFunc, opt *InterceptorOptions) grpc.UnaryServerInterceptor
Interceptor is grpc UnaryServerInterceptor that asserts that a caller has permission to access the endpoints. PermissionsFunc is used to retreive the permissions of the current user
func WithLevelMatcher ¶
func WithLevelMatcher(m LevelMatcher) option
WithLevelMatcher can be used to replace the level matching strategies
List of available options: Exact, Ordered, and BitMask
func WithResourceMatcher ¶
func WithResourceMatcher(m ResourceMatcher) option
WithResourceMatcher can be used to replace the resource matching strategies
List of available options: Exact, Prefix, Regex, and Glob
Types ¶
type BitMaskLevelMatcher ¶
type BitMaskLevelMatcher struct { }
BitMaskLevelMatcher matches by doing bitwise AND and checking if the user has all the needed bits set.
func (*BitMaskLevelMatcher) MatchLevel ¶
func (*BitMaskLevelMatcher) MatchLevel(has, needs int) bool
type ErrorLogger ¶
type ErrorLogger func(v ...interface{})
type ExactLevelMatcher ¶
type ExactLevelMatcher struct { }
ExactLevelMatcher matches if both the levels are exactly equal
func (*ExactLevelMatcher) MatchLevel ¶
func (*ExactLevelMatcher) MatchLevel(has, needs int) bool
type ExactResourceMatcher ¶
type ExactResourceMatcher struct{}
ExactResourceMatcher matches if both the pattern and resource are exactly equal
func (*ExactResourceMatcher) MatchResource ¶
func (*ExactResourceMatcher) MatchResource(pattern, resource string) (bool, error)
type GlobResourceMatcher ¶
type GlobResourceMatcher struct { }
RegexResourceMatcher matches if the resource satisfies the pattern (glob) It uses srikrsna/glob package to compile and match globs. It is documented as follows,
Match reports whether resource matches the shell pattern. The pattern syntax is:
pattern: { term } term: '*' matches any sequence of non-/ characters '**' matches any sequence of characters '?' matches any single non-/ character '[' [ '!' ] { character-range } ']' character class (must be non-empty) c matches character c (c != '*', '?', '\\', '[') '\\' c matches character c character-range: c matches character c (c != '\\', '-', ']') '\\' c matches character c lo '-' hi matches character c for lo <= c <= hi
Match requires pattern to match all of resource, not just a substring. The only possible returned error is ErrBadPattern, when pattern is malformed.
func (*GlobResourceMatcher) MatchResource ¶
func (rm *GlobResourceMatcher) MatchResource(pattern, resource string) (bool, error)
type InterceptorOptions ¶
type InterceptorOptions struct { Skip bool ErrorLogger ErrorLogger }
type Level ¶
Level defines a permission level. Name can be used as is in the assert expressions. They are substituted with their corresponding Value
func DefaultLevels ¶
func DefaultLevels() []Level
DefaultLevels are only a placeholder, They can be used in a production system. But typically they are overridden.
Look at `WithRoles` to override them
type LevelMatcher ¶
ResourceMatcher is used to match permission levels.
There are the following strategies already implemented, * Exact * Ordered * BitMask
type MultiError ¶
type MultiError []error
func (MultiError) Error ¶
func (me MultiError) Error() string
type OrderedLevelMatcher ¶
type OrderedLevelMatcher struct {
Asc bool
}
OrderedLevelMatcher matches if comparision succeeds based on the Asc parameter.
If Asc is false (default), the user needs to have equal or less than the level that is required for an operation i.e. levels behave like ranks If Asc is true, the user needs to have equal or greater than the level that is required for an operation
Defaults to Asc false
func (*OrderedLevelMatcher) MatchLevel ¶
func (o *OrderedLevelMatcher) MatchLevel(has, needs int64) bool
type Permission ¶
type Permission = pb.Permission
type PermissionsFunc ¶
type PermissionsFunc func(context.Context) ([]*Permission, error)
PermissionsFunc is used to retreive the permissions of the current user. The context passed is an incoming grpc context.
If it returns an error, it will be returned to the user.
type PrefixResourceMatcher ¶
type PrefixResourceMatcher struct{}
RegexResourceMatcher matches if the resource has the pattern as prefix
func (*PrefixResourceMatcher) MatchResource ¶
func (*PrefixResourceMatcher) MatchResource(prefix, resource string) (bool, error)
type RegexResourceMatcher ¶
type RegexResourceMatcher struct {
// contains filtered or unexported fields
}
RegexResourceMatcher matches if the resource satisfies the pattern (regex) It uses go's std regex library which follows the re2 syntax
func (*RegexResourceMatcher) MatchResource ¶
func (rm *RegexResourceMatcher) MatchResource(pattern, resource string) (bool, error)
type ResourceMatcher ¶
ResourceMatcher is used to match resources.
There are the following strategies already implemented, * Exact * Prefix * Regex * Glob
type Vanguard ¶
Vanguard holds all the compiled assert expressions against the fully qualified method name.
Example for key: /package.Service/Method Look at `NewVanguard` to see how it can be created
func NewVanguard ¶
NewVanguard reads all the proto files that are imported in the calling module and compiles vanguard's assert statements.
See Options for various ways it can be tweaked.