spoof

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Jul 17, 2018 License: Apache-2.0 Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

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)
}

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.

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

	RetryCodes []int
	// 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, logger *zap.SugaredLogger, domain string, resolvable bool) (*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.

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
y or Y : Canonical URL