httphandling

package
v0.0.0-...-50dd056 Latest Latest
Warning

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

Go to latest
Published: Feb 17, 2018 License: Apache-2.0 Imports: 27 Imported by: 0

README

Code Flow and Logic

  • Call to NewRouter() to get the mux.Router
    • For each API namespace - call addRoutes() method using the getRoutes methods to get a map of routes...
      • For each route in the namespaces map of routes...
        • Map provides a handler func
        • Map indicates if the func requires authentication
        • Call WrapCommonHandler()
          • If authentication enabled wrap the namespace's handler func in the AuthnHandler
            • Wrap the handler func in the accessLogger handler
          • Return a handler that first sets standard response headers and then calls the wrapped up handler function's ServeHTTP method

Execution Order

The above wrapping results in the following execution order:

# Step Handler/Method Source File
1 Set the standard response HTTP headers on the responseWriter setHeaders handler.go
2 Get the start time of the operation accessLogger logging.go
3 Wrap the responseWriter to be able to get the final HTTP status code returned to the client NewResponseWriterWrapper responseWriter.go
4 If authentication is on for the operation on this part of the namespace call the ServeHTTP on the AuthnHandler function AuthnHandler authn.go
5 Call the ServeHTTP method of the namespace's handler function various from namespace depending on the path and method of the request various
6 Return to the accessLogger function to actually write the log line accessLogger logging.go

Documentation

Index

Constants

View Source
const (
	MuxVarAccountID = "accountID"
	AccountAPI      = "account"
	AccountGETTmpl  = "" /* 194-byte string literal not displayed */
	AccountPOSTTmpl = "{\"ID\":\"%s\",\"Email\":\"%s\",\"Name\":\"%s\",\"Type\":{\"ID\":%d},\"Status\":{\"ID\":%d},\"FederationUserARN\":\"%s\"}"
)
View Source
const (
	MuxVarAccountClassID = "accountClassID"
	AccountClassAPI      = "accountclass"
	AccountClassPOSTTmpl = "{\"Class\":\"%s\"}"
	AccountClassPUTTmpl  = "{\"ID\":%d,\"Class\":\"%s\"}"
)
View Source
const (
	MuxVarAccountStatusID = "accountStatusID"
	AccountStatusAPI      = "accountstatus"
	AccountStatusPOSTTmpl = "{\"Status\":\"%s\"}"
	AccountStatusPUTTmpl  = "{\"ID\":%d,\"Status\":\"%s\"}"
)
View Source
const (
	MuxVarAccountTypeID = "accountTypeID"
	AccountTypeAPI      = "accounttype"
	AccountTypeGETTmpl  = "{\"ID\":%d,\"Type\":\"%s\",\"Class\":{\"ID\":%d}}"
	AccountTypePOSTTmpl = "{\"Type\":\"%s\",\"Class\":{\"ID\":%d}}"
	AccountTypePUTTmpl  = "{\"ID\":%d,\"Type\":\"%s\",\"Class\":{\"ID\":%d}}"
)
View Source
const (
	AuthMechanismNegotiate = "Negotiate"
	AuthMechanismBasic     = "Basic"
	AuthMechanismBearer    = "Bearer"
)
View Source
const (
	MuxVarUsername             = "username"
	FederationUserAPI          = "federationuser"
	FederationUserResponseTmpl = "" /* 221-byte string literal not displayed */
	FederationUserPOSTTmpl     = "" /* 205-byte string literal not displayed */
)
View Source
const (
	FilterAuthz         = "authz"
	FilterARN           = "arn"
	FilterAccountIDs    = "account"
	RoleMappingAPI      = "rolemapping"
	RoleMappingPOSTTmpl = "{\"RoleARN\":\"%s\",\"AuthzAttribute\":\"%s\"}"
	RoleMappingPUTTmpl  = "{\"ID\":\"%s\",\"RoleARN\":\"%s\",\"AuthzAttribute\":\"%s\"}"
	RoleMappingGETTmpl  = "{\"ID\":\"%s\",\"RoleARN\":\"%s\",\"AuthzAttribute\":\"%s\",\"AccountID\":\"%s\"}"
)
View Source
const (
	APIVersion = "v1"
)
View Source
const (
	MuxVarRoleUUID = "roleUUID"
)

Variables

This section is empty.

Functions

func AuthnHandler

func AuthnHandler(inner http.Handler, c *config.Config) http.Handler

func GetIdentity

func GetIdentity(ctx context.Context) (id goidentity.Identity, err error)

func MethodNotAllowed

func MethodNotAllowed() http.HandlerFunc

func NewRouter

func NewRouter(c *config.Config, stmtMap *database.StmtMap, fc *federationuser.FedUserCache) *mux.Router

func ParseAuthorizationHeader

func ParseAuthorizationHeader(r *http.Request) (mechanism, value string, err error)

func ParseBasicHeaderValue

func ParseBasicHeaderValue(s string) (domain, username, password string, err error)

func WrapCommonHandler

func WrapCommonHandler(inner http.Handler, authn bool, c *config.Config) http.Handler

Types

type AccessLog

type AccessLog struct {
	SourceIP    string        `json:"SourceIP"`
	Username    string        `json:"Username"`
	UserDomain  string        `json:"UserRealm"`
	StatusCode  int           `json:"StatusCode"`
	Method      string        `json:"Method"`
	ServerHost  string        `json:"ServerHost"`
	Path        string        `json:"Path"`
	QueryString string        `json:"QueryString"`
	Time        time.Time     `json:"Time"`
	Duration    time.Duration `json:"Duration"`
}

type JSONCreatedResponse

type JSONCreatedResponse struct {
	CreatedEntity   string
	Message         string
	HTTPCode        int
	ApplicationCode int
}

type JSONGenericResponse

type JSONGenericResponse struct {
	Message         string
	HTTPCode        int
	ApplicationCode int
}

type LDAPBasicAuthenticator

type LDAPBasicAuthenticator struct {
	BasicHeaderValue string

	LDAPConfig config.LDAPBasic
	// contains filtered or unexported fields
}

func (LDAPBasicAuthenticator) Authenticate

func (a LDAPBasicAuthenticator) Authenticate() (i goidentity.Identity, ok bool, err error)

func (LDAPBasicAuthenticator) Mechanism

func (a LDAPBasicAuthenticator) Mechanism() string

type ResponseWriterWrapper

type ResponseWriterWrapper struct {
	http.ResponseWriter
	// contains filtered or unexported fields
}

func NewResponseWriterWrapper

func NewResponseWriterWrapper(w http.ResponseWriter) *ResponseWriterWrapper

func (*ResponseWriterWrapper) Status

func (w *ResponseWriterWrapper) Status() int

func (*ResponseWriterWrapper) Write

func (w *ResponseWriterWrapper) Write(p []byte) (n int, err error)

func (*ResponseWriterWrapper) WriteHeader

func (w *ResponseWriterWrapper) WriteHeader(code int)

type Route

type Route struct {
	Method         string
	Pattern        string
	Name           string
	Authentication bool
	HandlerFunc    http.HandlerFunc
}

type StaticAuthenticator

type StaticAuthenticator struct {
	BasicHeaderValue string

	RequiredSecret  string
	StaticAttribute string
	// contains filtered or unexported fields
}

StaticAuthenticator is mainly for testing purposes. Do not use in production.

func (StaticAuthenticator) Authenticate

func (a StaticAuthenticator) Authenticate() (i goidentity.Identity, ok bool, err error)

func (StaticAuthenticator) Mechanism

func (a StaticAuthenticator) Mechanism() string

Jump to

Keyboard shortcuts

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