proxy

package
v1.0.0-alpha.9 Latest Latest
Warning

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

Go to latest
Published: Sep 4, 2019 License: MIT Imports: 30 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func WithCtxRoot

func WithCtxRoot(c *Config, next http.Handler) http.Handler

WithCtxRoot is a middleware that reads the url path params in the request and tries to determine which kubeconfig context to use for upstream api server requests. If a context is found in the URL path params, the request-context is populated with the value so that other handlers and middlewares may use the information

func WithEmpty

func WithEmpty(c *Config, next http.Handler) http.Handler

WithEmpty is an empty handler that does nothing

func WithHeader

func WithHeader(c *Config, next http.Handler) http.Handler

WithHeader is a middleware that reads the value of the HTTP header "Multikube-Context" in the request and, if found, sets it's value in the request context.

func WithJWKValidation

func WithJWKValidation(c *Config, next http.Handler) http.Handler

WithJWKValidation is a middleware that validates a JWT token in the http request using RS256 signing method. It will do so using a JWK (Json Web Key) provided in c

func WithJWT

func WithJWT(c *Config, next http.Handler) http.Handler

WithJWT is a middleware that parses a JWT token from the requests and propagates the request context with a claim value.

func WithLogging

func WithLogging(c *Config, next http.Handler) http.Handler

WithLogging applies access log style logging to the HTTP server

func WithMetrics

func WithMetrics(c *Config, next http.Handler) http.Handler

WithMetrics is an empty handler that does nothing

func WithTracing

func WithTracing(c *Config, next http.Handler) http.Handler

WithTracing is a middleware that starts a new span and populates the context

func WithX509Validation

func WithX509Validation(c *Config, next http.Handler) http.Handler

WithX509Validation is a middleware that validates a JWT token in the http request using RS256 signing method. It will do so using a x509 certificate provided in c

Types

type Config

type Config struct {
	OIDCIssuerURL     string
	OIDCUsernameClaim string
	OIDCPollInterval  time.Duration
	RS256PublicKey    *x509.Certificate
	JWKS              *JWKS
}

Config holds a top-level configuration of an instance of Multikube. It is used to pass around configuration used by different packages within the project.

func (*Config) GetJWKSFromURL

func (c *Config) GetJWKSFromURL() func()

GetJWKSFromURL fetches the keys of an OpenID Connect endpoint in a go routine. It polls the endpoint every n seconds. Returns a cancel function which can be called to stop polling and close the channel. The endpoint must support OpenID Connect discovery as per https://openid.net/specs/openid-connect-discovery-1_0.html

type JSONWebKey

type JSONWebKey struct {
	Kty string   `json:"kty"`
	Kid string   `json:"kid"`
	Use string   `json:"use"`
	N   string   `json:"n"`
	E   string   `json:"e"`
	X5c []string `json:"x5c"`
}

JSONWebKey is a representation of a Json Web Key

type JWKS

type JWKS struct {
	Keys []JSONWebKey `json:"keys"`
}

JWKS is a representation of Json Web Key Store. It holds multiple JWK's in an array

func (*JWKS) Find

func (j *JWKS) Find(s string) *JSONWebKey

Find will loop through the keys on the JWKS and return that which has a matching key id

type Middleware

type Middleware func(*Config, http.Handler) http.Handler

Middleware represents a multikube middleware

type Options

type Options struct {
	*api.Cluster
	*api.AuthInfo
	// contains filtered or unexported fields
}

Options embeds Cluster and AuthInfo from https://godoc.org/k8s.io/client-go/tools/clientcmd/api so that fields and methods are easily accessible from one type.

type Proxy

type Proxy struct {
	CertChain  *x509.Certificate
	Config     *Config
	KubeConfig *api.Config
	// contains filtered or unexported fields
}

Proxy implements an HTTP handler. It has a built-in transport with in-mem cache capabilities.

func NewProxy

func NewProxy() *Proxy

NewProxy creates a new Proxy and initialises router and configuration

func NewProxyFrom

func NewProxyFrom(kc *api.Config) *Proxy

NewProxyFrom creates an instance of Proxy

func (*Proxy) ServeHTTP

func (p *Proxy) ServeHTTP(w http.ResponseWriter, r *http.Request)

ServeHTTP routes the request to an apiserver. It determines, resolves an apiserver using data in the request itsel such as certificate data, authorization bearer tokens, http headers etc.

func (*Proxy) Use

func (p *Proxy) Use(mw ...Middleware) Middleware

Use chains all middlewares and applies a context to the request flow

type Request

type Request struct {
	Transport http.RoundTripper
	// contains filtered or unexported fields
}

Request is a simple type used to compose inidivudal requests to an HTTP server.

func NewRequest

func NewRequest(u *url.URL) *Request

NewRequest will return a new Request object with the given URL

func (*Request) APIVer

func (r *Request) APIVer(v string) *Request

APIVer sets the api version to be used when building the URI for the request. Defaults to 'v1' if not set.

func (*Request) Body

func (r *Request) Body(b io.Reader) *Request

Body sets the request body of the request being made.

func (*Request) Delete

func (r *Request) Delete() *Request

Delete method sets the method on a request to DELETE. Delete will invoke Method(http.MethodDelete).

func (*Request) Do

func (r *Request) Do() (*http.Response, error)

Do executes the request and returns an http.Response. The caller is responible of closing the Body.

func (*Request) DoWithContext

func (r *Request) DoWithContext(ctx context.Context) (*http.Response, error)

DoWithContext executes the request and returns an http.Response. DoWithContext expect a context to be provided.

func (*Request) Get

func (r *Request) Get() *Request

Get method sets the method on a request to GET. Get will invoke Method(http.MethodGet).

func (*Request) Header

func (r *Request) Header(key string, values ...string) *Request

Header sets one header and replacing any headers with equal key

func (*Request) Headers

func (r *Request) Headers(h http.Header) *Request

Headers overrides the entire headers field of the http request. Use Header() method to set individual headers.

func (*Request) Into

func (r *Request) Into(obj interface{}) *Request

Into sets the interface in which the returning data will be marshaled into.

func (*Request) Method

func (r *Request) Method(m string) *Request

Method methdo sets the method on a request.

func (*Request) Name

func (r *Request) Name(n string) *Request

Name sets the name of the Kubernetes resource to be used when building the URI. For example setting the name to 'app-pod-1' will create an uri like /api/v1/namespaces/pods/app-pod-1.

func (*Request) Namespace

func (r *Request) Namespace(ns string) *Request

Namespace sets the Kubernetes namespace to be used when building the URI. For example setting the namespace to 'default' will create an uri like /api/v1/namespaces/default.

func (*Request) Options

func (r *Request) Options() *Request

Options method sets the method on a request to OPTIONS. Options will invoke Method(http.MethodOptions),

func (*Request) Path

func (r *Request) Path(p string) *Request

Path sets the raw URI path later used by the request.

func (*Request) Post

func (r *Request) Post() *Request

Post method sets the method on a request to POST. Post will invoke Method(http.MethodPost).

func (*Request) Put

func (r *Request) Put() *Request

Put method sets the method on a request to PUT. Put will invoke Method(http.MethodPut).

func (*Request) Query

func (r *Request) Query(q string) *Request

Query sets the raw query path to be used when performing the request

func (*Request) Resource

func (r *Request) Resource(res string) *Request

Resource sets the Kubernetes resource to be used when building the URI. For example setting the resource to 'Pod' will create an uri like /api/v1/namespaces/pods.

func (*Request) URL

func (r *Request) URL() *url.URL

URL composes a complete URL and return an url.URL then used by the request

type Transport

type Transport struct {
	Cache           *cache.Cache
	TLSClientConfig *tls.Config
	// contains filtered or unexported fields
}

Transport is an implementation of RoundTripper and extension of http.Transport with the addition of a Cache.

func (*Transport) RoundTrip

func (t *Transport) RoundTrip(req *http.Request) (res *http.Response, err error)

RoundTrip implements http.Transport

Jump to

Keyboard shortcuts

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