util

package
v0.59.0 Latest Latest
Warning

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

Go to latest
Published: Nov 6, 2024 License: Apache-2.0 Imports: 19 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 DoGetWithOptions added in v0.53.0

func DoGetWithOptions(c *http.Client, url string, options *ReqOptions) (body []byte, e error)

DoGetWithOptions 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 GetClientWithTimeout added in v0.58.0

func GetClientWithTimeout(to time.Duration, verify bool) *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 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.

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

type GetOption func(url.URL) url.URL

GetOption is an option that can be passed to DoGet

func WithValues added in v0.53.0

func WithValues(values url.Values) GetOption

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

func (*IPCEndpoint) DoGet added in v0.53.0

func (end *IPCEndpoint) DoGet(options ...GetOption) ([]byte, error)

DoGet sends GET method to the endpoint

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
)

Jump to

Keyboard shortcuts

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