Documentation ¶
Overview ¶
Package util implements helper functions for the api
Index ¶
- func CreateAndSetAuthToken(config model.Reader) error
- func DoGet(c *http.Client, url string, conn ShouldCloseConnection) (body []byte, e error)
- func DoGetWithOptions(c *http.Client, url string, options *ReqOptions) (body []byte, e error)
- func DoPost(c *http.Client, url string, contentType string, body io.Reader) (resp []byte, e error)
- func DoPostChunked(c *http.Client, url string, contentType string, body io.Reader, ...) error
- func GetAuthToken() string
- func GetClient(verify bool) *http.Client
- func GetClientWithTimeout(to time.Duration, verify bool) *http.Client
- func GetDCAAuthToken() string
- func InitDCAAuthToken(config model.Reader) error
- func IsForbidden(ip string) bool
- func IsIPv6(ip string) bool
- func SetAuthToken(config model.Reader) error
- func Validate(w http.ResponseWriter, r *http.Request) error
- func ValidateDCARequest(w http.ResponseWriter, r *http.Request) error
- func WithCloseConnection(state bool) func(*IPCEndpoint)
- func WithHTTPClient(client *http.Client) func(*IPCEndpoint)
- func WithHostAndPort(cmdHost string, cmdPort int) func(*IPCEndpoint)
- func WithURLScheme(scheme string) func(*IPCEndpoint)
- type EndpointOption
- type GetOption
- type IPCEndpoint
- type ReqOptions
- type ShouldCloseConnection
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func CreateAndSetAuthToken ¶
CreateAndSetAuthToken creates and sets the authorization token Requires that the config has been set up before calling
func DoGetWithOptions ¶ added in v0.53.0
DoGetWithOptions is a wrapper around performing HTTP GET requests
func DoPostChunked ¶
func DoPostChunked(c *http.Client, url string, contentType string, body io.Reader, onChunk func([]byte)) error
DoPostChunked is a wrapper around performing HTTP POST requests that stream chunked data
func GetClient ¶
GetClient is a convenience function returning an http client `GetClient(false)` must be used only for HTTP requests whose destination is localhost (ie, for Agent commands).
func GetClientWithTimeout ¶ added in v0.58.0
GetClientWithTimeout is a convenience function returning an http client Arguments correspond to the request timeout duration, and a boolean to verify the server TLS client (false should only be used on localhost trusted endpoints).
func InitDCAAuthToken ¶
InitDCAAuthToken initialize the session token for the Cluster Agent based on config options Requires that the config has been set up before calling
func IsForbidden ¶
IsForbidden returns whether the cluster check runner server is allowed to listen on a given ip The function is a non-secure helper to help avoiding setting an IP that's too permissive. The function doesn't guarantee any security feature
func SetAuthToken ¶
SetAuthToken sets the session token Requires that the config has been set up before calling
func Validate ¶
func Validate(w http.ResponseWriter, r *http.Request) error
Validate validates an http request
func ValidateDCARequest ¶
func ValidateDCARequest(w http.ResponseWriter, r *http.Request) error
ValidateDCARequest is used for the exposed endpoints of the DCA. It is different from Validate as we want to have different validations.
func WithCloseConnection ¶ added in v0.53.0
func WithCloseConnection(state bool) func(*IPCEndpoint)
WithCloseConnection is an option to close the connection
func WithHTTPClient ¶ added in v0.53.0
func WithHTTPClient(client *http.Client) func(*IPCEndpoint)
WithHTTPClient is an option to assign a different http.Client
func WithHostAndPort ¶ added in v0.53.0
func WithHostAndPort(cmdHost string, cmdPort int) func(*IPCEndpoint)
WithHostAndPort is an option to use a host address for sending IPC requests default is the config settings "cmd_host" (default localhost) and "cmd_port" (default 5001)
func WithURLScheme ¶ added in v0.53.0
func WithURLScheme(scheme string) func(*IPCEndpoint)
WithURLScheme is an option to set the URL's scheme
Types ¶
type EndpointOption ¶ added in v0.53.0
type EndpointOption func(*IPCEndpoint)
EndpointOption allows configuration of the IPCEndpoint during construction
type GetOption ¶ added in v0.53.0
GetOption is an option that can be passed to DoGet
func WithValues ¶ added in v0.53.0
WithValues is an option to add url.Values to the GET request
type IPCEndpoint ¶ added in v0.53.0
type IPCEndpoint struct {
// contains filtered or unexported fields
}
IPCEndpoint is an endpoint that IPC requests will be sent to
func NewIPCEndpoint ¶ added in v0.53.0
func NewIPCEndpoint(config config.Component, endpointPath string, options ...EndpointOption) (*IPCEndpoint, error)
NewIPCEndpoint constructs a new IPC Endpoint using the given config, path, and options
type ReqOptions ¶ added in v0.53.0
type ReqOptions struct { Conn ShouldCloseConnection Ctx context.Context Authtoken string }
ReqOptions are options when making a request
type ShouldCloseConnection ¶
type ShouldCloseConnection int
ShouldCloseConnection is an option to DoGet to indicate whether to close the underlying connection after reading the response
const ( // LeaveConnectionOpen keeps the underlying connection open after reading the request response LeaveConnectionOpen ShouldCloseConnection = iota // CloseConnection closes the underlying connection after reading the request response CloseConnection )