common

package
v0.0.0-...-109c033 Latest Latest
Warning

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

Go to latest
Published: Aug 29, 2024 License: MIT Imports: 6 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GetAccessToken

func GetAccessToken(ctx context.Context) string

GetAccessToken obtains the raw access token from the context.

This is without the "Bearer " prefix.

func GetGroups

func GetGroups(ctx context.Context) []string

GetGroups extracts the groups from the jwt token that came with the request or from the groups retrieved from userinfo, if using authorization token.

In either case the list is filtered by relevant groups (if reg-auth-service is configured).

func GetRequestID

func GetRequestID(ctx context.Context) string

GetRequestID extracts the request ID from the context.

It originally comes from a header with the request, or is rolled while processing the request.

func GetSubject

func GetSubject(ctx context.Context) string

GetSubject extracts the subject field from the jwt token or the userinfo response, if using an authorization token.

func HasGroup

func HasGroup(ctx context.Context, group string) bool

HasGroup checks that the user has a group.

func IsAPIError

func IsAPIError(err error) bool

func IsBadGatewayError

func IsBadGatewayError(err error) bool

func IsBadRequestError

func IsBadRequestError(err error) bool

func IsConflictError

func IsConflictError(err error) bool

func IsForbiddenError

func IsForbiddenError(err error) bool

func IsInternalServerError

func IsInternalServerError(err error) bool

func IsNotFoundError

func IsNotFoundError(err error) bool

func IsUnauthorizedError

func IsUnauthorizedError(err error) bool

Types

type APIError

type APIError interface {
	error
	Status() int
	Response() apimodel.Error
}

APIError allows lower layers of the service to provide detailed information about an error.

While this breaks layer separation somewhat, it avoids having to map errors all over the place.

func NewAPIError

func NewAPIError(ctx context.Context, status int, message ErrorMessageCode, details url.Values) APIError

NewAPIError creates a generic API error from directly provided information.

func NewBadGateway

func NewBadGateway(ctx context.Context, message ErrorMessageCode, details url.Values) APIError

func NewBadRequest

func NewBadRequest(ctx context.Context, message ErrorMessageCode, details url.Values) APIError

func NewConflict

func NewConflict(ctx context.Context, message ErrorMessageCode, details url.Values) APIError

func NewForbidden

func NewForbidden(ctx context.Context, message ErrorMessageCode, details url.Values) APIError

func NewInternalServerError

func NewInternalServerError(ctx context.Context, message ErrorMessageCode, details url.Values) APIError

func NewNotFound

func NewNotFound(ctx context.Context, message ErrorMessageCode, details url.Values) APIError

func NewUnauthorized

func NewUnauthorized(ctx context.Context, message ErrorMessageCode, details url.Values) APIError

type AllClaims

type AllClaims struct {
	jwt.RegisteredClaims
	CustomClaims
}

func GetClaims

func GetClaims(ctx context.Context) *AllClaims

GetClaims extracts all jwt token claims from the context.

type CtxKeyAPIKey

type CtxKeyAPIKey struct{}

type CtxKeyAccessToken

type CtxKeyAccessToken struct{}

type CtxKeyClaims

type CtxKeyClaims struct{}

type CtxKeyIDToken

type CtxKeyIDToken struct{}

type CtxKeyRequestID

type CtxKeyRequestID struct{}

type CustomClaims

type CustomClaims struct {
	EMail         string   `json:"email"`
	EMailVerified bool     `json:"email_verified"`
	Groups        []string `json:"groups,omitempty"`
	Name          string   `json:"name"`
}

type ErrorMessageCode

type ErrorMessageCode string

ErrorMessageCode is a key to use for error messages in frontends or other automated systems interacting with our API. It avoids having to parse human-readable language for error classification beyond the http status.

const (
	AuthUnauthorized     ErrorMessageCode = "auth.unauthorized" // token missing completely or invalid or expired
	AuthForbidden        ErrorMessageCode = "auth.forbidden"    // permissions missing
	RequestParseFailed   ErrorMessageCode = "request.parse.failed"
	ValueTooHigh         ErrorMessageCode = "value.too.high"
	ValueTooLow          ErrorMessageCode = "value.too.low"
	InternalErrorMessage ErrorMessageCode = "error.internal"
	UnknownErrorMessage  ErrorMessageCode = "error.unknown"
)

type StatusError

type StatusError struct {
	// contains filtered or unexported fields
}

func (*StatusError) Error

func (se *StatusError) Error() string

func (*StatusError) Response

func (se *StatusError) Response() apimodel.Error

func (*StatusError) Status

func (se *StatusError) Status() int

Jump to

Keyboard shortcuts

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