cloudsql

package
v1.14.1 Latest Latest
Warning

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

Go to latest
Published: Jan 23, 2025 License: Apache-2.0 Imports: 21 Imported by: 0

Documentation

Index

Constants

View Source
const (

	// RefreshTimeout is the maximum amount of time to wait for a refresh
	// cycle to complete. This value should be greater than the
	// refreshInterval.
	RefreshTimeout = 60 * time.Second

	// FailoverPeriod is the frequency with which the dialer will check
	// if the DNS record has changed for connections configured using
	// a DNS name.
	FailoverPeriod = 30 * time.Second
)
View Source
const (
	// PublicIP is the value for public IP Cloud SQL instances.
	PublicIP = "PUBLIC"
	// PrivateIP is the value for private IP Cloud SQL instances.
	PrivateIP = "PRIVATE"
	// PSC is the value for private service connect Cloud SQL instances.
	PSC = "PSC"
	// AutoIP selects public IP if available and otherwise selects private
	// IP.
	AutoIP = "AutoIP"
)

Variables

DNSResolver uses the default net.Resolver to find TXT records containing an instance name for a DNS record.

View Source
var DefaultResolver = &ConnNameResolver{}

DefaultResolver simply parses instance names.

Functions

This section is empty.

Types

type ConnNameResolver added in v1.12.0

type ConnNameResolver struct {
}

ConnNameResolver simply parses instance names. Implements InstanceConnectionNameResolver

func (*ConnNameResolver) Resolve added in v1.12.0

func (r *ConnNameResolver) Resolve(_ context.Context, icn string) (instanceName instance.ConnName, err error)

Resolve returns the instance name, possibly using DNS. This will return an instance.ConnName or an error if it was unable to resolve an instance name.

type ConnectionInfo added in v1.9.0

type ConnectionInfo struct {
	ConnectionName    instance.ConnName
	ClientCertificate tls.Certificate
	ServerCACert      []*x509.Certificate
	ServerCAMode      string
	DBVersion         string
	// The DNSName is from the ConnectSettings API.
	// It is used to validate the server identity of the CAS instances.
	DNSName    string
	Expiration time.Time
	// contains filtered or unexported fields
}

ConnectionInfo contains all necessary information to connect securely to the server-side Proxy running on a Cloud SQL instance.

func NewConnectionInfo added in v1.11.0

func NewConnectionInfo(
	cn instance.ConnName,
	dnsName string,
	serverCAMode string,
	version string,
	ipAddrs map[string]string,
	serverCACert []*x509.Certificate,
	clientCert tls.Certificate,
) ConnectionInfo

NewConnectionInfo initializes a ConnectionInfo struct.

func (ConnectionInfo) Addr added in v1.9.0

func (c ConnectionInfo) Addr(ipType string) (string, error)

Addr returns the IP address or DNS name for the given IP type.

func (ConnectionInfo) TLSConfig added in v1.9.0

func (c ConnectionInfo) TLSConfig() *tls.Config

TLSConfig constructs a TLS configuration for the given connection info.

type DNSInstanceConnectionNameResolver added in v1.12.0

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

DNSInstanceConnectionNameResolver can resolve domain names into instance names using TXT records in DNS. Implements InstanceConnectionNameResolver

func (*DNSInstanceConnectionNameResolver) Resolve added in v1.12.0

func (r *DNSInstanceConnectionNameResolver) Resolve(ctx context.Context, icn string) (instanceName instance.ConnName, err error)

Resolve returns the instance name, possibly using DNS. This will return an instance.ConnName or an error if it was unable to resolve an instance name.

type LazyRefreshCache added in v1.9.0

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

LazyRefreshCache is caches connection info and refreshes the cache only when a caller requests connection info and the current certificate is expired.

func NewLazyRefreshCache added in v1.9.0

func NewLazyRefreshCache(
	cn instance.ConnName,
	l debug.ContextLogger,
	client *sqladmin.Service,
	key *rsa.PrivateKey,
	_ time.Duration,
	tp auth.TokenProvider,
	dialerID string,
	useIAMAuthNDial bool,
) *LazyRefreshCache

NewLazyRefreshCache initializes a new LazyRefreshCache.

func (*LazyRefreshCache) Close added in v1.9.0

func (c *LazyRefreshCache) Close() error

Close is a no-op and provided purely for a consistent interface with other caching types.

func (*LazyRefreshCache) ConnectionInfo added in v1.9.0

func (c *LazyRefreshCache) ConnectionInfo(
	ctx context.Context,
) (ConnectionInfo, error)

ConnectionInfo returns connection info for the associated instance. New connection info is retrieved under two conditions: - the current connection info's certificate has expired, or - a caller has separately called ForceRefresh

func (*LazyRefreshCache) ForceRefresh added in v1.9.0

func (c *LazyRefreshCache) ForceRefresh()

ForceRefresh invalidates the caches and configures the next call to ConnectionInfo to retrieve a fresh connection info.

func (*LazyRefreshCache) UpdateRefresh added in v1.9.0

func (c *LazyRefreshCache) UpdateRefresh(useIAMAuthNDial *bool)

UpdateRefresh updates the refresh operation to either enable or disable IAM authentication for the cached connection info.

type RefreshAheadCache added in v1.9.0

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

RefreshAheadCache manages the information used to connect to the Cloud SQL instance by periodically calling the Cloud SQL Admin API. It automatically refreshes the required information approximately 4 minutes before the previous certificate expires (every ~56 minutes).

func NewRefreshAheadCache added in v1.9.0

func NewRefreshAheadCache(
	cn instance.ConnName,
	l debug.ContextLogger,
	client *sqladmin.Service,
	key *rsa.PrivateKey,
	refreshTimeout time.Duration,
	tp auth.TokenProvider,
	dialerID string,
	useIAMAuthNDial bool,
) *RefreshAheadCache

NewRefreshAheadCache initializes a new Instance given an instance connection name

func (*RefreshAheadCache) Close added in v1.9.0

func (i *RefreshAheadCache) Close() error

Close closes the instance; it stops the refresh cycle and prevents it from making additional calls to the Cloud SQL Admin API.

func (*RefreshAheadCache) ConnectionInfo added in v1.9.0

func (i *RefreshAheadCache) ConnectionInfo(ctx context.Context) (ConnectionInfo, error)

ConnectionInfo returns an IP address specified by ipType (i.e., public or private) and a TLS config that can be used to connect to a Cloud SQL instance.

func (*RefreshAheadCache) ForceRefresh added in v1.9.0

func (i *RefreshAheadCache) ForceRefresh()

ForceRefresh triggers an immediate refresh operation to be scheduled and used for future connection attempts. Until the refresh completes, the existing connection info will be available for use if valid.

func (*RefreshAheadCache) UpdateRefresh added in v1.9.0

func (i *RefreshAheadCache) UpdateRefresh(useIAMAuthNDial *bool)

UpdateRefresh cancels all existing refresh attempts and schedules new attempts with the provided config only if it differs from the current configuration.

Jump to

Keyboard shortcuts

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