firetail

package
v0.2.2 Latest Latest
Warning

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

Go to latest
Published: Oct 21, 2024 License: LGPL-3.0 Imports: 17 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GetMiddleware

func GetMiddleware(options *Options) (func(next http.Handler) http.Handler, error)

GetMiddleware creates & returns a firetail middleware. Errs if the openapi spec can't be found, validated, or loaded into a gorillamux router.

Types

type ErrorAppspecInvalid

type ErrorAppspecInvalid struct {
	Err error // The error that occurred during initialisation of the middleware due to the appspec being invalid
}

ErrorAppspecInvalid is used at initialisation/startup when the OpenAPI appspec file is malformed

func (ErrorAppspecInvalid) Error

func (e ErrorAppspecInvalid) Error() string

type ErrorAtRequest

type ErrorAtRequest interface {
	error

	// Should return the appropriate HTTP status code to provide in response to the request for which the error occured
	StatusCode() int

	// Should return a title string appropriate for public RFC7807 error responses
	Title() string
}

ErrorAtRequest is an interface that extends the standard error interface for errors that occur during the handling of a request. To satisfy this interface, errors should implement a method which returns an appropriate HTTP status code to provide the client.

type ErrorAtRequestUnspecified

type ErrorAtRequestUnspecified struct {
	Err error
}

ErrorAtRequestUnspecified is used to wrap errors that are returned at request time, but aren't able to be broken down into more useful information

func (ErrorAtRequestUnspecified) Error

func (ErrorAtRequestUnspecified) StatusCode

func (e ErrorAtRequestUnspecified) StatusCode() int

func (ErrorAtRequestUnspecified) Title

type ErrorAuthNoMatchingScheme

type ErrorAuthNoMatchingScheme struct {
	Err *openapi3filter.SecurityRequirementsError
}

ErrorAuthNoMatchingSchema is used when a request doesn't satisfy any of the securitySchemes corresponding to the route that the request matched in the OpenAPI spec

func (ErrorAuthNoMatchingScheme) Error

func (ErrorAuthNoMatchingScheme) StatusCode

func (e ErrorAuthNoMatchingScheme) StatusCode() int

func (ErrorAuthNoMatchingScheme) Title

type ErrorAuthSchemeNotImplemented

type ErrorAuthSchemeNotImplemented struct {
	MissingScheme string
}

ErrorAuthSchemaNotImplemented is used when a request is made to a path that has a security scheme requirement that has not been implemented in the application

func (ErrorAuthSchemeNotImplemented) Error

type ErrorInvalidConfiguration

type ErrorInvalidConfiguration struct {
	Err error // The path that was used to attempt to load the appspec
}

InvalidConfiguration is used by middleware constructors if the configuration they are provided is invalid for some reason

func (ErrorInvalidConfiguration) Error

type ErrorRequestBodyInvalid

type ErrorRequestBodyInvalid struct {
	Err error
}

ErrorRequestBodyInvalid is used when the body of a request doesn't conform to the schema in the OpenAPI spec

func (ErrorRequestBodyInvalid) Error

func (e ErrorRequestBodyInvalid) Error() string

func (ErrorRequestBodyInvalid) StatusCode

func (e ErrorRequestBodyInvalid) StatusCode() int

func (ErrorRequestBodyInvalid) Title

func (e ErrorRequestBodyInvalid) Title() string

type ErrorRequestContentTypeInvalid

type ErrorRequestContentTypeInvalid struct {
	RequestedContentType string
	RequestedRoute       string
}

ErrorRequestHeadersInvalid is used when the Content-Type header of a request doesn't conform to the schema in the OpenAPI spec

func (ErrorRequestContentTypeInvalid) Error

func (ErrorRequestContentTypeInvalid) StatusCode

func (e ErrorRequestContentTypeInvalid) StatusCode() int

func (ErrorRequestContentTypeInvalid) Title

type ErrorRequestHeadersInvalid

type ErrorRequestHeadersInvalid struct {
	Err error
}

ErrorRequestHeadersInvalid is used when any of the headers of a request don't conform to the schema in the OpenAPI spec, except for the Content-Type header for which an ErrorRequestContentTypeInvalid is used

func (ErrorRequestHeadersInvalid) Error

func (ErrorRequestHeadersInvalid) StatusCode

func (e ErrorRequestHeadersInvalid) StatusCode() int

func (ErrorRequestHeadersInvalid) Title

type ErrorRequestPathParamsInvalid

type ErrorRequestPathParamsInvalid struct {
	Err error
}

ErrorRequestPathParamsInvalid is used when the path params of a request don't conform to the schema in the OpenAPI spec

func (ErrorRequestPathParamsInvalid) Error

func (ErrorRequestPathParamsInvalid) StatusCode

func (e ErrorRequestPathParamsInvalid) StatusCode() int

func (ErrorRequestPathParamsInvalid) Title

type ErrorRequestQueryParamsInvalid

type ErrorRequestQueryParamsInvalid struct {
	Err error
}

ErrorRequestQueryParamsInvalid is used when the query params of a request don't conform to the schema in the OpenAPI spec

func (ErrorRequestQueryParamsInvalid) Error

func (ErrorRequestQueryParamsInvalid) StatusCode

func (e ErrorRequestQueryParamsInvalid) StatusCode() int

func (ErrorRequestQueryParamsInvalid) Title

type ErrorResponseBodyInvalid

type ErrorResponseBodyInvalid struct {
	Err error
}

ErrorResponseHeadersInvalid is used when the body of a response doesn't conform to the schema in the OpenAPI spec

func (ErrorResponseBodyInvalid) Error

func (e ErrorResponseBodyInvalid) Error() string

func (ErrorResponseBodyInvalid) StatusCode

func (e ErrorResponseBodyInvalid) StatusCode() int

func (ErrorResponseBodyInvalid) Title

func (e ErrorResponseBodyInvalid) Title() string

type ErrorResponseHeadersInvalid

type ErrorResponseHeadersInvalid struct {
	Err error
}

ErrorResponseHeadersInvalid is used when any of the headers of a response don't conform to the schema in the OpenAPI spec Currently not implemented as the underlying kin-openapi module doesn't perform response header validation. See the open issue here: https://github.com/getkin/kin-openapi/issues/201 TODO: Open source contribution to kin-openapi?

func (ErrorResponseHeadersInvalid) Error

func (ErrorResponseHeadersInvalid) StatusCode

func (e ErrorResponseHeadersInvalid) StatusCode() int

func (ErrorResponseHeadersInvalid) Title

type ErrorResponseStatusCodeInvalid

type ErrorResponseStatusCodeInvalid struct {
	RespondedStatusCode int
}

ErrorResponseStatusCodeInvalid is used when the status code of a response doesn't conform to the schema in the OpenAPI spec

func (ErrorResponseStatusCodeInvalid) Error

func (ErrorResponseStatusCodeInvalid) StatusCode

func (e ErrorResponseStatusCodeInvalid) StatusCode() int

func (ErrorResponseStatusCodeInvalid) Title

type ErrorRouteNotFound

type ErrorRouteNotFound struct {
	RequestedPath string // The path that was requested for which no corresponding route could be found
}

ErrorRouteNotFound is used when a request is made for which no corresponding route in the OpenAPI spec could be found

func (ErrorRouteNotFound) Error

func (e ErrorRouteNotFound) Error() string

func (ErrorRouteNotFound) StatusCode

func (e ErrorRouteNotFound) StatusCode() int

func (ErrorRouteNotFound) Title

func (e ErrorRouteNotFound) Title() string

type ErrorUnsupportedMethod

type ErrorUnsupportedMethod struct {
	RequestedPath   string // The route that corresponds to the path that was requested for which the method is not supported
	RequestedMethod string // The method which was requested but is not supported on the route corresponding to the request path
}

ErrorUnsupportedMethod is used when a request is made which corresponds to a route in the OpenAPI spec, but that route doesn't support the HTTP method with which the request was made

func (ErrorUnsupportedMethod) Error

func (e ErrorUnsupportedMethod) Error() string

func (ErrorUnsupportedMethod) StatusCode

func (e ErrorUnsupportedMethod) StatusCode() int

func (ErrorUnsupportedMethod) Title

func (e ErrorUnsupportedMethod) Title() string

type Options

type Options struct {
	// SpecPath is the path at which your openapi spec can be found. Supplying an empty string disables any validation.
	OpenapiSpecPath string

	// OpenapiBytes is the raw bytes of your openapi spec. Supplying an empty slice disables any validation. OpenapiBytes takes
	// precedence over OpenapiSpecPath if both are provided. OpenapiSpecPath will be used if OpenapiBytes is nil or len() == 0
	OpenapiBytes []byte

	// LogsApiToken is the API token which will be used when sending logs to the Firetail logging API with the default batch callback.
	// This value should typically be loaded in from an environment variable. If unset, the default batch callback will not forward
	// logs to the Firetail SaaS
	LogsApiToken string

	// LogsApiUrl is the URL of the Firetail logging API endpoint to which logs will be sent by the default batch callback. This value
	// should typically be loaded in from an environment variable. If unset, the default value is the Firetail SaaS' bulk logs endpoint
	// in the default region (firetail.app). If another region is being used, this option will need to be configured appropriately. For
	// example, for us.firetail.app LogsApiUrl should normally be https://api.logging.us-east-2.prod.firetail.app/logs/bulk
	LogsApiUrl string

	// LogBatchCallback is an optional callback which is provided with a batch of Firetail log entries ready to be sent to Firetail. The
	// default callback sends log entries to the Firetail logging API. It may be customised to, for example, additionally log the entries
	// to a file on disk
	LogBatchCallback func([][]byte)

	// MaxBatchSize is the maximum size of a logging batch in bytes which will be passed to the LogBatchCallback, or the default callback
	// if it is used.
	MaxBatchSize int

	// MaxLogAge is the maximum age of the oldest log in a batch which will be passed to the LogBatchCallback, or the default callback if
	// it is used.
	MaxLogAge time.Duration

	// ErrCallback is an optional callback func which is given an error and a ResponseWriter to which an apropriate response can be written
	// for the error. This allows you customise the responses given, when for example a request or response fails to validate against the
	// openapi spec, to be consistent with the format in which the rest of your application returns error responses
	ErrCallback func(ErrorAtRequest, http.ResponseWriter, *http.Request)

	// DebugErrs is a flag which, when set to true, will enable the default ErrCallback to send more verbose information in the RFC7807
	// error responses' `details` member.
	DebugErrs bool

	// AuthCallbacks is a map of strings, which should match the names of your appspec's securitySchemes, to callback funcs which must be
	// defined if you wish to use security schemas in your openapi specification. See the openapi3filter package's reference for further
	// documentation
	AuthCallbacks map[string]openapi3filter.AuthenticationFunc

	// EnableRequestValidation is an optional flag which, if set to true, enables request validation against the openapi spec provided -
	// if no openapi spec is provided, then no validation will be performed
	EnableRequestValidation bool

	// EnableResponseValidation is an optional flag which, if set to true, enables response validation against the openapi spec provided -
	// if no openapi spec is provided, then no validation will be performed
	EnableResponseValidation bool

	// CustomBodyDecoders is a map of Content-Type header values to openapi3 decoders - if the kin-openapi module does not support your
	// Content-Type by default, you will need to add a custom decoder here
	CustomBodyDecoders map[string]openapi3filter.BodyDecoder

	// LogEntrySanitiser is a function used to sanitise the log entries sent to Firetail. You may wish to use this to redact sensitive
	// information, or anonymise identifiable information using a custom implementation of this callback for your application. A default
	// implementation is provided in the firetail logging package
	LogEntrySanitiser func(logging.LogEntry) logging.LogEntry
}

Options is an options struct used when creating a Firetail middleware (GetMiddleware)

Jump to

Keyboard shortcuts

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