proxy

package
v0.8.0 Latest Latest
Warning

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

Go to latest
Published: Jul 14, 2021 License: Apache-2.0 Imports: 13 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Cert

type Cert struct {
	ClientCert tls.Certificate
	CACerts    []*x509.Certificate
	RemoteAddr string
	Ports      RemotePorts
}

type CertError added in v0.7.0

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

CertError represents a Cert operation error.

func (*CertError) Error added in v0.7.0

func (c *CertError) Error() string

type CertSource

type CertSource interface {
	// Cert returns the required certs needed to establish a TLS connection
	// from the client to the server.
	Cert(ctx context.Context, org, db, branch string) (*Cert, error)
}

CertSource is used

type Client

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

Client is responsible for listening to unsecured connections over a TCP localhost port and tunneling them securely over a TLS connection to a remote database instance defined by its PlanetScale unique branch identifier.

func NewClient

func NewClient(opts Options) (*Client, error)

NewClient creates a new proxy client instance

func (*Client) LocalAddr

func (c *Client) LocalAddr() (net.Addr, error)

LocalAddr returns the address of the local listener. This is by default blocking and will only return if the proxy is invoked with the Run() method.

func (*Client) Run

func (c *Client) Run(ctx context.Context) error

Run runs the proxy. It listens to the configured localhost address and proxies the connection over a TLS tunnel to the remote DB instance.

func (*Client) Shutdown

func (c *Client) Shutdown(timeout time.Duration) error

Shutdown waits up to a given amount of time for all active connections to close. Returns an error if there are still active connections after waiting for the whole length of the timeout.

type Conn

type Conn struct {
	Instance string
	Conn     net.Conn
}

Conn represents a connection from a client to a specific instance.

type Options

type Options struct {
	// RemoteAddr defines the server address to tunnel local connections. By
	// default we connect to the remote address given by the CertSource. This
	// option can be used to over write it.
	RemoteAddr string

	// LocalAddr defines the address to listen for new connection
	LocalAddr string

	// Instance defines the remote DB instance to proxy new connection
	Instance string

	// MaxConnections is the maximum number of connections to establish
	// before refusing new connections. 0 means no limit.
	MaxConnections uint64

	// CertSource defines the certificate source to obtain the required TLS
	// certificates for the client and the remote address of the server to
	// connect.
	CertSource CertSource

	// Logger defines which zap.Logger to use. Use it to override the default
	// Development logger . Useful for tests.
	Logger *zap.Logger
}

Options are the options for creating a new Client.

type RemotePorts

type RemotePorts struct {
	Proxy int
	MySQL int
}

Jump to

Keyboard shortcuts

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