Initial cloud-services repo - gateway service + pkg modules
This commit is contained in:
39
pkg/httphandlers/auth_base.go
Normal file
39
pkg/httphandlers/auth_base.go
Normal file
@@ -0,0 +1,39 @@
|
||||
package httphandlers
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"fiskerinc.com/modules/adminroles"
|
||||
"fiskerinc.com/modules/common/authproviders"
|
||||
c "fiskerinc.com/modules/common/context"
|
||||
)
|
||||
|
||||
type AuthBase struct {
|
||||
}
|
||||
|
||||
func (a AuthBase) hasRoles(requiredRoles map[string][]adminroles.RoleID) bool {
|
||||
if len(requiredRoles) == 0 {
|
||||
return false
|
||||
}
|
||||
|
||||
for _, roles := range requiredRoles {
|
||||
if len(roles) > 0 {
|
||||
return true
|
||||
}
|
||||
}
|
||||
|
||||
return false
|
||||
}
|
||||
|
||||
func (a AuthBase) getRolesForProvider(provider string, required map[string][]adminroles.RoleID) (roles []adminroles.RoleID, ok bool) {
|
||||
if roles, ok = required[provider]; ok {
|
||||
return
|
||||
}
|
||||
|
||||
roles, ok = required[authproviders.Default]
|
||||
return
|
||||
}
|
||||
|
||||
func (a AuthBase) addContext(ctx context.Context, key c.ContextType, value string) context.Context {
|
||||
return context.WithValue(ctx, key, value)
|
||||
}
|
||||
Reference in New Issue
Block a user