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(opts ...ClientOption) *http.Client
- func GetClientWithTimeout(to time.Duration, opts ...ClientOption) *http.Client
- func GetDCAAuthToken() string
- func GetTLSClientConfig() *tls.Config
- func GetTLSServerConfig() *tls.Config
- func InitDCAAuthToken(config model.Reader) error
- func IsForbidden(ip string) bool
- func IsIPv6(ip string) bool
- func IsInitialized() 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 WithInsecureTransport(c *http.Client) *http.Client
- func WithURLScheme(scheme string) func(*IPCEndpoint)
- type ClientOption
- 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 and IPC certificate 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 ¶
func GetClient(opts ...ClientOption) *http.Client
GetClient is a convenience function returning an http client
func GetClientWithTimeout ¶ added in v0.58.0
func GetClientWithTimeout(to time.Duration, opts ...ClientOption) *http.Client
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 GetTLSClientConfig ¶ added in v0.62.0
GetTLSClientConfig gets the certificate and key used for IPC
func GetTLSServerConfig ¶ added in v0.62.0
GetTLSServerConfig gets the certificate and key used for IPC
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 IsInitialized ¶ added in v0.62.0
func IsInitialized() bool
IsInitialized return true if the auth_token and IPC cert/key pair have been initialized with SetAuthToken or CreateAndSetAuthToken functions
func SetAuthToken ¶
SetAuthToken sets the session token and IPC certificate 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 WithInsecureTransport ¶ added in v0.65.0
WithInsecureTransport modifies the provided HTTP client to use an insecure transport configuration. Specifically, it sets the TLSClientConfig to skip verification of the server's certificate. TODO IPC: remove this function
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 ClientOption ¶ added in v0.65.0
ClientOption is a function type that takes an *http.Client as input and returns an *http.Client. It can be used to modify or configure an HTTP client.
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 )