Documentation
¶
Index ¶
- func CheckUserPermission(ctx context.Context, method string) bool
- func GetJWTSecret() []byte
- func GetMethodFromContext(ctx context.Context) string
- func GetServiceFromContext(ctx context.Context) string
- func GetUserFromContext(ctx context.Context) *typesv2.User
- func GetUserName(ctx context.Context) string
- func IsUserName(ctx context.Context, name string) bool
- func SetRBACContext(ctx context.Context, service, method string) context.Context
- func YAMLToJSONHandler(next http.Handler) http.Handler
- type AuthHandler
- type IPRateLimitHandler
- type JWTClaims
- type RBACHandler
- type TimeoutInterceptor
- func (*TimeoutInterceptor) WrapStreamingClient(next connect.StreamingClientFunc) connect.StreamingClientFunc
- func (*TimeoutInterceptor) WrapStreamingHandler(next connect.StreamingHandlerFunc) connect.StreamingHandlerFunc
- func (i *TimeoutInterceptor) WrapUnary(next connect.UnaryFunc) connect.UnaryFunc
- type UserRateLimitHandler
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func CheckUserPermission ¶
CheckUserPermission verifies if the user has the required permission Returns true if the user has permission, false otherwise
func GetJWTSecret ¶
func GetJWTSecret() []byte
GetJWTSecret returns the JWT secret, generating it if necessary
func GetMethodFromContext ¶
GetMethodFromContext retrieves the service from context
func GetServiceFromContext ¶
GetServiceFromContext retrieves the service from context
func GetUserFromContext ¶
GetUserFromContext retrieves the user from context
func GetUserName ¶
GetUserName returns logged in user name or empty string
func IsUserName ¶
IsUserName ensures the provided name and user's name are the same
func SetRBACContext ¶
SetRBACContext sets the RBAC service and method in context for permission checking
Types ¶
type AuthHandler ¶
type AuthHandler struct {
// contains filtered or unexported fields
}
AuthHandler is a HTTP middleware that handles authentication
func NewAuthHandler ¶
func NewAuthHandler(db *database.Database, ipRateLimiter *IPRateLimitHandler) *AuthHandler
NewAuthHandler creates a new auth handler
type IPRateLimitHandler ¶
type IPRateLimitHandler struct {
// contains filtered or unexported fields
}
IPRateLimitHandler handles rate limiting per IP for unauthenticated requests
func NewIPRateLimitHandler ¶
func NewIPRateLimitHandler(limit int32, window time.Duration) *IPRateLimitHandler
NewIPRateLimitHandler creates a new IP rate limit handler
func (*IPRateLimitHandler) Handler ¶
func (h *IPRateLimitHandler) Handler(next http.Handler) http.Handler
Handler implements HTTP middleware for IP rate limiting
func (*IPRateLimitHandler) Shutdown ¶
func (h *IPRateLimitHandler) Shutdown()
Shutdown stops the cleanup routine
type JWTClaims ¶
type JWTClaims struct {
UserName string `json:"user_name"`
Roles []string `json:"roles"`
jwt.RegisteredClaims
}
JWT claims structure
func ParseJWTToken ¶
ParseJWTToken parses a JWT token and returns the claims
type RBACHandler ¶
type RBACHandler struct {
// contains filtered or unexported fields
}
RBACHandler is a HTTP middleware that handles authorization
func NewRBACHandler ¶
func NewRBACHandler(enforcer *auth.Enforcer) *RBACHandler
NewRBACHandler creates a new RBAC handler
type TimeoutInterceptor ¶
type TimeoutInterceptor struct {
// contains filtered or unexported fields
}
TimeoutInterceptor adds timeout to unary operations
func NewTimeoutInterceptor ¶
func NewTimeoutInterceptor(timeout time.Duration) *TimeoutInterceptor
NewTimeoutInterceptor creates a new timeout interceptor
func (*TimeoutInterceptor) WrapStreamingClient ¶
func (*TimeoutInterceptor) WrapStreamingClient(next connect.StreamingClientFunc) connect.StreamingClientFunc
WrapStreamingClient is not implemented as we only want to timeout unary operations
func (*TimeoutInterceptor) WrapStreamingHandler ¶
func (*TimeoutInterceptor) WrapStreamingHandler(next connect.StreamingHandlerFunc) connect.StreamingHandlerFunc
WrapStreamingHandler is not implemented as we only want to timeout unary operations
type UserRateLimitHandler ¶
type UserRateLimitHandler struct {
// contains filtered or unexported fields
}
UserRateLimitHandler handles rate limiting per authenticated user
func NewUserRateLimitHandler ¶
func NewUserRateLimitHandler(db *database.Database, defaultLimit int32, window time.Duration) *UserRateLimitHandler
NewUserRateLimitHandler creates a new user rate limit handler
func (*UserRateLimitHandler) Handler ¶
func (h *UserRateLimitHandler) Handler(next http.Handler) http.Handler
Handler implements HTTP middleware for user rate limiting
func (*UserRateLimitHandler) Shutdown ¶
func (h *UserRateLimitHandler) Shutdown()
Shutdown stops the cleanup routine