spoof

package
Version: v0.0.0-...-b30ab9d Latest Latest
Warning

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

Go to latest
Published: May 14, 2019 License: Apache-2.0 Imports: 15 Imported by: 0

Documentation

Index

Constants

View Source
const (

	// RequestTimeout is the default timeout for the polling requests.
	RequestTimeout = 5 * time.Minute
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Interface

type Interface interface {
	Do(*http.Request) (*Response, error)
	Poll(*http.Request, ResponseChecker) (*Response, error)
}

Interface defines the actions that can be performed by the spoofing client.

type Response

type Response struct {
	Status     string
	StatusCode int
	Header     http.Header
	Body       []byte
}

Response is a stripped down subset of http.Response. The is primarily useful for ResponseCheckers to inspect the response body without consuming it. Notably, Body is a byte slice instead of an io.ReadCloser.

func (*Response) String

func (r *Response) String() string

type ResponseChecker

type ResponseChecker func(resp *Response) (done bool, err error)

ResponseChecker is used to determine when SpoofinClient.Poll is done polling. This allows you to predicate wait.PollImmediate on the request's http.Response.

See the apimachinery wait package: https://github.com/kubernetes/apimachinery/blob/cf7ae2f57dabc02a3d215f15ca61ae1446f3be8f/pkg/util/wait/wait.go#L172

type SpoofingClient

type SpoofingClient struct {
	Client          *http.Client
	RequestInterval time.Duration
	RequestTimeout  time.Duration
	// contains filtered or unexported fields
}

SpoofingClient is a minimal HTTP client wrapper that spoofs the domain of requests for non-resolvable domains.

func New

func New(kubeClientset *kubernetes.Clientset, logf logging.FormatLogger, domain string, resolvable bool, endpointOverride string) (*SpoofingClient, error)

New returns a SpoofingClient that rewrites requests if the target domain is not `resolveable`. It does this by looking up the ingress at construction time, so reusing a client will not follow the ingress if it moves (or if there are multiple ingresses).

If that's a problem, see test/request.go#WaitForEndpointState for oneshot spoofing.

func (*SpoofingClient) Do

func (sc *SpoofingClient) Do(req *http.Request) (*Response, error)

Do dispatches to the underlying http.Client.Do, spoofing domains as needed and transforming the http.Response into a spoof.Response. Each response is augmented with "ZipkinTraceID" header that identifies the zipkin trace corresponding to the request.

func (*SpoofingClient) Poll

func (sc *SpoofingClient) Poll(req *http.Request, inState ResponseChecker) (*Response, error)

Poll executes an http request until it satisfies the inState condition or encounters an error.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
t or T : Toggle theme light dark auto