Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func BuildConnectionString ¶ added in v0.7.0
func BuildConnectionString(service api.Service, opts ConnectionStringOptions) (string, error)
BuildConnectionString creates a PostgreSQL connection string from service details
The function supports various configuration options through ConnectionStringOptions: - Pooled connections (if available on the service) - With or without password embedded in the URI - Custom database role/username - Optional warning output when pooler is unavailable
Examples:
// Simple connection string without password (for use with PGPASSWORD or ~/.pgpass)
connStr, err := BuildConnectionString(service, ConnectionStringOptions{
Role: "tsdbadmin",
WithPassword: false,
})
// Connection string with password embedded
connStr, err := BuildConnectionString(service, ConnectionStringOptions{
Role: "tsdbadmin",
WithPassword: true,
})
// Pooled connection with warnings
connStr, err := BuildConnectionString(service, ConnectionStringOptions{
Pooled: true,
Role: "tsdbadmin",
WithPassword: true,
WarnWriter: os.Stderr,
})
Types ¶
type ConnectionStringOptions ¶ added in v0.7.0
type ConnectionStringOptions struct {
// Pooled determines whether to use the pooler endpoint (if available)
Pooled bool
// Role is the database role/username to use (e.g., "tsdbadmin")
Role string
// PasswordMode determines how passwords are handled
PasswordMode PasswordMode
// WarnWriter is an optional writer for warning messages (e.g., when pooler is requested but not available)
// If nil, warnings are suppressed
WarnWriter io.Writer
}
ConnectionStringOptions configures how the connection string is built
type KeyringStorage ¶
type KeyringStorage struct{}
KeyringStorage implements password storage using system keyring
func (*KeyringStorage) GetStorageResult ¶
func (k *KeyringStorage) GetStorageResult(err error, password string) PasswordStorageResult
type NoStorage ¶
type NoStorage struct{}
NoStorage implements no password storage (passwords are not saved)
func (*NoStorage) GetStorageResult ¶
func (n *NoStorage) GetStorageResult(err error, password string) PasswordStorageResult
type PasswordMode ¶ added in v0.7.0
type PasswordMode int
PasswordMode determines how passwords are handled in connection strings
const ( // PasswordExclude means don't include password in connection string (default) // Connection will rely on PGPASSWORD env var or ~/.pgpass file PasswordExclude PasswordMode = iota // PasswordRequired means include password in connection string, return error if unavailable // Used when user explicitly requests --with-password flag PasswordRequired // PasswordOptional means include password if available, but don't error if unavailable // Used for connection testing and psql launching where we want best-effort password inclusion PasswordOptional )
type PasswordStorage ¶
type PasswordStorage interface {
Save(service api.Service, password string) error
Get(service api.Service) (string, error)
Remove(service api.Service) error
GetStorageResult(err error, password string) PasswordStorageResult
}
PasswordStorage defines the interface for password storage implementations
func GetPasswordStorage ¶
func GetPasswordStorage() PasswordStorage
GetPasswordStorage returns the appropriate PasswordStorage implementation based on configuration
type PasswordStorageResult ¶
type PasswordStorageResult struct {
Success bool `json:"success"`
Method string `json:"method"` // "keyring", "pgpass", or "none"
Message string `json:"message"` // Human-readable message
}
PasswordStorageResult contains the result of password storage operations
func SavePasswordWithResult ¶
func SavePasswordWithResult(service api.Service, password string) (PasswordStorageResult, error)
SavePasswordWithResult handles saving a password and returns both error and result info
type PgpassStorage ¶
type PgpassStorage struct{}
PgpassStorage implements password storage using ~/.pgpass file
func (*PgpassStorage) GetStorageResult ¶
func (p *PgpassStorage) GetStorageResult(err error, password string) PasswordStorageResult