...

Package cloudsql

import "cloud.google.com/go/cloudsqlconn/internal/cloudsql"
Overview
Index

Overview ▾

Constants

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"
)
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
)

type ConnectionInfo

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

type ConnectionInfo struct {
    ConnectionName    instance.ConnName
    ClientCertificate tls.Certificate
    ServerCaCert      *x509.Certificate
    DBVersion         string
    Expiration        time.Time
    // contains filtered or unexported fields
}

func (ConnectionInfo) Addr

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

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

func (ConnectionInfo) TLSConfig

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

TLSConfig constructs a TLS configuration for the given connection info.

type LazyRefreshCache

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

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

func NewLazyRefreshCache

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

NewLazyRefreshCache initializes a new LazyRefreshCache.

func (*LazyRefreshCache) Close

func (c *LazyRefreshCache) Close() error

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

func (*LazyRefreshCache) ConnectionInfo

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

func (c *LazyRefreshCache) ForceRefresh()

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

func (*LazyRefreshCache) UpdateRefresh

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

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).

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

func NewRefreshAheadCache

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

NewRefreshAheadCache initializes a new Instance given an instance connection name

func (*RefreshAheadCache) Close

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

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

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

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.