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 DoGetWithContext(ctx context.Context, c *http.Client, url string, conn ShouldCloseConnection) (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 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
- 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 DoGetWithContext ¶
func DoGetWithContext(ctx context.Context, c *http.Client, url string, conn ShouldCloseConnection) (body []byte, e error)
DoGetWithContext 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 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.
Types ¶
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 )