pkg

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Oct 20, 2020 License: MIT Imports: 24 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewStatsdClient

func NewStatsdClient(config *Config) (statsd.StatSender, error)

Types

type Config

type Config struct {
	ListenAddress string        `yaml:"listen_address"`
	CA            *TLSInfo      `yaml:"ca"`
	LogLevel      string        `yaml:"log_level"`
	Statsd        *StatsdConfig `yaml:"statsd"`

	Registries []Registry `yaml:"registries"`
}

func NewConfig

func NewConfig(configPath string) (*Config, error)

type DefaultMitmHijacker

type DefaultMitmHijacker struct{}

A default implementation of the MitmHijacker interface.

func (DefaultMitmHijacker) RequestHandler

func (DefaultMitmHijacker) TransformMetricName

func (d DefaultMitmHijacker) TransformMetricName(name MitmProxyStatsdMetricName, _ *http.Request) string

type DockerRegistryHijacker

type DockerRegistryHijacker struct {
	// contains filtered or unexported fields
}

DockerRegistryHijacker is an implementation of MitmHijacker to be used to hijack queries to docker registries, and redirect them to Kraken.

func NewDockerRegistryHijacker

func NewDockerRegistryHijacker(config *Config) (*DockerRegistryHijacker, error)

returns a *MitmHijacker to be used to hijack queries to docker registries, and redirect them to Kraken.

func (*DockerRegistryHijacker) RequestHandler

func (h *DockerRegistryHijacker) RequestHandler(responseWriter http.ResponseWriter, request *http.Request) (bool, *http.Response, error)

func (*DockerRegistryHijacker) TransformMetricName

func (h *DockerRegistryHijacker) TransformMetricName(name MitmProxyStatsdMetricName, request *http.Request) string

we suffix pace metrics with the name of the registry, abd also mark manifests and blob queries as such.

type MitmHijacker

type MitmHijacker interface {
	// RequestHandler is called for all incoming requests
	// * the first item of the return tuple, the boolean, says whether the hijacker wishes to hijack that request; in
	//   that case,
	// * if that first item is true, the hijacker can optionally provide a *http.Response to copy to the client
	// * if the first item of the return tuple is false, or error is not nil, then the proxy forwards the request upstream
	RequestHandler(http.ResponseWriter, *http.Request) (bool, *http.Response, error)

	// hijackers can choose to transform statsd metrics' names
	// metricName is guaranteed to be one of the constants defined above.
	// If it returns an empty string, then the metric point is not emitted.
	TransformMetricName(MitmProxyStatsdMetricName, *http.Request) string
}

a MitmHijacker tells a MitmProxy how to handle incoming requests.

type MitmProxy

type MitmProxy struct {
	// contains filtered or unexported fields
}

func NewMitmProxy

func NewMitmProxy(listenAddr string, ca *TLSInfo, hijacker MitmHijacker, statsdClient statsd.StatSender) *MitmProxy

func (*MitmProxy) RequestHandler

func (p *MitmProxy) RequestHandler(upstream http.Handler, writer http.ResponseWriter, request *http.Request)

func (*MitmProxy) Start

func (p *MitmProxy) Start() error

Start is a blocking call.

func (*MitmProxy) Stop

func (p *MitmProxy) Stop() error

type MitmProxyStatsdMetricName

type MitmProxyStatsdMetricName string
const (
	// Statsd counter metric incremented when a request is hijacked.
	HijackedRequestCounter MitmProxyStatsdMetricName = "mitm.hijacked"

	// Statsd counter metric incremented when a request is transparently proxied.
	ProxiedRequestCounter MitmProxyStatsdMetricName = "mitm.proxied"

	// Statsd timing metric, measuring the time needed to transmit 1kB for hijacked requests.
	HijackedRequestTransferPace MitmProxyStatsdMetricName = "mitm.hijacked.pace"

	// Statsd timing metric, measuring the time needed to transmit 1kB for proxied requests.
	ProxiedRequestTransferPace MitmProxyStatsdMetricName = "mitm.proxied.pace"

	// Statsd counter metric incremented when hijacking a request fails.
	HijackingErrorsCounter MitmProxyStatsdMetricName = "mitm.hijacked.errors"
)

The names of the statsd metrics that MitmProxys push.

type RedirectRegistry

type RedirectRegistry struct {
	krakenconfig.Config `yaml:",inline"`

	// if specified, this should indicate how to rewrite repositories
	// à la SSH config, %r will be replaced by the original repository name,
	// and %t by the original tag name
	RewriteRepositories string `yaml:"rewrite_repositories"`
}

type Registry

type Registry struct {
	krakenconfig.Config `yaml:",inline"`

	// if specified, that will be used instead of the registry's address to determine
	// if a given request is addressed to this registry
	MatchingRegex string `yaml:"matching_regex"`

	// which registries to try & redirect to, in order
	Redirects []RedirectRegistry `yaml:"redirects"`
}

type StatsdConfig

type StatsdConfig struct {
	Address       string        `yaml:"address"`
	Prefix        string        `yaml:"prefix"`
	FlushInterval time.Duration `yaml:"flush_interval"`
	FlushBytes    int           `yaml:"flush_bytes"`
}

type TLSInfo

type TLSInfo struct {
	CertPath string `yaml:"cert_path"`
	KeyPath  string `yaml:"key_path"`
}

Jump to

Keyboard shortcuts

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