cloud_sql

package
v1.120.0 Latest Latest
Warning

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

Go to latest
Published: Nov 19, 2026 License: MIT Imports: 21 Imported by: 0

Documentation

Index

Constants

View Source
const (
	Domain = "sqladmin.googleapis.com"

	// LoginScope is the OAuth scope a token needs to log into a database as its IAM principal.
	LoginScope = "https://www.googleapis.com/auth/sqlservice.login"
	AdminScope = "https://www.googleapis.com/auth/sqlservice.admin"
)
View Source
const (
	DefaultTokenInfoUrl      = "https://oauth2.googleapis.com/tokeninfo"                   //nolint:gosec // G101: a public endpoint, not a credential
	DefaultServiceAccountUrl = "https://iam.googleapis.com/v1/projects/-/serviceAccounts/" //nolint:gosec // G101: a public endpoint, not a credential
)

Variables

View Source
var ErrOperationFailed = errors.New("cloud sql operation failed")

ErrOperationFailed is an operation that finished with errors; the error wrapping it gives them.

Functions

func DatabaseUsername

func DatabaseUsername(principal string) (string, error)

DatabaseUsername returns the Postgres role Cloud SQL creates for an IAM principal, given as an IAM member (`serviceAccount:x`, `user:x`, `group:x`) or a bare email. A service account's role drops the `.gserviceaccount.com` suffix; every name is lowercase.

Types

type Client

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

Client calls the Cloud SQL Admin API methods a connection needs, and those an export does. Authentication is the caller's: pass an authenticating http.Client through cloud_sql_config.WithFetchOptions.

func NewClient

func NewClient(options ...cloud_sql_config.Option) *Client

func (*Client) Export added in v1.120.0

func (c *Client) Export(
	ctx context.Context,
	project string,
	instance string,
	exportContext *export_context.ExportContext,
	options ...fetch_config.Option,
) (*operation.Operation, error)

Export starts an export of the instance and returns its operation, which WaitForOperation follows to its end. An instance runs one operation at a time: an export asked for while another runs is refused with a 409.

func (*Client) GenerateEphemeralCert

func (c *Client) GenerateEphemeralCert(
	ctx context.Context,
	project string,
	instance string,
	publicKeyPem string,
	accessToken string,
	options ...fetch_config.Option,
) (*generate_ephemeral_cert_response.Response, error)

GenerateEphemeralCert has the instance's CA sign publicKeyPem for a client certificate. When accessToken is set, the certificate carries it, and the database accepts it in place of a password for the token's principal.

func (*Client) GetConnectSettings

func (c *Client) GetConnectSettings(ctx context.Context, project string, instance string, options ...fetch_config.Option) (*connect_settings.ConnectSettings, error)

GetConnectSettings returns the instance's server CA, addresses and DNS name.

func (*Client) GetOperation added in v1.120.0

func (c *Client) GetOperation(ctx context.Context, project string, name string, options ...fetch_config.Option) (*operation.Operation, error)

GetOperation returns an operation of the project as it stands.

func (*Client) WaitForOperation added in v1.120.0

func (c *Client) WaitForOperation(
	ctx context.Context,
	project string,
	name string,
	interval time.Duration,
	options ...fetch_config.Option,
) (*operation.Operation, error)

WaitForOperation polls an operation every interval until it is done, and returns it. One that finished with errors is returned with an error wrapping ErrOperationFailed. A poll that fails is returned as it is: the operation goes on regardless, and a caller can look again.

type UsernameResolver added in v1.70.0

type UsernameResolver struct {
	TokenInfoUrl      string
	ServiceAccountUrl string
}

UsernameResolver works out the database username of the principal a token source speaks for. A user's token names its email; a service account's names only its unique ID, which the IAM API turns into the email.

func NewUsernameResolver added in v1.70.0

func NewUsernameResolver() *UsernameResolver

func (*UsernameResolver) Resolve added in v1.70.0

func (r *UsernameResolver) Resolve(ctx context.Context, tokenSource token_source.TokenSource) (string, error)

Directories

Path Synopsis
types
export_context
Package export_context is the body of a Cloud SQL Admin API export: what to export, how, and where to.
Package export_context is the body of a Cloud SQL Admin API export: what to export, how, and where to.
operation
Package operation is a Cloud SQL Admin API operation: a long-running change to an instance, as an export, and how it went.
Package operation is a Cloud SQL Admin API operation: a long-running change to an instance, as an export, and how it went.

Jump to

Keyboard shortcuts

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