hoverfly

package
v0.9.2 Latest Latest
Warning

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

Go to latest
Published: Dec 2, 2016 License: Apache-2.0 Imports: 39 Imported by: 1

Documentation

Index

Constants

View Source
const (
	HoverflyAuthEnabledEV     = "HoverflyAuthEnabled"
	HoverflySecretEV          = "HoverflySecret"
	HoverflyTokenExpirationEV = "HoverflyTokenExpiration"

	HoverflyAdminPortEV = "AdminPort"
	HoverflyProxyPortEV = "ProxyPort"

	HoverflyDBEV         = "HoverflyDB"
	HoverflyMiddlewareEV = "HoverflyMiddleware"

	HoverflyTLSVerification = "HoverflyTlsVerification"

	HoverflyAdminUsernameEV = "HoverflyAdmin"
	HoverflyAdminPasswordEV = "HoverflyAdminPass"

	HoverflyImportRecordsEV = "HoverflyImport"
)

Environment variables

View Source
const ActionTypeConfigurationChanged = "configurationChanged"

ActionTypeConfigurationChanged - default action name for identifying configuration changes

View Source
const ActionTypeRequestCaptured = "requestCaptured"

ActionTypeRequestCaptured - default action type name for identifying

View Source
const ActionTypeWipeDB = "wipeDatabase"

ActionTypeWipeDB - default action type for wiping database

View Source
const CaptureMode = "capture"

CaptureMode - requests are captured and stored in cache

View Source
const DefaultAdminPort = "8888"

DefaultAdminPort - default admin interface port

View Source
const DefaultDatabasePath = "requests.db"

DefaultDatabasePath - default database name that will be created or used by Hoverfly

View Source
const DefaultJWTExpirationDelta = 1 * 24 * 60 * 60

DefaultJWTExpirationDelta - default token expiration if environment variable is no provided

View Source
const DefaultPort = "8500"

DefaultPort - default proxy port

View Source
const ModifyMode = "modify"

ModifyMode - middleware is applied to outgoing and incoming traffic

View Source
const SimulateMode = "simulate"

SimulateMode - default mode when Hoverfly looks for captured requests to respond

View Source
const SynthesizeMode = "synthesize"

SynthesizeMode - all requests are sent to middleware to create response

View Source
const URL string = `` /* 321-byte string literal not displayed */

URL is regexp to match http urls

Variables

View Source
var TestDB *bolt.DB

TestDB - holds connection to database during tests

Functions

func ExecuteMiddlewareLocally added in v0.8.0

func ExecuteMiddlewareLocally(middlewares string, pair models.RequestResponsePair) (models.RequestResponsePair, error)

ExecuteMiddleware - takes command (middleware string) and payload, which is passed to middleware

func ExecuteMiddlewareRemotely added in v0.8.0

func ExecuteMiddlewareRemotely(middleware string, pair models.RequestResponsePair) (models.RequestResponsePair, error)

func GetAllHandlers added in v0.9.0

func GetAllHandlers(hoverfly *Hoverfly) []handlers.AdminHandler

func GetDefaultHoverflyHTTPClient added in v0.9.0

func GetDefaultHoverflyHTTPClient(tlsVerification bool) *http.Client

func GetRandomName

func GetRandomName(n int) []byte

GetRandomName - provides random name for buckets. Each test case gets it's own bucket

func NewProxy

func NewProxy(hoverfly *Hoverfly) *goproxy.ProxyHttpServer

Creates goproxy.ProxyHttpServer and configures it to be used as a proxy for Hoverfly goproxy is given handlers that use the Hoverfly request processing

func NewWebserverProxy

func NewWebserverProxy(hoverfly *Hoverfly) *goproxy.ProxyHttpServer

Creates goproxy.ProxyHttpServer and configures it to be used as a webserver for Hoverfly goproxy is given a non proxy handler that uses the Hoverfly request processing

func Pipeline

func Pipeline(cmds ...*exec.Cmd) (pipeLineOutput, collectedStandardError []byte, pipeLineError error)

Pipeline - to provide input to the pipeline, assign an io.Reader to the first's Stdin.

func SynthesizeResponse

func SynthesizeResponse(req *http.Request, requestDetails models.RequestDetails, middleware string) (*http.Response, error)

SynthesizeResponse calls middleware to populate response data, nothing gets pass proxy

Types

type ActionType

type ActionType string

ActionType - action type can be things such as "RequestCaptured", "GotResponse" - anything

type ActionTypeHooks

type ActionTypeHooks map[ActionType][]Hook

ActionTypeHooks type for storing the hooks

func (ActionTypeHooks) Add

func (hooks ActionTypeHooks) Add(hook Hook)

Add a hook

func (ActionTypeHooks) Fire

func (hooks ActionTypeHooks) Fire(ac ActionType, entry *Entry) error

Fire all the hooks for the passed ActionType

type AdminApi added in v0.9.0

type AdminApi struct{}

func (*AdminApi) StartAdminInterface added in v0.9.0

func (this *AdminApi) StartAdminInterface(hoverfly *Hoverfly)

StartAdminInterface - starts admin interface web server

type Client

type Client struct {
	HTTPClient *http.Client
}

Client structure to be injected into functions to perform HTTP calls

type Configuration

type Configuration struct {
	AdminPort    string
	ProxyPort    string
	Mode         string
	Destination  string
	Middleware   string
	DatabasePath string
	Webserver    bool

	TLSVerification bool

	Verbose     bool
	Development bool

	SecretKey          []byte
	JWTExpirationDelta int
	AuthEnabled        bool

	ProxyControlWG sync.WaitGroup
	// contains filtered or unexported fields
}

Configuration - initial structure of configuration

func InitSettings

func InitSettings() *Configuration

InitSettings gets and returns initial configuration from env variables or sets defaults

func (*Configuration) GetMode

func (c *Configuration) GetMode() string

GetMode - provides safe way to get current mode

func (*Configuration) SetMode

func (c *Configuration) SetMode(mode string)

SetMode - provides safe way to set new mode

type Constructor

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

Constructor - holds information about original request (which is needed to create response and also holds payload

func NewConstructor

func NewConstructor(req *http.Request, pair models.RequestResponsePair) *Constructor

NewConstructor - returns constructor instance

func (*Constructor) ApplyMiddleware

func (c *Constructor) ApplyMiddleware(middleware string) error

ApplyMiddleware - activates given middleware, middleware should be passed as string to executable, can be full path.

func (*Constructor) ReconstructRequest

func (c *Constructor) ReconstructRequest() (*http.Request, error)

ReconstructRequest replaces original request with details provided in Constructor Payload.Request

func (*Constructor) ReconstructResponse

func (c *Constructor) ReconstructResponse() *http.Response

ReconstructResponse changes original response with details provided in Constructor Payload.Response

type Entry

type Entry struct {
	// Contains encoded data
	Data []byte

	// Time at which the action entry was fired
	Time time.Time

	ActionType ActionType

	// Message, can carry additional information
	Message string
}

Entry - holds information about action, based on action type - other clients will be able to decode the data field.

type Hook

type Hook interface {
	ActionTypes() []ActionType
	Fire(*Entry) error
}

Hook - an interface to add dynamic hooks to extend functionality

type Hoverfly

type Hoverfly struct {
	RequestCache   cache.Cache
	RequestMatcher matching.RequestMatcher
	MetadataCache  cache.Cache
	Authentication authBackend.Authentication
	HTTP           *http.Client
	Cfg            *Configuration
	Counter        *metrics.CounterByMode
	Hooks          ActionTypeHooks

	ResponseDelays models.ResponseDelays

	Proxy *goproxy.ProxyHttpServer
	SL    *StoppableListener
	// contains filtered or unexported fields
}

Hoverfly provides access to hoverfly - updating/starting/stopping proxy, http client and configuration, cache access

func GetNewHoverfly

func GetNewHoverfly(cfg *Configuration, requestCache, metadataCache cache.Cache, authentication authBackend.Authentication) *Hoverfly

GetNewHoverfly returns a configured ProxyHttpServer and DBClient

func (*Hoverfly) AddHook

func (hf *Hoverfly) AddHook(hook Hook)

AddHook - adds a hook to DBClient

func (Hoverfly) DeleteRequestCache added in v0.9.0

func (hf Hoverfly) DeleteRequestCache() error

func (*Hoverfly) DeleteResponseDelays added in v0.9.0

func (hf *Hoverfly) DeleteResponseDelays()

func (*Hoverfly) DeleteSimulation added in v0.9.0

func (this *Hoverfly) DeleteSimulation()

func (*Hoverfly) DeleteTemplateCache added in v0.9.0

func (this *Hoverfly) DeleteTemplateCache()

func (Hoverfly) GetDestination added in v0.9.0

func (this Hoverfly) GetDestination() string

func (Hoverfly) GetMetadataCache added in v0.9.0

func (this Hoverfly) GetMetadataCache() cache.Cache

func (Hoverfly) GetMiddleware added in v0.9.0

func (hf Hoverfly) GetMiddleware() string

func (Hoverfly) GetMode added in v0.9.0

func (this Hoverfly) GetMode() string

func (Hoverfly) GetRecords added in v0.9.0

func (hf Hoverfly) GetRecords() ([]v1.RequestResponsePairView, error)

func (Hoverfly) GetRequestCacheCount added in v0.9.0

func (hf Hoverfly) GetRequestCacheCount() (int, error)

func (*Hoverfly) GetResponseDelays added in v0.9.0

func (hf *Hoverfly) GetResponseDelays() v1.ResponseDelayPayloadView

func (Hoverfly) GetSimulation added in v0.9.0

func (hf Hoverfly) GetSimulation() (v2.SimulationView, error)

func (Hoverfly) GetStats added in v0.9.0

func (hf Hoverfly) GetStats() metrics.Stats

func (Hoverfly) GetTemplates added in v0.9.0

func (this Hoverfly) GetTemplates() v1.RequestTemplateResponsePairPayload

func (*Hoverfly) Import

func (hf *Hoverfly) Import(uri string) error

Import is a function that based on input decides whether it is a local resource or whether it should fetch it from remote server. It then imports given payload into the database or returns an error

func (*Hoverfly) ImportFromDisk

func (hf *Hoverfly) ImportFromDisk(path string) error

ImportFromDisk - takes one string value and tries to open a file, then parse it into recordedRequests structure (which is default format in which Hoverfly exports captured requests) and imports those requests into the database

func (*Hoverfly) ImportFromURL

func (hf *Hoverfly) ImportFromURL(url string) error

ImportFromURL - takes one string value and tries connect to a remote server, then parse response body into recordedRequests structure (which is default format in which Hoverfly exports captured requests) and imports those requests into the database

func (*Hoverfly) ImportRequestResponsePairViews added in v0.8.1

func (hf *Hoverfly) ImportRequestResponsePairViews(pairViews []interfaces.RequestResponsePair) error

ImportRequestResponsePairViews - a function to save given pairs into the database.

func (*Hoverfly) ImportTemplates added in v0.9.0

func (this *Hoverfly) ImportTemplates(pairPayload v1.RequestTemplateResponsePairPayload) error

func (*Hoverfly) PutSimulation added in v0.9.0

func (this *Hoverfly) PutSimulation(simulationView v2.SimulationView) error

func (*Hoverfly) SetDestination added in v0.9.0

func (hf *Hoverfly) SetDestination(destination string) (err error)

UpdateDestination - updates proxy with new destination regexp

func (Hoverfly) SetMiddleware added in v0.8.0

func (hf Hoverfly) SetMiddleware(middleware string) error

func (*Hoverfly) SetMode added in v0.9.0

func (this *Hoverfly) SetMode(mode string) error

func (*Hoverfly) SetResponseDelays added in v0.9.0

func (hf *Hoverfly) SetResponseDelays(payloadView v1.ResponseDelayPayloadView) error

func (*Hoverfly) StartProxy

func (hf *Hoverfly) StartProxy() error

StartProxy - starts proxy with current configuration, this method is non blocking.

func (*Hoverfly) StopProxy

func (hf *Hoverfly) StopProxy()

StopProxy - stops proxy

type StoppableListener

type StoppableListener struct {
	*net.TCPListener
	// contains filtered or unexported fields
}

StoppableListener - wrapper for tcp listener that can stop

func NewStoppableListener

func NewStoppableListener(l net.Listener) (*StoppableListener, error)

NewStoppableListener returns new StoppableListener listener

func (*StoppableListener) Accept

func (sl *StoppableListener) Accept() (net.Conn, error)

Accept - TCPListener waits for the next call, implements default interface method

func (*StoppableListener) Stop

func (sl *StoppableListener) Stop()

Stop - stops listener

Directories

Path Synopsis
cmd
examples
v1
v2

Jump to

Keyboard shortcuts

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