identity

package
v0.3.0 Latest Latest
Warning

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

Go to latest
Published: Jul 3, 2020 License: Apache-2.0 Imports: 11 Imported by: 6

Documentation

Overview

Package identity extracts the callers contextual identity information from the HTTP/TLS requests and exposes them for access via the generalized go context model.

Index

Constants

View Source
const GuestRoleName = "guest"

GuestRoleName is default role name for guest

Variables

This section is empty.

Functions

func AddToContext

func AddToContext(ctx context.Context, rq *RequestContext) context.Context

AddToContext returns a new golang context that adds `rq` as the dolly request context.

func ClientIPFromRequest

func ClientIPFromRequest(r *http.Request) string

ClientIPFromRequest return client's real public IP address from http request headers.

func NewContextHandler

func NewContextHandler(delegate http.Handler) http.Handler

NewContextHandler returns a handler that will extact the role & contextID from the request and stash them away in the request context for later handlers to use. Also adds header to indicate which host is currently servicing the request

func SetGlobalIdentityMapper

func SetGlobalIdentityMapper(e Mapper)

SetGlobalIdentityMapper applies global IdentityMapper for the application

func SetGlobalNodeInfo

func SetGlobalNodeInfo(n netutil.NodeInfo)

SetGlobalNodeInfo applies NodeInfo for the application

func WithTestIdentity

func WithTestIdentity(r *http.Request, identity Identity) *http.Request

WithTestIdentity is used in unit tests to set HTTP request identity

Types

type Context

type Context interface {
	Identity() Identity
	CorrelationID() string
	ClientIP() string
}

Context represents user contextual information about a request being processed by the server, it includes identity, CorrelationID [for cross system request correlation].

type Identity

type Identity interface {
	String() string
	UserID() string
	Role() string
	Name() string
	UserInfo() interface{}
}

Identity contains information about the identity of an API caller

func GuestIdentityMapper

func GuestIdentityMapper(r *http.Request) (Identity, error)

GuestIdentityMapper always returns "guest" for the role

func NewIdentity

func NewIdentity(role, name, userID string) Identity

NewIdentity returns a new Identity instance with the indicated role

func NewIdentityWithUserInfo

func NewIdentityWithUserInfo(role, name, userID string, userInfo interface{}) Identity

NewIdentityWithUserInfo returns a new Identity instance with the indicated role and user info

type Mapper

type Mapper func(*http.Request) (Identity, error)

Mapper returns Identity from supplied HTTP request

type RequestContext

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

RequestContext represents user contextual information about a request being processed by the server, it includes identity, CorrelationID [for cross system request correlation].

func ForRequest

func ForRequest(r *http.Request) *RequestContext

ForRequest returns the full context ascocicated with this http request.

func FromContext

func FromContext(ctx context.Context) *RequestContext

FromContext extracts the RequestContext stored inside a go context. Returns null if no such value exists.

func NewRequestContext

func NewRequestContext(id Identity) *RequestContext

NewRequestContext creates a request context with a specific identity.

func (*RequestContext) ClientIP

func (c *RequestContext) ClientIP() string

ClientIP returns request's IP

func (*RequestContext) CorrelationID

func (c *RequestContext) CorrelationID() string

CorrelationID returns request's CorrelationID, extracted from X-CorrelationID header. If it was not provided by the client, the a random will be generated.

func (*RequestContext) Identity

func (c *RequestContext) Identity() Identity

Identity returns request's identity

Jump to

Keyboard shortcuts

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