util

package
v0.52.1-rc.1 Latest Latest
Warning

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

Go to latest
Published: Mar 29, 2024 License: Apache-2.0 Imports: 9 Imported by: 27

Documentation

Overview

Package util implements helper functions for the api

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CreateAndSetAuthToken

func CreateAndSetAuthToken(config model.Reader) error

CreateAndSetAuthToken creates and sets the authorization token Requires that the config has been set up before calling

func DoGet

func DoGet(c *http.Client, url string, conn ShouldCloseConnection) (body []byte, e error)

DoGet is a wrapper around performing HTTP GET requests

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 DoPost

func DoPost(c *http.Client, url string, contentType string, body io.Reader) (resp []byte, e error)

DoPost is a wrapper around performing HTTP POST 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 GetAuthToken

func GetAuthToken() string

GetAuthToken gets the session token

func GetClient

func GetClient(verify bool) *http.Client

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 GetDCAAuthToken

func GetDCAAuthToken() string

GetDCAAuthToken gets the session token

func InitDCAAuthToken

func InitDCAAuthToken(config model.Reader) error

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

func IsForbidden(ip string) bool

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 IsIPv6

func IsIPv6(ip string) bool

IsIPv6 is used to differentiate between ipv4 and ipv6 addresses.

func SetAuthToken

func SetAuthToken(config model.Reader) error

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
)

Jump to

Keyboard shortcuts

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