request

package
v1.5.0 Latest Latest
Warning

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

Go to latest
Published: Aug 15, 2022 License: MIT Imports: 8 Imported by: 25

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)
)

Context keys

View Source
const (
	FlorenceHeaderKey        = "X-Florence-Token"
	AuthHeaderKey            = "Authorization"
	DownloadServiceHeaderKey = "X-Download-Service-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 ErrInvalidOp = fmt.Errorf("operation is missing or not valid. Please, provide one of the following: %v", validOps)

ErrInvalidOp is an error returned when a patch contains a wrong 'op'

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 ErrMissingMember added in v1.0.10

func ErrMissingMember(members []string) error

ErrMissingMember generates an error for a missing member

func ErrUnsupportedOp added in v1.0.10

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

ErrUnsupportedOp generates an error for unsupported ops

func GetCollectionID added in v1.0.9

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

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 added in v1.0.9

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

type ContextKey string

ContextKey is an alias of type 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 added in v1.0.10

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 (*Patch) Validate added in v1.0.10

func (p *Patch) Validate(supportedOps ...PatchOp) error

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

type PatchOp added in v1.0.10

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 added in v1.0.10

func (o PatchOp) String() string

Jump to

Keyboard shortcuts

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