proxy

package
v0.0.0-...-22b0e53 Latest Latest
Warning

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

Go to latest
Published: Sep 1, 2023 License: MIT Imports: 18 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type CloudProviders

type CloudProviders struct {
	Providers []yeoman.VMStore
}

func (CloudProviders) GetAllVMs

func (c CloudProviders) GetAllVMs(
	ctx context.Context,
	log *slog.Logger,
) ([]yeoman.VM, error)

type Config

type Config struct {
	Log                yeoman.LogConfig          `json:"log"`
	HTTP               HTTPConfig                `json:"http"`
	HTTPS              HTTPSConfig               `json:"https"`
	ProviderRegistries []yeoman.ProviderRegistry `json:"providerRegistries"`
	Subnets            []string                  `json:"subnets"`
}

type HTTPConfig

type HTTPConfig struct {
	Port int `json:"port"`
}

type HTTPSConfig

type HTTPSConfig struct {
	Host       string `json:"host"`
	Port       int    `json:"port"`
	CertBucket string `json:"certBucket"`
}

type Registry

type Registry struct {
	// Services maps hostnames to one of the following:
	//
	// * IPs with optional healthcheck paths, OR
	Services map[string]*backend `json:"services"`

	// Subnets restricts internal API access to specific prefixes, which
	// should all be on a private LAN.
	Subnets []string `json:"subnets,omitempty"`
}

Registry maps hosts to backends with other helpful info, such as healthchecks.

func (*Registry) Hosts

func (r *Registry) Hosts() []string

Hosts for the registry suitable for generating HTTPS certificates. This automatically removes *.internal domains.

type ReverseProxy

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

ReverseProxy maps frontend hosts to backends. It will automatically check the `/health` path of backend servers periodically and removes dead backends from rotation until health checks pass.

func New

func New(
	ctx context.Context,
	log *slog.Logger,
	terra CloudProviders,
	config Config,
	autocertManager *autocert.Manager,
	timeout time.Duration,
) (*ReverseProxy, error)

New ReverseProxy from a given Registry.

func (*ReverseProxy) CheckHealth

func (r *ReverseProxy) CheckHealth() error

CheckHealth of backend servers in the registry concurrently, and update the registry so requests are only routed to healthy servers.

func (*ReverseProxy) RedirectHTTPHandler

func (rp *ReverseProxy) RedirectHTTPHandler() (http.Handler, error)

RedirectHTTPHandler redirects http requests to use the API if the request originated from the whitelisted subnet. In all other GET and HEAD requests, this handler redirects to HTTPS. For POST, PUT, etc. this handler throws an error letting the client know to use HTTPS.

func (*ReverseProxy) ServeHTTP

func (r *ReverseProxy) ServeHTTP(w http.ResponseWriter, req *http.Request)

func (*ReverseProxy) UpdateRegistry

func (r *ReverseProxy) UpdateRegistry(reg *Registry)

UpdateRegistry for the reverse proxy with new frontends, backends, and health checks.

Jump to

Keyboard shortcuts

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