request

package
v2.11.2 Latest Latest
Warning

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

Go to latest
Published: Nov 30, 2023 License: MIT Imports: 11 Imported by: 46

Documentation

Index

Constants

View Source
const (
	CollectionIDHeaderKey = "Collection-Id"
	CollectionIDCookieKey = "collection"
)

CollectionID header and cookie keys

View Source
const (
	UserIdentityKey        = ContextKey("User-Identity")
	CallerIdentityKey      = ContextKey("Caller-Identity")
	RequestIdKey           = ContextKey("request-id")
	FlorenceIdentityKey    = ContextKey("florence-id")
	LocaleContextKey       = ContextKey(LocaleHeaderKey)
	CollectionIDContextKey = ContextKey(CollectionIDHeaderKey)
)
View Source
const (
	AuthHeaderKey            = "Authorization"
	DownloadServiceHeaderKey = "X-Download-Service-Token"
	FlorenceHeaderKey        = "X-Florence-Token"
	UserHeaderKey            = "User-Identity"
)

Header constants

View Source
const (
	DeprecatedAuthHeader = "Internal-Token"
	LegacyUser           = "legacyUser"
	BearerPrefix         = "Bearer "
)

Other identity-related constants

View Source
const (
	LangEN = "en"
	LangCY = "cy"

	DefaultLang = LangEN

	LocaleCookieKey = "lang"
	LocaleHeaderKey = "LocaleCode"
)
View Source
const (
	FlorenceCookieKey = "access_token"
)

Cookie constants

View Source
const (
	RequestHeaderKey = "X-Request-Id"
)

Header constants

Variables

View Source
var SupportedLanguages = [2]string{LangEN, LangCY}

Functions

func AddAuthHeaders

func AddAuthHeaders(ctx context.Context, r *http.Request, serviceToken string)

AddAuthHeaders sets authentication headers for request

func AddDeprecatedHeader

func AddDeprecatedHeader(r *http.Request, token string)

AddDeprecatedHeader sets the deprecated header on the given request

func AddDownloadServiceTokenHeader

func AddDownloadServiceTokenHeader(r *http.Request, serviceToken string)

AddDownloadServiceTokenHeader sets the given download service token on the given request

func AddFlorenceHeader

func AddFlorenceHeader(r *http.Request, userAccessToken string)

AddFlorenceHeader sets the given user access token (florence token) token on the given request

func AddRequestIdHeader

func AddRequestIdHeader(r *http.Request, token string)

AddRequestIdHeader add header for given correlation ID

func AddServiceTokenHeader

func AddServiceTokenHeader(r *http.Request, serviceToken string)

AddServiceTokenHeader sets the given service token on the given request

func AddUserHeader

func AddUserHeader(r *http.Request, user string)

AddUserHeader sets the given user ID on the given request

func Caller

func Caller(ctx context.Context) string

Caller gets the caller identity from the context

func ErrInvalidOp

func ErrInvalidOp(supportedOps []PatchOp) error

ErrInvalidOp generates an error when a patch contains a wrong 'op'

func ErrMissingMember

func ErrMissingMember(members []string) error

ErrMissingMember generates an error for a missing member

func ErrUnsupportedOp

func ErrUnsupportedOp(op string, supportedOps []PatchOp) error

ErrUnsupportedOp generates an error for unsupported ops

func GetCollectionID

func GetCollectionID(req *http.Request) (string, error)

GetCollectionID gets the collection id from the request

func GetLangFromCookieOrDefault

func GetLangFromCookieOrDefault(c *http.Cookie) string

GetLangFromCookieOrDefault returns a language based on the lang cookie or if not valid defaults it

func GetLangFromSubDomain

func GetLangFromSubDomain(req *http.Request) string

GetLangFromSubDomain returns a language based on subdomain

func GetLocaleCode

func GetLocaleCode(r *http.Request) string

GetLocaleCode will grab the locale code from the request

func GetRequestId

func GetRequestId(ctx context.Context) string

GetRequestId gets the correlation id on the context

func HandlerRequestID

func HandlerRequestID(size int) func(http.Handler) http.Handler

HandlerRequestID is a wrapper which adds an X-Request-Id header if one does not yet exist

func IsCallerPresent

func IsCallerPresent(ctx context.Context) bool

IsCallerPresent determines if an identity is present on the given context.

func IsFlorenceIdentityPresent

func IsFlorenceIdentityPresent(ctx context.Context) bool

IsFlorenceIdentityPresent determines if a florence identity is present on the given context

func IsUserPresent

func IsUserPresent(ctx context.Context) bool

IsUserPresent determines if a user identity is present on the given context

func NewRequestID

func NewRequestID(size int) string

NewRequestID generates a random string of requested length

func SetCaller

func SetCaller(ctx context.Context, caller string) context.Context

SetCaller sets the caller identity on the context

func SetFlorenceHeader

func SetFlorenceHeader(ctx context.Context, r *http.Request)

SetFlorenceHeader sets a florence Header if the corresponding Identity key is in context

func SetFlorenceIdentity

func SetFlorenceIdentity(ctx context.Context, user string) context.Context

SetFlorenceIdentity sets the florence identity for authentication

func SetLocaleCode

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

SetLocaleCode will fetch the locale code and then sets it

func SetUser

func SetUser(ctx context.Context, user string) context.Context

SetUser sets the user identity on the context

func User

func User(ctx context.Context) string

User gets the user identity from the context

func WithRequestId

func WithRequestId(ctx context.Context, correlationID string) context.Context

WithRequestId sets the correlation id on the context

Types

type CheckRequester

type CheckRequester interface {
	CheckRequest(*http.Request) (context.Context, int, error)
}

CheckRequester is an interface to allow mocking of auth.CheckRequest

type ContextKey added in v2.9.0

type ContextKey string

type IdentityResponse

type IdentityResponse struct {
	Identifier string `json:"identifier"`
}

IdentityResponse represents the response from the identity service

type Params

type Params map[string]string

Params represents a generic map of key value pairs, expected by go-ns/audit Auditor.Record()

func (Params) Copy

func (originalParams Params) Copy() Params

Copy preserves the original params value (key value pair) but stores the data in a different reference address

type Patch

type Patch struct {
	Op    string      `json:"op"`
	Path  string      `json:"path"`
	From  string      `json:"from"`
	Value interface{} `json:"value"`
}

Patch models an HTTP patch operation request, according to RFC 6902

func GetPatches added in v2.1.0

func GetPatches(requestBody io.ReadCloser, supportedOps []PatchOp) ([]Patch, error)

GetPatches gets the patches from the request body and returns it in the form of []Patch. An error will be returned if request body cannot be read, unmarshalling the requets body is unsuccessful, no patches are provided in the request or any of the provided patches are invalid

func (*Patch) Validate

func (p *Patch) Validate(supportedOps []PatchOp) error

Validate checks that the provided operation is correct and the expected members are provided

type PatchOp

type PatchOp int

PatchOp - iota enum of possible patch operations

const (
	OpAdd PatchOp = iota
	OpRemove
	OpReplace
	OpMove
	OpCopy
	OpTest
)

Possible patch operations

func (PatchOp) String

func (o PatchOp) String() string

Jump to

Keyboard shortcuts

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