utils

package
v0.0.0-...-30b734a Latest Latest
Warning

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

Go to latest
Published: Jan 2, 2025 License: MIT Imports: 25 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AuthedRequest

func AuthedRequest(req *http.Request) *http.Request

Add the auth header to a request

func CorsMiddleware

func CorsMiddleware(ctx huma.Context, next func(huma.Context))

Middleware to add cors headers

func FailOnError

func FailOnError(err error, msg string)

func GetDelLogTags

func GetDelLogTags(msg *amqp.Delivery) string

func LoadConfig

func LoadConfig()

LoadConfig loads and validates the configuration from a .env and environment variables

func LogResponse

func LogResponse(ctx context.Context, resp *http.Response, req *http.Request)

This isn't working for some reason

func LogWithContext

func LogWithContext(ctx context.Context, msg ...string)

Logs the message and appends span/traceId tags from the passed context

func MockLoadConfig

func MockLoadConfig()

func OidcMiddleware

func OidcMiddleware(ctx huma.Context, next func(huma.Context))

Middleware to provide authentication in cxt.Values("user.id")

func PrettyPrint

func PrettyPrint(i interface{}) string

func RegisterOidcProvider

func RegisterOidcProvider(ctx context.Context)

Register an Oidc Provider

func SendRequest

func SendRequest(ctx context.Context, method string, sendUrl string, pBody *bytes.Reader, timeout time.Duration) (*http.Response, error)

Post an unauthed request to the given url Returns the response or an error if requests statusCode is not 2xx uses to application/json content type for post bodies

func TraceTagList

func TraceTagList(ctx context.Context) []string

List of traceId, spanId for slog, can't get this working for some reason

func TraceTags

func TraceTags(ctx context.Context) string

String formatted traceId, spanId for logging

Types

type ClientClaims

type ClientClaims struct {
	//The user id
	Uid    string   `json:"sub"`
	Groups []string `json:"groups"`
	jwt.RegisteredClaims
}

Wrapper type for claims from the jwt

func Authorize

func Authorize(w http.ResponseWriter, r *http.Request, allowedMethods []string, requiredScope string) (claims *ClientClaims, err error)

Extract a token, add cors headers, and validate the token

func ValidateToken

func ValidateToken(ctx context.Context, tokenString string) (claims *ClientClaims, err error)

Validate a token and return the claims

type ConfigValues

type ConfigValues struct {
	// RabbitMQ config
	MQ_HOST string `validate:"required"`
	MQ_PORT string `validate:"required"`
	MQ_USER string `validate:"required"`
	MQ_PASS string `validate:"required"`
	// Queue config
	GEN_XCHANGE  string `validate:"required"`
	PROG_XCHANGE string `validate:"required"`
	// Prefix for exchanges and queues to enable different environments
	MQ_PREFIX string
	// OIDC config
	OIDC_ISSUER        string `validate:"required"`
	OIDC_CLIENT_ID     string `validate:"required"`
	OIDC_CLIENT_SECRET string `validate:"required"`
	GEN_HANDLER_SECRET string `validate:"required"`
	GEN_HANDLER_SA     string `validate:"required"`

	// API to query machines and send results
	API_SEND_URL string

	// Port number for http server
	PORT_NUM int
	// Machine check interval in minutes
	MACHINE_FETCH_INTERVAL int
	// Machine status check interval in minutes
	CHECK_INTERVAL int
	// Restart check interval in milliseconds
	RESTART_CHECK_INTERVAL int
	// Router timeout in seconds
	ROUTER_TIMEOUT int
	// Max reqeues before dropping a message (total idle time for a gen would be router_timeout * (max_router_retry_count + )
	MAX_ROUTER_RETRY_COUNT uint64

	// OTLP config
	DEPLOYMENT_ENVIRONMENT_NAME string `validate:"required"`
	OTEL_SERVICE_NAME           string `validate:"required"`
	OTEL_EXPORTER_OTLP_ENDPOINT string `validate:"required"`
	// Enable a debug consumer queue
	DEBUG_CONSUMER_QUEUE bool

	LOG_LEVEL string
}
var Config *ConfigValues

func MockConfig

func MockConfig() ConfigValues

func (*ConfigValues) GetDLXchange

func (c *ConfigValues) GetDLXchange() string

func (*ConfigValues) GetDLXqueue

func (c *ConfigValues) GetDLXqueue() string

func (*ConfigValues) GetGenXchange

func (c *ConfigValues) GetGenXchange() string

func (*ConfigValues) GetLoggerLevel

func (c *ConfigValues) GetLoggerLevel() slog.Level

func (*ConfigValues) GetMqUrl

func (c *ConfigValues) GetMqUrl() string

func (*ConfigValues) GetProgXchange

func (c *ConfigValues) GetProgXchange() string

Jump to

Keyboard shortcuts

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