sql

package
v0.13.0 Latest Latest
Warning

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

Go to latest
Published: Oct 30, 2026 License: Apache-2.0 Imports: 58 Imported by: ? modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package sql emulates Cloud SQL for PostgreSQL (SRS 5.6). The control plane is the sqladmin REST API (v1beta4 and v1) with its own Operation resource; each instance's data plane is a real PostgreSQL server in a container whose entrypoint is the gcpemu sql-proxy agent (package proxy), which enforces authorized networks, SSL modes and IAM database authentication and terminates the Cloud SQL connector's TLS on port 3307.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func New

func New(env *emu.Env) emu.Service

New returns the service.

Types

type Service

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

Service is the Cloud SQL service module.

func (*Service) ApplySeed

func (s *Service) ApplySeed(ctx context.Context, section *yaml.Node, baseDir string) error

ApplySeed implements emu.Seeder.

func (*Service) ClockAdvanced added in v0.9.0

func (s *Service) ClockAdvanced(ctx context.Context) error

ClockAdvanced deletes the backups that expired before returning (`gcpemu time advance`).

func (*Service) EnvVars

func (s *Service) EnvVars(gateway string, _ map[string]string) map[string]string

EnvVars implements emu.EnvVarer. gcloud's sql API client uses base URL https://sqladmin.googleapis.com/ with paths "sql/v1beta4/...", so the override is the "/sqladmin/" mount (which also accepts the version-less form). Each instance's published PostgreSQL port is exported as GCPEMU_SQL_<INSTANCE> (upper-cased, '-' → '_') = host:port.

func (*Service) ExportSeed added in v0.6.0

func (s *Service) ExportSeed(ctx context.Context) (any, error)

ExportSeed writes the instances back as the "sql" section (FR-CORE-013), ordered by project and name: each instance's settings that differ from the create defaults, its root password, and the databases and users beyond the built-in postgres ones, with built-in users' passwords. The rows in the databases are data plane and are not exported (no initSQL), nor are a database's charset and collation or a user's databaseRoles, which the seed file cannot declare. databaseVersion is always written, since its default moves with releases.

func (*Service) HostAddrs

func (s *Service) HostAddrs() map[string]string

HostAddrs returns "P/I" → host:port of every instance's published PostgreSQL port.

func (*Service) InstanceRegion added in v0.3.0

func (s *Service) InstanceRegion(project, instance string) (string, error)

InstanceRegion implements emu.SQLUsers.

func (*Service) LoopbackAddrs added in v0.6.0

func (s *Service) LoopbackAddrs() []string

LoopbackAddrs implements emu.LoopbackHolder. It reads only the store, so that LB may call it while holding its own lock.

func (*Service) Name

func (s *Service) Name() string

func (*Service) Operations added in v0.2.0

func (s *Service) Operations() []emu.OperationInfo

Operations implements emu.OperationLister.

func (*Service) Ready

func (s *Service) Ready() error

Ready reports not-ready while instances are being recovered after a restart.

func (*Service) Register

func (s *Service) Register(r emu.Router) error

Register mounts the API: "/sql/v1beta4/..." at the gateway root (gcloud, OpenTofu and the Cloud SQL connector address it there) and everything (v1beta4, v1 and the agent endpoint) under "/sqladmin/" and in host mode for sqladmin.googleapis.com.

func (*Service) ReservedAddrs added in v0.4.0

func (s *Service) ReservedAddrs() []string

ReservedAddrs implements emu.AddressReserver: the public and private IPs instances ask for again when their containers are recreated.

func (*Service) Reset

func (s *Service) Reset(ctx context.Context) error

Reset cancels the background work started before it and waits for it (bounded by ctx), so none of it creates a container or writes a record afterwards (#306). It then removes every instance container and volume and the backup files (`gcpemu reset`). Work started after Reset runs on a fresh background context, unless the service is stopped.

func (*Service) ResourceCounts added in v0.2.0

func (s *Service) ResourceCounts() map[string]int

ResourceCounts implements emu.ResourceCounter.

func (*Service) Restore added in v0.6.0

func (s *Service) Restore(ctx context.Context, dir string) error

Restore implements emu.Snapshotter: after Reset removed every container and volume, each instance with data is started on a fresh volume and its dump replayed, in parallel.

func (*Service) ServeHTTP

func (s *Service) ServeHTTP(w http.ResponseWriter, r *http.Request)

ServeHTTP routes the sqladmin REST API. Both API versions share one implementation (the resource shapes are identical): v1beta4 at "/sql/v1beta4/..." (gcloud, OpenTofu, the Cloud SQL connector) and v1 at "/v1/..." (google.golang.org/api/sqladmin/v1). The agent endpoint lives at "/_agent/v1/...".

func (*Service) SetUserPassword added in v0.3.0

func (s *Service) SetUserPassword(ctx context.Context, project, instance, user, password string) error

SetUserPassword implements emu.SQLUsers: it sets a built-in user's password as users.update would, without an Operation.

func (*Service) Snapshot added in v0.6.0

func (s *Service) Snapshot(ctx context.Context, dir string) error

Snapshot implements emu.Snapshotter. A stopped instance's data cannot be dumped, so it must be started or deleted first.

func (*Service) Start

func (s *Service) Start(ctx context.Context) error

Start marks operations interrupted by a previous shutdown as failed and brings back the containers of running instances (FR-CORE-031) in the background; Ready reports not-ready until they are up.

func (*Service) Stop

func (s *Service) Stop(ctx context.Context) error

Stop cancels background work and waits for it.

Directories

Path Synopsis
internal
genflags command
Command genflags generates Cloud SQL for PostgreSQL's database flag allow-list (FR-SQL-003) from Google's documentation:
Command genflags generates Cloud SQL for PostgreSQL's database flag allow-list (FR-SQL-003) from Google's documentation:
Package proxy is the Cloud SQL in-container agent (FR-SQL-004..007).
Package proxy is the Cloud SQL in-container agent (FR-SQL-004..007).

Jump to

Keyboard shortcuts

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