common

package
v0.0.0-...-03689f6 Latest Latest
Warning

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

Go to latest
Published: May 22, 2019 License: MIT Imports: 7 Imported by: 0

Documentation

Index

Constants

View Source
const (
	FlorenceHeaderKey        = "X-Florence-Token"
	DownloadServiceHeaderKey = "X-Download-Service-Token"

	FlorenceCookieKey = "access_token"

	AuthHeaderKey    = "Authorization"
	UserHeaderKey    = "User-Identity"
	RequestHeaderKey = "X-Request-Id"

	DeprecatedAuthHeader = "Internal-Token"
	LegacyUser           = "legacyUser"
	BearerPrefix         = "Bearer "

	UserIdentityKey     = ContextKey("User-Identity")
	CallerIdentityKey   = ContextKey("Caller-Identity")
	RequestIdKey        = ContextKey("request-id")
	FlorenceIdentityKey = ContextKey("florence-id")
)

A list of common constants used across go-ns packages

Variables

This section is empty.

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

func GetRequestId(ctx context.Context) string

GetRequestId gets the correlation id on the context

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

type APIClient struct {
	BaseURL    string
	AuthToken  string
	HTTPClient RCHTTPClienter
	Lock       sync.RWMutex
}

APIClient represents a common structure for any api client

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 ONSError

type ONSError struct {
	Parameters map[string]interface{}
	RootError  error
}

ONSError encapsulates an error with additional parameters

func NewONSError

func NewONSError(e error, description string) *ONSError

NewONSError creates a new ONS error

func (*ONSError) AddParameter

func (e *ONSError) AddParameter(name string, value interface{}) *ONSError

AddParameter method creates or overwrites parameters attatched to an ONSError

func (ONSError) Error

func (e ONSError) Error() string

Error returns the ONSError RootError message

type Params

type Params map[string]string

Params represents a generic map of key value pairs

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 RCHTTPClienter

type RCHTTPClienter interface {
	SetAuthToken(token string)
	SetDownloadServiceToken(token string)
	SetTimeout(timeout time.Duration)
	SetMaxRetries(int)
	GetMaxRetries() int

	Get(ctx context.Context, url string) (*http.Response, error)
	Head(ctx context.Context, url string) (*http.Response, error)
	Post(ctx context.Context, url string, contentType string, body io.Reader) (*http.Response, error)
	Put(ctx context.Context, url string, contentType string, body io.Reader) (*http.Response, error)
	PostForm(ctx context.Context, uri string, data url.Values) (*http.Response, error)

	Do(ctx context.Context, req *http.Request) (*http.Response, error)
}

RCHTTPClienter provides an interface for methods on an HTTP Client

Directories

Path Synopsis
Package mock_common is a generated GoMock package.
Package mock_common is a generated GoMock package.

Jump to

Keyboard shortcuts

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