Documentation
¶
Index ¶
- Constants
- Variables
- func AddAuthHeaders(ctx context.Context, r *http.Request, serviceToken string)
- func AddDeprecatedHeader(r *http.Request, token string)
- func AddDownloadServiceTokenHeader(r *http.Request, serviceToken string)
- func AddFlorenceHeader(r *http.Request, userAccessToken string)
- func AddRequestIdHeader(r *http.Request, token string)
- func AddServiceTokenHeader(r *http.Request, serviceToken string)
- func AddUserHeader(r *http.Request, user string)
- func Caller(ctx context.Context) string
- func ErrInvalidOp(supportedOps []PatchOp) error
- func ErrMissingMember(members []string) error
- func ErrUnsupportedOp(op string, supportedOps []PatchOp) error
- func GetCollectionID(req *http.Request) (string, error)
- func GetLangFromCookieOrDefault(c *http.Cookie) string
- func GetLangFromSubDomain(req *http.Request) string
- func GetLocaleCode(r *http.Request) string
- func GetRequestId(ctx context.Context) string
- func HandlerRequestID(size int) func(http.Handler) http.Handler
- func IsCallerPresent(ctx context.Context) bool
- func IsFlorenceIdentityPresent(ctx context.Context) bool
- func IsUserPresent(ctx context.Context) bool
- func NewRequestID(size int) string
- func SetCaller(ctx context.Context, caller string) context.Context
- func SetFlorenceHeader(ctx context.Context, r *http.Request)
- func SetFlorenceIdentity(ctx context.Context, user string) context.Context
- func SetLocaleCode(req *http.Request) *http.Request
- func SetUser(ctx context.Context, user string) context.Context
- func User(ctx context.Context) string
- func WithRequestId(ctx context.Context, correlationID string) context.Context
- type CheckRequester
- type ContextKey
- type IdentityResponse
- type Params
- type Patch
- type PatchOp
Constants ¶
const ( CollectionIDHeaderKey = "Collection-Id" CollectionIDCookieKey = "collection" )
CollectionID header and cookie keys
const ( UserIdentityKey = ContextKey("User-Identity") CallerIdentityKey = ContextKey("Caller-Identity") RequestIdKey = ContextKey("request-id") FlorenceIdentityKey = ContextKey("florence-id") LocaleContextKey = ContextKey(LocaleHeaderKey) CollectionIDContextKey = ContextKey(CollectionIDHeaderKey) )
const ( AuthHeaderKey = "Authorization" DownloadServiceHeaderKey = "X-Download-Service-Token" FlorenceHeaderKey = "X-Florence-Token" UserHeaderKey = "User-Identity" )
Header constants
const ( DeprecatedAuthHeader = "Internal-Token" LegacyUser = "legacyUser" BearerPrefix = "Bearer " )
Other identity-related constants
const ( LangEN = "en" LangCY = "cy" DefaultLang = LangEN LocaleCookieKey = "lang" LocaleHeaderKey = "LocaleCode" )
const (
FlorenceCookieKey = "access_token"
)
Cookie constants
const (
RequestHeaderKey = "X-Request-Id"
)
Header constants
Variables ¶
var SupportedLanguages = [2]string{LangEN, LangCY}
Functions ¶
func AddAuthHeaders ¶
AddAuthHeaders sets authentication headers for request
func AddDeprecatedHeader ¶
AddDeprecatedHeader sets the deprecated header on the given request
func AddDownloadServiceTokenHeader ¶
AddDownloadServiceTokenHeader sets the given download service token on the given request
func AddFlorenceHeader ¶
AddFlorenceHeader sets the given user access token (florence token) token on the given request
func AddRequestIdHeader ¶
AddRequestIdHeader add header for given correlation ID
func AddServiceTokenHeader ¶
AddServiceTokenHeader sets the given service token on the given request
func AddUserHeader ¶
AddUserHeader sets the given user ID on the given request
func ErrInvalidOp ¶
ErrInvalidOp generates an error when a patch contains a wrong 'op'
func ErrMissingMember ¶
ErrMissingMember generates an error for a missing member
func ErrUnsupportedOp ¶
ErrUnsupportedOp generates an error for unsupported ops
func GetCollectionID ¶
GetCollectionID gets the collection id from the request
func GetLangFromCookieOrDefault ¶
GetLangFromCookieOrDefault returns a language based on the lang cookie or if not valid defaults it
func GetLangFromSubDomain ¶
GetLangFromSubDomain returns a language based on subdomain
func GetLocaleCode ¶
GetLocaleCode will grab the locale code from the request
func GetRequestId ¶
GetRequestId gets the correlation id on the context
func HandlerRequestID ¶
HandlerRequestID is a wrapper which adds an X-Request-Id header if one does not yet exist
func IsCallerPresent ¶
IsCallerPresent determines if an identity is present on the given context.
func IsFlorenceIdentityPresent ¶
IsFlorenceIdentityPresent determines if a florence identity is present on the given context
func IsUserPresent ¶
IsUserPresent determines if a user identity is present on the given context
func NewRequestID ¶
NewRequestID generates a random string of requested length
func SetFlorenceHeader ¶
SetFlorenceHeader sets a florence Header if the corresponding Identity key is in context
func SetFlorenceIdentity ¶
SetFlorenceIdentity sets the florence identity for authentication
func SetLocaleCode ¶
SetLocaleCode will fetch the locale code and then sets it
Types ¶
type CheckRequester ¶
CheckRequester is an interface to allow mocking of auth.CheckRequest
type ContextKey ¶
type ContextKey string
type IdentityResponse ¶
type IdentityResponse struct {
Identifier string `json:"identifier"`
}
IdentityResponse represents the response from the identity service
type Params ¶
Params represents a generic map of key value pairs, expected by go-ns/audit Auditor.Record()
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 ¶
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