http

package
v0.0.0-...-72724d7 Latest Latest
Warning

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

Go to latest
Published: Jun 8, 2020 License: Apache-2.0 Imports: 13 Imported by: 0

Documentation

Index

Constants

View Source
const (

	// HeaderContent is constant extracted value of Content-Type header
	HeaderContent = "Content-Type"
	// HeaderAccept is constant extracted value of Accept header
	HeaderAccept = "Accept"

	// MimeText is constant extracted value of mimetype for text
	MimeText = "text/plain"
	// MimeJSON is constant extracted value of mimetype for text
	MimeJSON = "application/json"

	// FmtErr is yubico format for text error response
	FmtErr = "ERR %s"
)

Variables

View Source
var (
	// ErrSkip is the error used to notify that error has been handled
	ErrSkip = fmt.Errorf("error already handled")
)

Functions

func DefaultErrorHandler

func DefaultErrorHandler(ctx *Context, err error)

DefaultErrorHandler is the default way of dealing with error in Yubistack. It maps error returned by the caller in Yubico text equivalent responses

Types

type AuthHandler

type AuthHandler struct {
	AuthentifierFactory
	AuthorizerFactory
}

AuthHandler is a structure embedding authentication and authorization and serving it as http

func NewAuthHandler

func NewAuthHandler(options ...func(handler *AuthHandler)) *AuthHandler

NewAuthHandler creates a new AuthHandler with sensible defaults

func (*AuthHandler) Handle

func (ah *AuthHandler) Handle(ctx *Context) error

Handle implements the pkg.Handle interface and perform authenticate and authorize over http.

type AuthentifierFactory

type AuthentifierFactory func(zerolog.Logger) ykauth.Authentifier

AuthentifierFactory is currying an Authentifier to inject a logger on each request

type AuthorizerFactory

type AuthorizerFactory func(zerolog.Logger) ykauth.Authorizer

AuthorizerFactory is currying an Authorizer to inject a logger on each request

type ClientLoaderFactory

type ClientLoaderFactory func(zerolog.Logger) yubico.ClientLoader

ClientLoaderFactory is currying a ClientLodaer to inject a logger on each request

type Context

type Context struct {
	*Response
	*http.Request
	zerolog.Logger
}

Context wraps most of the structures we want to pass down to the Handler It contains the stdlib ServeHTTP arguments: Request, Response and is enhanced with other services, for the moment only the Logger, but some may be added later (like DB or so).

func (*Context) Error

func (c *Context) Error(msg string, code int) error

Error function allow to quickly define an error response

func (*Context) RemoteHost

func (c *Context) RemoteHost() string

RemoteHost get the value of the host without the port

func (*Context) Writef

func (c *Context) Writef(format string, a ...interface{})

Writef creates a text response and write it to the buffer with format

type DecryptHandler

type DecryptHandler struct {
	ykksm.DecrypterFactory
}

DecryptHandler is a structure embedding a DecrypterFactory and serving it as http

func NewDecryptHandler

func NewDecryptHandler(options ...func(handler *DecryptHandler)) *DecryptHandler

NewDecryptHandler creates a new DecryptHandler with sensible defaults

func (*DecryptHandler) Handle

func (dh *DecryptHandler) Handle(ctx *Context) error

Handle implements the pkg.Handle interface and decrypt a token over http.

type ErrorHandler

type ErrorHandler func(*Context, error)

ErrorHandler is the function type we will use to customize error handling

type Handler

type Handler interface {
	Handle(*Context) error
}

Handler is an interface we will use to handle HTTP requests

type HandlerFunc

type HandlerFunc func(*Context) error

HandlerFunc is a wrapper for a function to implement the Handler interface

func (HandlerFunc) Handle

func (hf HandlerFunc) Handle(ctx *Context) error

Handle wraps a function to implement Handler interface

type Middleware

type Middleware func(HandlerFunc) HandlerFunc

Middleware is the function type we will use to chain middleware in the application

type Response

type Response struct {
	Code   int
	Header http.Header
	*bytes.Buffer
	// contains filtered or unexported fields
}

Response wraps the stdlib ResponseWriter interface. It allows to keep some states before writing them to the underlying ResponseWriter where this information can't be retrieved once pushed. The state is pushed by the Context.write() function which is not accessible through the public API.

func NewResponse

func NewResponse(w http.ResponseWriter) *Response

NewResponse creates a new instance of a response with default OK state

type Server

type Server struct {
	*http.Server
	zerolog.Logger
	ErrorHandler
	// contains filtered or unexported fields
}

Server wraps the serving logic

func NewServer

func NewServer(options ...ServerOption) *Server

NewServer creates an instance of a server using option parameters to configure.

func (*Server) Handle

func (s *Server) Handle(path string, handler Handler)

Handle add a handler to a specific path

func (*Server) HandleFunc

func (s *Server) HandleFunc(path string, handle HandlerFunc)

HandleFunc add a handler function to a specific path

func (*Server) ListenAndServe

func (s *Server) ListenAndServe() error

ListenAndServe starts a server on the configured addressed over TCP

func (*Server) Serve

func (s *Server) Serve(network, address string) error

Serve starts a server on the given network and address and route request to handlers

func (*Server) Use

func (s *Server) Use(middlewares ...Middleware)

Use plugs a middleware in the request handling chain

type ServerOption

type ServerOption func(*Server)

ServerOption is the function type used to customize the Server fields at creation

func WithTLS

func WithTLS(certFile, keyFile string) ServerOption

WithTLS creates a ServerOption setting up TLS options

type SyncHandler

type SyncHandler struct {
	ykval.SynchronizerFactory
	ClientLoaderFactory
}

SyncHandler is a structure embedding a SynchronizerFactory and serving it as http

func NewSyncHandler

func NewSyncHandler(options ...func(handler *SyncHandler)) *SyncHandler

NewSyncHandler creates a new SyncHandler with sensible defaults

func (*SyncHandler) Handle

func (sh *SyncHandler) Handle(ctx *Context) error

Handle implements the pkg.Handle interface and synchronize a token over http.

type VerifyHandler

type VerifyHandler struct {
	ykval.VerifierFactory
	ClientLoaderFactory
}

VerifyHandler is a http.Handler responsible for the verification of tokens

func NewVerifyHandler

func NewVerifyHandler(options ...func(handler *VerifyHandler)) *VerifyHandler

NewVerifyHandler creates a new VerifyHandler with sensible defaults

func (*VerifyHandler) Handle

func (vh *VerifyHandler) Handle(ctx *Context) error

Handle implements the pkg.Handle interface and verify a token over http.

Jump to

Keyboard shortcuts

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