Documentation ¶
Overview ¶
Package http provides an HTTP interface allowing HTTP clients to interact with otf.
Index ¶
- Constants
- Variables
- func APIRouter(r *mux.Router) *mux.Router
- func Absolute(r *http.Request, path string) string
- func ExternalHost(r *http.Request) string
- func GetClientIP(r *http.Request) (string, error)
- func SanitizeAddress(address string) (string, error)
- func SanitizeHostname(hostname string) (string, error)
- type Client
- type Config
- type RetryLogHook
- type Server
- type ServerConfig
Constants ¶
const ( // DefaultBasePath on which the API is served. DefaultBasePath = "/api/v2/" // PingEndpoint is a no-op API endpoint used to configure the rate limiter PingEndpoint = "ping" )
const ( ModuleV1Prefix = "/v1/modules/" APIPrefixV2 = "/api/v2/" )
const (
DefaultAddress = "localhost:8080"
)
Variables ¶
var ( // endpoints with these prefixes require authentication AuthenticatedPrefixes = []string{ APIPrefixV2, ModuleV1Prefix, paths.UIPrefix, } )
var Encoder = schema.NewEncoder()
Encoder for encoding structs into queries: caches structs, and safe for sharing
Functions ¶
func Absolute ¶
Absolute returns an absolute URL for the given path. It uses the http request to determine the correct hostname and scheme to use. Handles situations where otf is sitting behind a reverse proxy, using the X-Forwarded-* headers the proxy sets.
func ExternalHost ¶
ExternalHost uses the incoming HTTP request to determine the host:port on which this server can be reached externally by clients and the internet.
func GetClientIP ¶
GetClientIP gets the client's IP address
func SanitizeAddress ¶
SanitizeAddress ensures address is in format https://<host>:<port>
func SanitizeHostname ¶
SanitizeHostname ensures hostname is in the format <host>:<port>
Types ¶
type Client ¶
type Client struct {
// contains filtered or unexported fields
}
func (*Client) Do ¶
Do sends an API request and returns the API response. The API response is JSONAPI decoded and the document's primary data is stored in the value pointed to by v, or returned as an error if an API error has occurred.
If v implements the io.Writer interface, the raw response body will be written to v, without attempting to first decode it.
The provided ctx must be non-nil. If it is canceled or times out, ctx.Err() will be returned.
func (*Client) NewRequest ¶
func (c *Client) NewRequest(method, path string, v interface{}) (*retryablehttp.Request, error)
NewRequest creates an API request with proper headers and serialization.
A relative URL path can be provided, in which case it is resolved relative to the baseURL of the Client. Relative URL paths should always be specified without a preceding slash. Adding a preceding slash allows for ignoring the configured baseURL for non-standard endpoints.
If v is supplied, the value will be JSONAPI encoded and included as the request body. If the method is GET, the value will be parsed and added as query parameters.
func (*Client) RetryServerErrors ¶
RetryServerErrors configures the retry HTTP check to also retry unexpected errors or requests that failed with a server error.
type Config ¶
type Config struct { // The address of the otf API. Address string // The base path on which the API is served. BasePath string // API token used to access the otf API. Token string // Headers that will be added to every request. Headers http.Header // A custom HTTP client to use. HTTPClient *http.Client // RetryLogHook is invoked each time a request is retried. RetryLogHook RetryLogHook // Insecure skips verification of upstream TLS certs. // NOTE: this does not take effect if HTTPClient is non-nil Insecure bool }
Config provides configuration details to the API client.
type RetryLogHook ¶
RetryLogHook allows a function to run before each retry.
type Server ¶
type Server struct { logr.Logger ServerConfig // contains filtered or unexported fields }
Server is the http server for OTF
type ServerConfig ¶
type ServerConfig struct { SSL bool CertFile, KeyFile string EnableRequestLogging bool DevMode bool Handlers []internal.Handlers Middleware []mux.MiddlewareFunc }
ServerConfig is the http server config
Directories ¶
Path | Synopsis |
---|---|
Package decode contains decoders for various HTTP artefacts
|
Package decode contains decoders for various HTTP artefacts |
Package html contains code relating specifically to the web UI.
|
Package html contains code relating specifically to the web UI. |
paths
Package paths provides rails-style path helpers for use with the web app.
|
Package paths provides rails-style path helpers for use with the web app. |