Documentation ¶
Index ¶
- Constants
- Variables
- func Authorize(inner http.Handler, c Config) http.Handler
- func ContextCopyUser(parent, background context.Context) context.Context
- func ContextWithUser(ctx context.Context, u *User) context.Context
- func Middleware(p Parser) func(h http.Handler) http.Handler
- type Config
- type GroupTree
- type MockParser
- type MockPermission
- func (m MockPermission) CheckPermission(product string, object string, permission Permission, specials ...string) ([]string, bool)
- func (m MockPermission) GetAllGroups() map[string]struct{}
- func (m MockPermission) GetGroups(groupType string) []string
- func (m MockPermission) GetGroupsByTypes() map[string][]string
- func (m MockPermission) GetParents(group string) map[string]interface{}
- func (m MockPermission) ValidGroups(product string, object string, permission Permission) map[string]struct{}
- type Parser
- type Permission
- type PermissionTable
- func (t *PermissionTable) CheckPermission(product string, object string, per Permission, groups ...string) ([]string, bool)
- func (t *PermissionTable) GetAllGroups() map[string]struct{}
- func (t *PermissionTable) GetGroups(groupType string) []string
- func (t *PermissionTable) GetGroupsByTypes() map[string][]string
- func (t *PermissionTable) GetParents(group string) map[string]interface{}
- func (t *PermissionTable) ValidGroups(product string, object string, per Permission) map[string]struct{}
- type Permissions
- type User
Constants ¶
const ADDITIONAL = "a"
const AuthKey = key("authorization")
const ContextKey = key("permission")
ContextKey contains the key where the PermissionTree will be stored
const GROUP = "c"
const GROUPS = "g"
const PRODUCTS = "p"
const TYPE = "t"
Variables ¶
var ErrInvalidUser = errors.New("Invalid User")
Functions ¶
func ContextCopyUser ¶ added in v1.4.5
ContextCopyUser lookups for a user in a parent context a copies it into another context. Useful when creating background context with the parent's values
func ContextWithUser ¶ added in v1.4.5
ContextWithUser returns a new `context.Context` that holds a reference to the user `u`
Types ¶
type MockParser ¶ added in v1.4.5
type MockPermission ¶ added in v1.4.5
type MockPermission struct { CheckPermissionFn func(string, string, Permission, ...string) ([]string, bool) ValidGroupsFn func(string, string, Permission) map[string]struct{} GetGroupsFn func(string) []string GetAllGroupsFn func() map[string]struct{} GetGroupsByTypesFn func() map[string][]string GetParentsFn func(string) map[string]interface{} }
func (MockPermission) CheckPermission ¶ added in v1.4.5
func (m MockPermission) CheckPermission(product string, object string, permission Permission, specials ...string) ([]string, bool)
func (MockPermission) GetAllGroups ¶ added in v1.4.5
func (m MockPermission) GetAllGroups() map[string]struct{}
func (MockPermission) GetGroups ¶ added in v1.4.5
func (m MockPermission) GetGroups(groupType string) []string
func (MockPermission) GetGroupsByTypes ¶ added in v1.4.5
func (m MockPermission) GetGroupsByTypes() map[string][]string
func (MockPermission) GetParents ¶ added in v1.4.5
func (m MockPermission) GetParents(group string) map[string]interface{}
func (MockPermission) ValidGroups ¶ added in v1.4.5
func (m MockPermission) ValidGroups(product string, object string, permission Permission) map[string]struct{}
type Permission ¶ added in v1.2.0
type Permission string
const ( Create Permission = "c" Update Permission = "u" Delete Permission = "d" Read Permission = "r" Execute Permission = "x" Admin Permission = "a" )
type PermissionTable ¶
type PermissionTable struct { Permissions map[string]map[string]map[Permission]map[string]struct{} //Product-->object-->Permission-->Groups IsAdmin bool Bearer string Groups []map[string]GroupTree // Group hierarchy tree MemberID []string // Member identifier }
func NewPermissionTable ¶
func NewPermissionTable(jwt interface{}, memberId []string, bearer string, adminGroup string) *PermissionTable
func PermissionTableFromContext ¶ added in v1.1.1
func PermissionTableFromContext(ctx context.Context) (*PermissionTable, bool)
PermissionTableFromContext returns the permissionTable stored in a context
func (*PermissionTable) CheckPermission ¶
func (t *PermissionTable) CheckPermission(product string, object string, per Permission, groups ...string) ([]string, bool)
Checks the user Permissions for a specified product and object Returns: Groups that have the requested Permissions
func (*PermissionTable) GetAllGroups ¶
func (t *PermissionTable) GetAllGroups() map[string]struct{}
Return the group codes
func (*PermissionTable) GetGroups ¶ added in v1.1.1
func (t *PermissionTable) GetGroups(groupType string) []string
Returns all groups of a given type
func (*PermissionTable) GetGroupsByTypes ¶ added in v1.1.1
func (t *PermissionTable) GetGroupsByTypes() map[string][]string
Returns a map indexed by group types, containing the list of groups of that type
func (*PermissionTable) GetParents ¶
func (t *PermissionTable) GetParents(group string) map[string]interface{}
Returns all the parents of a given group
func (*PermissionTable) ValidGroups ¶
func (t *PermissionTable) ValidGroups(product string, object string, per Permission) map[string]struct{}
Return all the groups that have a Permissions into an object
type Permissions ¶ added in v1.2.0
type Permissions interface { // CheckPermission returns the given Permissions for a given product and object. Returns the special Permissions applied on that object if any, and a boolean indicating if the user has the requested Permission. NOTE: Special Permissions returned can be filtered by the specials argument). CheckPermission(product string, object string, permission Permission, specials ...string) ([]string, bool) // ValidGroups returns all the groups and its Permissions that have any Permission for the given product and object. ValidGroups(product string, object string, permission Permission) map[string]struct{} // Returns all groups of a given type GetGroups(groupType string) []string // GetAllGroups returns the group hierarchy GetAllGroups() map[string]struct{} // GetGroupsByTypes returns a map indexed by group types, containing the list of groups of that type GetGroupsByTypes() map[string][]string // GetParents returns all the parent groups of a given group. GetParents(group string) map[string]interface{} }