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 ¶
- func New(env *emu.Env) emu.Service
- type Service
- func (s *Service) ApplySeed(ctx context.Context, section *yaml.Node, baseDir string) error
- func (s *Service) ClockAdvanced(ctx context.Context) error
- func (s *Service) EnvVars(gateway string, _ map[string]string) map[string]string
- func (s *Service) ExportSeed(ctx context.Context) (any, error)
- func (s *Service) HostAddrs() map[string]string
- func (s *Service) InstanceRegion(project, instance string) (string, error)
- func (s *Service) LoopbackAddrs() []string
- func (s *Service) Name() string
- func (s *Service) Operations() []emu.OperationInfo
- func (s *Service) Ready() error
- func (s *Service) Register(r emu.Router) error
- func (s *Service) ReservedAddrs() []string
- func (s *Service) Reset(ctx context.Context) error
- func (s *Service) ResourceCounts() map[string]int
- func (s *Service) Restore(ctx context.Context, dir string) error
- func (s *Service) ServeHTTP(w http.ResponseWriter, r *http.Request)
- func (s *Service) SetUserPassword(ctx context.Context, project, instance, user, password string) error
- func (s *Service) Snapshot(ctx context.Context, dir string) error
- func (s *Service) Start(ctx context.Context) error
- func (s *Service) Stop(ctx context.Context) error
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type Service ¶
type Service struct {
// contains filtered or unexported fields
}
Service is the Cloud SQL service module.
func (*Service) ClockAdvanced ¶ added in v0.9.0
ClockAdvanced deletes the backups that expired before returning (`gcpemu time advance`).
func (*Service) EnvVars ¶
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
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 ¶
HostAddrs returns "P/I" → host:port of every instance's published PostgreSQL port.
func (*Service) InstanceRegion ¶ added in v0.3.0
InstanceRegion implements emu.SQLUsers.
func (*Service) LoopbackAddrs ¶ added in v0.6.0
LoopbackAddrs implements emu.LoopbackHolder. It reads only the store, so that LB may call it while holding its own lock.
func (*Service) Operations ¶ added in v0.2.0
func (s *Service) Operations() []emu.OperationInfo
Operations implements emu.OperationLister.
func (*Service) Ready ¶
Ready reports not-ready while instances are being recovered after a restart.
func (*Service) Register ¶
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
ReservedAddrs implements emu.AddressReserver: the public and private IPs instances ask for again when their containers are recreated.
func (*Service) Reset ¶
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
ResourceCounts implements emu.ResourceCounter.
func (*Service) Restore ¶ added in v0.6.0
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
Snapshot implements emu.Snapshotter. A stopped instance's data cannot be dumped, so it must be started or deleted first.
Source Files
¶
- agentapi.go
- backups.go
- backupsapi.go
- certs.go
- connect.go
- databases.go
- dataplane.go
- errors.go
- executesql.go
- expiry.go
- filter.go
- finalbackup.go
- flags.go
- flags_docs.go
- images.go
- importexport.go
- instances.go
- loopback.go
- model.go
- operations.go
- pitr.go
- rest.go
- retainedbackup.go
- retention.go
- seed.go
- settings.go
- snapshot.go
- sql.go
- users.go
- xservice.go
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). |