Documentation
¶
Overview ¶
Package vaultpg is the client for per-vault Postgres databases: building connection strings for a domain.PostgresInstance/vault database+role pair, running the admin-side DDL that provisions a vault's role+database (AdminClient), and caching the tenant-side *sql.DB connections the MCP executor queries through (ConnPool).
Index ¶
- type AdminClient
- func (c *AdminClient) Close() error
- func (c *AdminClient) DropDatabase(ctx context.Context, dbName string) error
- func (c *AdminClient) DropRole(ctx context.Context, roleName string) error
- func (c *AdminClient) EnsureDatabase(ctx context.Context, dbName, ownerRole string) error
- func (c *AdminClient) EnsureRole(ctx context.Context, roleName, password string) error
- type Config
- type ConnPool
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type AdminClient ¶
type AdminClient struct {
// contains filtered or unexported fields
}
AdminClient runs the admin-side DDL (CREATE ROLE/DATABASE, etc.) against a postgres_instances row's maintenance database — mirrors couchdb.Client's role in vault.go's ensureCouchUserExists/ ensureVaultExists, but for Postgres there's no higher-level client library, so this talks database/sql directly.
func NewAdminClient ¶
func NewAdminClient(instance domain.PostgresInstance) (*AdminClient, error)
NewAdminClient opens a fresh connection to instance's admin_database — mirrors newCouchClient in internal/service/v1/vault/vault.go (fresh per call, not pooled).
func (*AdminClient) Close ¶
func (c *AdminClient) Close() error
Close closes the underlying admin connection — callers own the AdminClient's lifetime since NewAdminClient opens a fresh connection per call.
func (*AdminClient) DropDatabase ¶
func (c *AdminClient) DropDatabase(ctx context.Context, dbName string) error
DropDatabase best-effort drops dbName, tolerating "does not exist" via IF EXISTS.
func (*AdminClient) DropRole ¶
func (c *AdminClient) DropRole(ctx context.Context, roleName string) error
DropRole best-effort drops roleName, tolerating "does not exist" via IF EXISTS.
func (*AdminClient) EnsureDatabase ¶
func (c *AdminClient) EnsureDatabase(ctx context.Context, dbName, ownerRole string) error
EnsureDatabase creates dbName owned by ownerRole, tolerating "database already exists" the same way ensureVaultExists tolerates user_errors.CouchDbDatabaseAlreadyExists.
func (*AdminClient) EnsureRole ¶
func (c *AdminClient) EnsureRole(ctx context.Context, roleName, password string) error
EnsureRole creates roleName as a LOGIN role with password, or — if it already exists — resets its password. Identifiers are quoted with pq.QuoteIdentifier and the password is quoted with pq.QuoteLiteral since CREATE ROLE/ALTER ROLE do not accept bind parameters for these clauses; callers only ever pass UUID-derived role names and generatePassword()-style random hex, never raw user input, but this stays defensive regardless.
type Config ¶
type Config struct {
Host string
Port int
Database string
User string
Password string
SSLMode string
}
Config identifies one Postgres database+role to connect to — either a postgres_instances admin database (AdminClient) or a per-vault tenant database (ConnPool).
func (Config) DSN ¶
DSN builds a `postgres://` URL-form DSN — lib/pq accepts both keyword and URL DSN forms, this codebase's other Postgres DSN builder (matreshka's resources.Postgres.ConnectionString) also uses the URL form. net/url takes care of escaping special characters in user/password/database.
type ConnPool ¶
type ConnPool struct {
// contains filtered or unexported fields
}
ConnPool caches one tenant *sql.DB per vault — opened and validated on first use, reused thereafter, evicted on Close. Used by the MCP executor (a later task) to avoid reopening a connection on every tool call.
func NewConnPool ¶
func NewConnPool() *ConnPool
NewConnPool returns an empty ConnPool ready for use.