Documentation ¶
Index ¶
- Constants
- Variables
- func GetDB(name string) *bolt.DB
- func GetRandomName(n int) []byte
- func Pipeline(cmds ...*exec.Cmd) (pipeLineOutput, collectedStandardError []byte, pipeLineError error)
- func SynthesizeResponse(req *http.Request, middleware string) (*http.Response, error)
- type ActionType
- type ActionTypeHooks
- type BoltCache
- func (c *BoltCache) CloseDB()
- func (c *BoltCache) DeleteBucket(name []byte) (err error)
- func (c *BoltCache) DeleteData() error
- func (c *BoltCache) Get(key []byte) (value []byte, err error)
- func (c *BoltCache) GetAllKeys() (keys map[string]bool, err error)
- func (c *BoltCache) GetAllRequests() (payloads []Payload, err error)
- func (c *BoltCache) RecordsCount() (count int, err error)
- func (c *BoltCache) Set(key, value []byte) error
- type BoltMeta
- type Cache
- type Client
- type Configuration
- type Constructor
- type CounterByMode
- type DBClient
- func (d *DBClient) AddHook(hook Hook)
- func (d *DBClient) AllMetadataHandler(w http.ResponseWriter, req *http.Request, next http.HandlerFunc)
- func (d *DBClient) AllRecordsHandler(w http.ResponseWriter, req *http.Request, next http.HandlerFunc)
- func (d *DBClient) CurrentStateHandler(w http.ResponseWriter, req *http.Request, next http.HandlerFunc)
- func (d *DBClient) DeleteAllRecordsHandler(w http.ResponseWriter, req *http.Request, next http.HandlerFunc)
- func (d *DBClient) DeleteMetadataHandler(w http.ResponseWriter, req *http.Request, next http.HandlerFunc)
- func (d *DBClient) Import(uri string) error
- func (d *DBClient) ImportFromDisk(path string) error
- func (d *DBClient) ImportFromURL(url string) error
- func (d *DBClient) ImportPayloads(payloads []Payload) error
- func (d *DBClient) ImportRecordsHandler(w http.ResponseWriter, req *http.Request, next http.HandlerFunc)
- func (d *DBClient) ManualAddHandler(w http.ResponseWriter, req *http.Request, next http.HandlerFunc)
- func (d *DBClient) RecordsCount(w http.ResponseWriter, req *http.Request, next http.HandlerFunc)
- func (d *DBClient) SetMetadataHandler(w http.ResponseWriter, req *http.Request, next http.HandlerFunc)
- func (d *DBClient) StartAdminInterface()
- func (d *DBClient) StateHandler(w http.ResponseWriter, r *http.Request, next http.HandlerFunc)
- func (d *DBClient) StatsHandler(w http.ResponseWriter, req *http.Request, next http.HandlerFunc)
- func (d *DBClient) StatsWSHandler(w http.ResponseWriter, r *http.Request)
- type Entry
- type Hook
- type MetaObject
- type Metadata
- type Payload
- type RequestContainer
- type RequestDetails
- type ResponseDetails
- type Stats
Constants ¶
const ( HoverflyAuthEnabledEV = "HoverflyAuthEnabled" HoverflySecretEV = "HoverflySecret" HoverflyTokenExpirationEV = "HoverflyTokenExpiration" HoverflyAdminPortEV = "AdminPort" HoverflyProxyPortEV = "ProxyPort" HoverflyDBEV = "HoverflyDB" HoverflyMiddlewareEV = "HoverflyMiddleware" )
Environment variables
const ActionTypeConfigurationChanged = "configurationChanged"
ActionTypeConfigurationChanged - default action name for identifying configuration changes
const ActionTypeRequestCaptured = "requestCaptured"
ActionTypeRequestCaptured - default action type name for identifying
const ActionTypeWipeDB = "wipeDatabase"
ActionTypeWipeDB - default action type for wiping database
const CaptureMode = "capture"
CaptureMode - requests are captured and stored in cache
const DefaultAdminPort = "8888"
DefaultAdminPort - default admin interface port
const DefaultDatabaseName = "requests.db"
DefaultDatabaseName - default database name that will be created or used by Hoverfly
const DefaultJWTExpirationDelta = 72
DefaultJWTExpirationDelta - default token expiration if environment variable is no provided
const DefaultPort = "8500"
DefaultPort - default proxy port
const MetadataBucketName = "metadataBucket"
MetadataBucketName - default bucket name for storing metadata in boltdb
const ModifyMode = "modify"
ModifyMode - middleware is applied to outgoing and incoming traffic
const RequestsBucketName = "rqbucket"
RequestsBucketName - default name for BoltDB bucket
const SynthesizeMode = "synthesize"
SynthesizeMode - all requests are sent to middleware to create response
const URL string = `` /* 321-byte string literal not displayed */
URL is regexp to match http urls
const VirtualizeMode = "virtualize"
VirtualizeMode - default mode when Hoverfly looks for captured requests to respond
Variables ¶
var TestDB *bolt.DB
TestDB - holds connection to database during tests
Functions ¶
func GetDB ¶ added in v0.5.10
GetDB - returns open BoltDB database with read/write permissions or goes down in flames if something bad happends
func GetRandomName ¶ added in v0.5.1
GetRandomName - provides random name for buckets. Each test case gets it's own bucket
Types ¶
type ActionType ¶ added in v0.5.11
type ActionType string
ActionType - action type can be things such as "RequestCaptured", "GotResponse" - anything
type ActionTypeHooks ¶ added in v0.5.11
type ActionTypeHooks map[ActionType][]Hook
ActionTypeHooks type for storing the hooks
func (ActionTypeHooks) Add ¶ added in v0.5.11
func (hooks ActionTypeHooks) Add(hook Hook)
Add a hook
func (ActionTypeHooks) Fire ¶ added in v0.5.11
func (hooks ActionTypeHooks) Fire(ac ActionType, entry *Entry) error
Fire all the hooks for the passed ActionType
type BoltCache ¶ added in v0.5.11
BoltCache - container to implement Cache instance with BoltDB backend for storage
func NewBoltDBCache ¶ added in v0.5.11
NewBoltDBCache - returns new BoltCache instance
func (*BoltCache) CloseDB ¶ added in v0.5.11
func (c *BoltCache) CloseDB()
CloseDB - closes database
func (*BoltCache) DeleteBucket ¶ added in v0.5.11
DeleteBucket - deletes bucket with all saved data
func (*BoltCache) DeleteData ¶ added in v0.5.11
DeleteData - deletes bucket with all saved data
func (*BoltCache) Get ¶ added in v0.5.11
Get - searches for given key in the cache and returns value if found
func (*BoltCache) GetAllKeys ¶ added in v0.5.11
GetAllKeys - gets all current keys
func (*BoltCache) GetAllRequests ¶ added in v0.5.11
GetAllRequests - returns all captured requests/responses
func (*BoltCache) RecordsCount ¶ added in v0.5.11
RecordsCount - returns records count
type BoltMeta ¶ added in v0.5.13
BoltMeta - metadata backend that uses BoltDB
func NewBoltDBMetadata ¶ added in v0.5.13
NewBoltDBMetadata - default metadata store
func (*BoltMeta) DeleteData ¶ added in v0.5.13
DeleteData - deletes bucket with all saved data
func (*BoltMeta) GetAll ¶ added in v0.5.13
func (m *BoltMeta) GetAll() (objects []MetaObject, err error)
GetAll - returns all key/value pairs
type Cache ¶
type Cache interface { Set(key, value []byte) error Get(key []byte) ([]byte, error) GetAllRequests() ([]Payload, error) RecordsCount() (int, error) DeleteData() error GetAllKeys() (map[string]bool, error) CloseDB() }
Cache - cache interface used to store and retrieve request/response payloads or anything else
type Configuration ¶
type Configuration struct { AdminPort string ProxyPort string Mode string Destination string Middleware string DatabaseName string Verbose bool Development bool SecretKey []byte JWTExpirationDelta int AuthEnabled bool // contains filtered or unexported fields }
Configuration - initial structure of configuration
func InitSettings ¶ added in v0.5.3
func InitSettings() *Configuration
InitSettings gets and returns initial configuration from env variables or sets defaults
func (*Configuration) GetMode ¶ added in v0.5.3
func (c *Configuration) GetMode() (mode string)
GetMode - provides safe way to get current mode
func (*Configuration) SetMode ¶ added in v0.5.3
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, payload Payload) *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 ¶ added in v0.5.10
func (c *Constructor) ReconstructRequest() (*http.Request, error)
ReconstructRequest replaces original request with details provided in Constructor Payload.Request
func (*Constructor) ReconstructResponse ¶ added in v0.5.10
func (c *Constructor) ReconstructResponse() *http.Response
ReconstructResponse changes original response with details provided in Constructor Payload.Response
type CounterByMode ¶ added in v0.5.8
type CounterByMode struct {
// contains filtered or unexported fields
}
CounterByMode - container for mode counters, registry and flush interval
func NewModeCounter ¶ added in v0.5.8
func NewModeCounter() *CounterByMode
NewModeCounter - returns new counter instance
func (*CounterByMode) Count ¶ added in v0.5.8
func (c *CounterByMode) Count(mode string)
Count - counts requests based on mode
func (*CounterByMode) Flush ¶ added in v0.5.8
func (c *CounterByMode) Flush() (h Stats)
Flush gets current metrics from stats registry
func (*CounterByMode) Init ¶ added in v0.5.8
func (c *CounterByMode) Init()
Init initializes logging
type DBClient ¶
type DBClient struct { Cache Cache HTTP *http.Client Cfg *Configuration Counter *CounterByMode Hooks ActionTypeHooks AB backends.AuthBackend MD Metadata }
DBClient provides access to cache, http client and configuration
func GetNewHoverfly ¶ added in v0.5.10
func GetNewHoverfly(cfg *Configuration, cache Cache) (*goproxy.ProxyHttpServer, DBClient)
GetNewHoverfly returns a configured ProxyHttpServer and DBClient
func (*DBClient) AllMetadataHandler ¶ added in v0.5.13
func (d *DBClient) AllMetadataHandler(w http.ResponseWriter, req *http.Request, next http.HandlerFunc)
AllMetadataHandler returns JSON content type http response
func (*DBClient) AllRecordsHandler ¶
func (d *DBClient) AllRecordsHandler(w http.ResponseWriter, req *http.Request, next http.HandlerFunc)
AllRecordsHandler returns JSON content type http response
func (*DBClient) CurrentStateHandler ¶
func (d *DBClient) CurrentStateHandler(w http.ResponseWriter, req *http.Request, next http.HandlerFunc)
CurrentStateHandler returns current state
func (*DBClient) DeleteAllRecordsHandler ¶
func (d *DBClient) DeleteAllRecordsHandler(w http.ResponseWriter, req *http.Request, next http.HandlerFunc)
DeleteAllRecordsHandler - deletes all captured requests
func (*DBClient) DeleteMetadataHandler ¶ added in v0.5.13
func (d *DBClient) DeleteMetadataHandler(w http.ResponseWriter, req *http.Request, next http.HandlerFunc)
DeleteMetadataHandler - deletes all metadata
func (*DBClient) Import ¶ added in v0.5.12
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 (*DBClient) ImportFromDisk ¶ added in v0.5.12
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 (*DBClient) ImportFromURL ¶ added in v0.5.12
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 (*DBClient) ImportPayloads ¶ added in v0.5.12
ImportPayloads - a function to save given payloads into the database.
func (*DBClient) ImportRecordsHandler ¶
func (d *DBClient) ImportRecordsHandler(w http.ResponseWriter, req *http.Request, next http.HandlerFunc)
ImportRecordsHandler - accepts JSON payload and saves it to cache
func (*DBClient) ManualAddHandler ¶ added in v0.5.12
func (d *DBClient) ManualAddHandler(w http.ResponseWriter, req *http.Request, next http.HandlerFunc)
ManualAddHandler - manually add new request/responses, using a form
func (*DBClient) RecordsCount ¶ added in v0.5.1
func (d *DBClient) RecordsCount(w http.ResponseWriter, req *http.Request, next http.HandlerFunc)
RecordsCount returns number of captured requests as a JSON payload
func (*DBClient) SetMetadataHandler ¶ added in v0.5.13
func (d *DBClient) SetMetadataHandler(w http.ResponseWriter, req *http.Request, next http.HandlerFunc)
SetMetadataHandler - sets new metadata
func (*DBClient) StartAdminInterface ¶ added in v0.5.10
func (d *DBClient) StartAdminInterface()
StartAdminInterface - starts admin interface web server
func (*DBClient) StateHandler ¶ added in v0.5.7
func (d *DBClient) StateHandler(w http.ResponseWriter, r *http.Request, next http.HandlerFunc)
StateHandler handles current proxy state
func (*DBClient) StatsHandler ¶ added in v0.5.8
func (d *DBClient) StatsHandler(w http.ResponseWriter, req *http.Request, next http.HandlerFunc)
StatsHandler - returns current stats about Hoverfly (request counts, record count)
func (*DBClient) StatsWSHandler ¶ added in v0.5.8
func (d *DBClient) StatsWSHandler(w http.ResponseWriter, r *http.Request)
StatsWSHandler - returns current stats about Hoverfly (request counts, record count) through the websocket
type Entry ¶ added in v0.5.11
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 ¶ added in v0.5.11
type Hook interface { ActionTypes() []ActionType Fire(*Entry) error }
Hook - an interface to add dynamic hooks to extend functionality
type MetaObject ¶ added in v0.5.13
MetaObject - container to store both keys and values of captured objects
type Metadata ¶ added in v0.5.13
type Metadata interface { Set(key, value []byte) error Get(key []byte) ([]byte, error) Delete(key []byte) error GetAll() ([]MetaObject, error) DeleteData() error CloseDB() }
Metadata - interface to store and retrieve any metadata that is related to Hoverfly
type Payload ¶
type Payload struct { Response ResponseDetails `json:"response"` Request RequestDetails `json:"request"` ID string `json:"id"` }
Payload structure holds request and response structure
func ExecuteMiddleware ¶
ExecuteMiddleware - takes command (middleware string) and payload, which is passed to middleware
type RequestContainer ¶ added in v0.5.10
type RequestContainer struct {
Details RequestDetails
}
RequestContainer holds structure for request
func (*RequestContainer) Hash ¶ added in v0.5.10
func (r *RequestContainer) Hash() string
Hash returns unique hash key for request
type RequestDetails ¶ added in v0.5.10
type RequestDetails struct { Path string `json:"path"` Method string `json:"method"` Destination string `json:"destination"` Scheme string `json:"scheme"` Query string `json:"query"` Body string `json:"body"` RemoteAddr string `json:"remoteAddr"` Headers map[string][]string `json:"headers"` }
RequestDetails stores information about request, it's used for creating unique hash and also as a payload structure
type ResponseDetails ¶ added in v0.5.10
type ResponseDetails struct { Status int `json:"status"` Body string `json:"body"` Headers map[string][]string `json:"headers"` }
ResponseDetails structure hold response body from external service, body is not decoded and is supposed to be bytes, however headers should provide all required information for later decoding by the client.