sql

package
v0.5.0 Latest Latest
Warning

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

Go to latest
Published: Oct 11, 2026 License: Apache-2.0 Imports: 47 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) 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) 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) 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 removes every instance container and volume (`gcpemu reset`).

func (*Service) ResourceCounts added in v0.2.0

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

ResourceCounts implements emu.ResourceCounter.

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