Documentation ¶
Index ¶
- Constants
- func ErrHeaderRequired(name string) error
- func ErrInvalidFormat(name string) error
- func GetAcceptedLanguages(ctx context.Context) []string
- func MaskForNonAdmin(ctx *gin.Context, m Masker)
- func MustGetClientIP(ctx context.Context) string
- func MustGetFingerprint(ctx context.Context) string
- func MustGetRequestID(ctx context.Context) string
- func MustGetTokenID(ctx context.Context) string
- func MustGetUserAgent(ctx context.Context) string
- func MustGetUserID(ctx context.Context) string
- func MustGetUserRole(ctx context.Context) string
- func PrepareContext(ctx *gin.Context)
- func RequestHeaders(ctx context.Context) http.Header
- func RequestHeadersMap(ctx context.Context) map[string]string
- func RequestXHeadersMap(ctx context.Context) map[string]string
- func RequireAdminRole(errToReturn cherry.ErrConstruct) gin.HandlerFunc
- func RequireHeaders(errToReturn cherry.ErrConstruct, headers ...string) gin.HandlerFunc
- func SaveHeaders(ctx *gin.Context)
- func ServiceStatus(status *kubeModel.ServiceStatus) gin.HandlerFunc
- func SubstituteUserMiddleware(validate *validator.Validate, translator *ut.UniversalTranslator, ...) gin.HandlerFunc
- func ValidateQueryParamsMiddleware(vmap map[string]string, validate *validator.Validate, ...) gin.HandlerFunc
- func ValidateURLParamsMiddleware(vmap map[string]string, validate *validator.Validate, ...) gin.HandlerFunc
- type AccessChecker
- type Masker
- type NamespaceAccess
- type Permissions
- type ProjectAccess
Constants ¶
const ( ProjectParam = "project" NamespaceParam = "namespace" )
const ( FingerPrintContextKey contextKey = iota ClientIPContextKey UserAgentContextKey RequestIDContextKey UserIDContextKey TokenIDContextKey UserRoleContextKey AcceptLanguageContextKey )
Keys to inject data to context
const ( UserClientHeader = "User-Client" AuthorizationHeader = "User-Token" )
Extrernal headers
const ( RequestIDXHeader = "X-Request-ID" RequestNameXHeader = "X-Request-Name" UserIDXHeader = "X-User-ID" UserClientXHeader = "X-User-Client" UserAgentXHeader = "X-User-Agent" UserIPXHeader = "X-Client-IP" TokenIDXHeader = "X-Token-ID" UserRoleXHeader = "X-User-Role" UserNamespacesXHeader = "X-User-Namespace" UserVolumesXHeader = "X-User-Volume" UserHideDataXHeader = "X-User-Hide-Data" )
Internal headers
const AccessContext = "access-ctx"
const AllAccessContext = "all-access-ctx"
Variables ¶
This section is empty.
Functions ¶
func ErrHeaderRequired ¶
ErrHeaderRequired return if header not required
func ErrInvalidFormat ¶
ErrInvalidFormat return if header has invalid format
func GetAcceptedLanguages ¶
GetAcceptedLanguages extracts accepted languages from context
func MaskForNonAdmin ¶
func MustGetClientIP ¶
MustGetClientIP attempts to extract client IP address using ClientIPContextKey from context. It panics if value was not found.
func MustGetFingerprint ¶
MustGetFingerprint attempts to extract client fingerprint using FingerPrintContextKey from context. It panics if value was not found.
func MustGetRequestID ¶
MustGetSessionID attempts to extract session ID using RequestIDContextKey from context. It panics if value was not found in context.
func MustGetTokenID ¶
MustGetTokenID attempts to extract token ID using TokenIDContextKey from context. It panics if value was not found in context.
func MustGetUserAgent ¶
MustGetUserAgent attempts to extract client IP address using UserAgentContextKey from context. It panics if value was not found.
func MustGetUserID ¶
MustGetUserID attempts to extract user ID using RequestIDContextKey from context. It panics if value was not found in context.
func MustGetUserRole ¶
MustGetUserRole attempts to extract user role using UserRoleContextKey from context It panics if value was not found in context.
func PrepareContext ¶
PrepareContext is a gin middleware which adds values from header to context
func RequestHeaders ¶
RequestHeaders extracts saved headers from context. saveHeaders middleware required for operation.
func RequestHeadersMap ¶
RequestHeadersMap extracts saved headers from context as map[string]string (useful for resty). saveHeaders middleware required for operation.
func RequestXHeadersMap ¶
RequestXHeadersMap works like RequestHeadersMap but returns only "X-" headers
func RequireAdminRole ¶
func RequireAdminRole(errToReturn cherry.ErrConstruct) gin.HandlerFunc
RequireAdminRole is a gin middleware which requires admin role
func RequireHeaders ¶
func RequireHeaders(errToReturn cherry.ErrConstruct, headers ...string) gin.HandlerFunc
RequireHeaders is a gin middleware to ensure that headers is set
func SaveHeaders ¶
SaveHeaders is a gin middleware which saves headers to request context
func ServiceStatus ¶ added in v1.0.7
func ServiceStatus(status *kubeModel.ServiceStatus) gin.HandlerFunc
func SubstituteUserMiddleware ¶
func SubstituteUserMiddleware(validate *validator.Validate, translator *ut.UniversalTranslator, validationErr cherry.ErrConstruct) gin.HandlerFunc
SubstituteUserMiddleware replaces user id in context with user id from query if it set and user is admin
func ValidateQueryParamsMiddleware ¶ added in v1.0.1
func ValidateQueryParamsMiddleware(vmap map[string]string, validate *validator.Validate, translator *ut.UniversalTranslator, validationErr cherry.ErrConstruct) gin.HandlerFunc
ValidateQueryParamsMiddleware validates query parameters with provided tags. Key of "vmap" is parameter name, value is tag
func ValidateURLParamsMiddleware ¶ added in v1.0.1
func ValidateURLParamsMiddleware(vmap map[string]string, validate *validator.Validate, translator *ut.UniversalTranslator, validationErr cherry.ErrConstruct) gin.HandlerFunc
ValidateURLParamsMiddleware validates URL parameters with provided tags. Key of "vmap" is parameter name, value is tag
Types ¶
type AccessChecker ¶ added in v1.0.4
type AccessChecker struct { PermissionsClient Permissions AccessError cherry.ErrConstruct NotFoundError cherry.ErrConstruct }
func (*AccessChecker) CheckAccess ¶ added in v1.0.4
func (a *AccessChecker) CheckAccess(requiredAccess kubeModel.UserGroupAccess) gin.HandlerFunc
func (*AccessChecker) SaveAllAccesses ¶ added in v1.0.4
func (a *AccessChecker) SaveAllAccesses() gin.HandlerFunc
type NamespaceAccess ¶ added in v1.0.4
type NamespaceAccess struct { NamespaceID string `json:"namespace_id"` NamespaceLabel string `json:"namespace_label"` Access kubeModel.UserGroupAccess `json:"access"` }
type Permissions ¶ added in v1.0.4
type Permissions interface { GetAllAccesses(ctx context.Context) ([]ProjectAccess, error) GetNamespaceAccess(ctx context.Context, projectID, namespaceID string) (NamespaceAccess, error) }
type ProjectAccess ¶ added in v1.0.4
type ProjectAccess struct { ProjectID string `json:"project_id"` ProjectLabel string `json:"project_label"` NamespacesAccesses []NamespaceAccess `json:"namespaces"` }