util

package
v0.9.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 18, 2025 License: Apache-2.0 Imports: 19 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CheckUserPermission

func CheckUserPermission(ctx context.Context, method string) bool

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

func GetMethodFromContext(ctx context.Context) string

GetMethodFromContext retrieves the service from context

func GetServiceFromContext

func GetServiceFromContext(ctx context.Context) string

GetServiceFromContext retrieves the service from context

func GetUserFromContext

func GetUserFromContext(ctx context.Context) *typesv2.User

GetUserFromContext retrieves the user from context

func GetUserName

func GetUserName(ctx context.Context) string

GetUserName returns logged in user name or empty string

func IsUserName

func IsUserName(ctx context.Context, name string) bool

IsUserName ensures the provided name and user's name are the same

func SetRBACContext

func SetRBACContext(ctx context.Context, service, method string) context.Context

SetRBACContext sets the RBAC service and method in context for permission checking

func YAMLToJSONHandler

func YAMLToJSONHandler(next http.Handler) http.Handler

YAMLToJSONHandler is a HTTP middleware that converts YAML to JSON

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

func (*AuthHandler) Handler

func (h *AuthHandler) Handler(next http.Handler) http.Handler

Handler implements HTTP middleware for authentication

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

func ParseJWTToken(tokenString string) (*JWTClaims, error)

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

func (*RBACHandler) Handler

func (h *RBACHandler) Handler(next http.Handler) http.Handler

Handler implements HTTP middleware for authorization

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

WrapStreamingClient is not implemented as we only want to timeout unary operations

func (*TimeoutInterceptor) WrapStreamingHandler

WrapStreamingHandler is not implemented as we only want to timeout unary operations

func (*TimeoutInterceptor) WrapUnary

WrapUnary wraps unary operations with timeout

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

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL