proxy

package
v1.14.0 Latest Latest
Warning

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

Go to latest
Published: Apr 5, 2019 License: Apache-2.0 Imports: 15 Imported by: 0

Documentation

Overview

Package proxy implements client and server code for proxying an unsecure connection over SSL.

Index

Constants

View Source
const (
	DefaultRefreshCfgThrottle = time.Minute
)
View Source
const SQLScope = "https://www.googleapis.com/auth/sqlservice.admin"

SQLScope is the Google Cloud Platform scope required for executing API calls to Cloud SQL.

Variables

This section is empty.

Functions

func Dial

func Dial(instance string) (net.Conn, error)

Dial returns a net.Conn connected to the Cloud SQL Instance specified. The format of 'instance' is "project-name:region:instance-name".

If one of the Init functions hasn't been called yet, InitDefault is called.

This is a network-level function; consider looking in the dialers subdirectory for more convenience functions related to actually logging into your database.

func Init

func Init(auth *http.Client, connset *ConnSet, dialer Dialer)

Init must be called before Dial is called. This is a more flexible version of InitDefault, but allows you to set more fields.

The http.Client is used to authenticate API requests. The connset parameter is optional. If the dialer is nil, net.Conn is used.

func InitClient

func InitClient(c Client)

InitClient is similar to Init, but allows you to specify the Client directly.

func InitDefault

func InitDefault(ctx context.Context) error

InitDefault attempts to initialize the Dial function using application default credentials.

func NewConnSrc

func NewConnSrc(instance string, l net.Listener) <-chan Conn

NewConnSrc returns a chan which can be used to receive connections on the passed Listener. All requests sent to the returned chan will have the instance name provided here. The chan will be closed if the Listener returns an error.

Types

type CertSource

type CertSource interface {
	// Local returns a certificate that can be used to authenticate with the
	// provided instance.
	Local(instance string) (tls.Certificate, error)
	// Remote returns the instance's CA certificate, address, and name.
	Remote(instance string) (cert *x509.Certificate, addr, name string, err error)
}

CertSource is how a Client obtains various certificates required for operation.

type Client

type Client struct {
	// Port designates which remote port should be used when connecting to
	// instances. This value is defined by the server-side code, but for now it
	// should always be 3307.
	Port int
	// Required; specifies how certificates are obtained.
	Certs CertSource
	// Optionally tracks connections through this client. If nil, connections
	// are not tracked and will not be closed before method Run exits.
	Conns *ConnSet
	// Dialer should return a new connection to the provided address. It is
	// called on each new connection to an instance. net.Dial will be used if
	// left nil.
	Dialer func(net, addr string) (net.Conn, error)

	// RefreshCfgThrottle is the amount of time to wait between configuration
	// refreshes. If not set, it defaults to 1 minute.
	//
	// This is to prevent quota exhaustion in the case of client-side
	// malfunction.
	RefreshCfgThrottle time.Duration

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

	// ConnectionsCounter is used to enforce the optional maxConnections limit
	ConnectionsCounter uint64
	// contains filtered or unexported fields
}

Client is a type to handle connecting to a Server. All fields are required unless otherwise specified.

func (*Client) Dial

func (c *Client) Dial(instance string) (net.Conn, error)

Dial uses the configuration stored in the client to connect to an instance. If this func returns a nil error the connection is correctly authenticated to connect to the instance.

func (*Client) Run

func (c *Client) Run(connSrc <-chan Conn)

Run causes the client to start waiting for new connections to connSrc and proxy them to the destination instance. It blocks until connSrc is closed.

func (*Client) Shutdown added in v1.13.0

func (c *Client) Shutdown(termTimeout 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 ConnSet

type ConnSet struct {
	sync.RWMutex
	// contains filtered or unexported fields
}

A ConnSet tracks net.Conns associated with a provided ID. A nil ConnSet will be a no-op for all methods called on it.

func NewConnSet

func NewConnSet() *ConnSet

NewConnSet initializes a new ConnSet and returns it.

func (*ConnSet) Add

func (c *ConnSet) Add(id string, conn net.Conn)

Add saves the provided conn and associates it with the given string identifier.

func (*ConnSet) Close

func (c *ConnSet) Close() error

Close closes every net.Conn contained in the set.

func (*ConnSet) Conns

func (c *ConnSet) Conns(ids ...string) []net.Conn

Conns returns all active connections associated with the provided ids.

func (*ConnSet) IDs

func (c *ConnSet) IDs() []string

IDs returns a slice of all identifiers which still have active connections.

func (*ConnSet) Remove

func (c *ConnSet) Remove(id string, conn net.Conn) error

Remove undoes an Add operation to have the set forget about a conn. Do not Remove an id/conn pair more than it has been Added.

func (*ConnSet) String

func (c *ConnSet) String() string

String returns a debug string for the ConnSet.

type Dialer

type Dialer func(net, addr string) (net.Conn, error)

Dialer is a convenience type to model the standard 'Dial' function.

Jump to

Keyboard shortcuts

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