Documentation
¶
Index ¶
- Constants
- func BytesToGB(bytes uint64) uint64
- func BytesToKB(bytes uint64) uint64
- func BytesToMB(bytes uint64) uint64
- func CheckPGDATAPermissions(pgdataPath string) error
- func DetectBinDir() (string, error)
- func DetectDataDir() (string, error)
- func FileEnv(key, defaultVal string) (string, error)
- func FormatDuration(d time.Duration) string
- func FormatDurationPostgreSQL(d time.Duration) string
- func FormatSize(bytes uint64) string
- func FormatSizePostgreSQL(bytes uint64) string
- func FormatSizePostgreSQLMB(bytes uint64) string
- func GBToBytes(gb uint64) uint64
- func GenerateSchemaDefaultsFromDescribeConfig(params []schemas.Param) map[string]string
- func GetCurrentUserInfo() (uid int, gid int, username string, err error)
- func GetPostgreSQLVersion(dataDir string) (string, error)
- func GetSchemaDefaults() map[string]string
- func GetSchemaDefaultsFromPostgres(version string) (map[string]string, error)
- func IsRunningAsPostgres() bool
- func IsRunningAsRoot() bool
- func KBToBytes(kb uint64) uint64
- func MBToBytes(mb uint64) uint64
- func MergeSchemaDefaults(manualDefaults, autoDefaults map[string]string) map[string]string
- func MustFileEnv(key, defaultVal string) string
- func ParseDuration(durationStr string) (time.Duration, error)
- func ParseSize(sizeStr string) (uint64, error)
- func ResolveBoolDefault(value string, fallback bool) bool
- func ResolveDefault(value string) string
- func ResolveFloat64Default(value string, fallback float64) float64
- func ResolveIntDefault(value string, fallback int) int
- func ValidateWithBinary(validator BinaryValidator, configPath string) error
- type BinaryValidator
- type PermissionCheckResult
- type PermissionError
- type PostgreSQLDirs
- type SensitiveString
- func (s SensitiveString) Equals(other SensitiveString) bool
- func (s SensitiveString) Format(f fmt.State, verb rune)
- func (s SensitiveString) GoString() string
- func (s SensitiveString) IsEmpty() bool
- func (s SensitiveString) MarshalJSON() ([]byte, error)
- func (s SensitiveString) MarshalText() ([]byte, error)
- func (s SensitiveString) String() string
- func (s SensitiveString) Value() string
- type ValidationError
Constants ¶
const ( Byte = 1 KB = 1024 * Byte MB = 1024 * KB GB = 1024 * MB TB = 1024 * GB )
Size constants in bytes
const ( Microsecond = time.Microsecond Millisecond = time.Millisecond Second = time.Second Minute = 60 * Second Hour = 60 * Minute Day = 24 * Hour )
Time constants
Variables ¶
This section is empty.
Functions ¶
func CheckPGDATAPermissions ¶
CheckPGDATAPermissions performs comprehensive permission checks on PGDATA
func DetectBinDir ¶
DetectBinDir detects PostgreSQL binary directory
func DetectDataDir ¶
DetectDataDir detects PostgreSQL data directory
func FileEnv ¶ added in v1.0.4
FileEnv retrieves an environment variable value or reads from a file if *_FILE variant exists. This implements Docker secrets pattern where sensitive values can be read from files. Returns error if both env var and file variant are set (exclusive use required).
func FormatDuration ¶
FormatDuration formats a duration to a human-readable string
func FormatDurationPostgreSQL ¶
FormatDurationPostgreSQL formats a duration as PostgreSQL expects it
func FormatSize ¶
FormatSize formats a size in bytes to a human-readable string
func FormatSizePostgreSQL ¶
FormatSizePostgreSQL formats a size in bytes as PostgreSQL expects it
func FormatSizePostgreSQLMB ¶
FormatSizePostgreSQLMB formats a size in bytes as PostgreSQL MB units only This ensures consistent MB units for all PostgreSQL memory settings
func GenerateSchemaDefaultsFromDescribeConfig ¶
GenerateSchemaDefaultsFromDescribeConfig creates schema defaults from postgres --describe-config output This function bridges the gap between PostgreSQL's native parameter metadata and our configuration schema
func GetCurrentUserInfo ¶
GetCurrentUserInfo returns information about the current user
func GetPostgreSQLVersion ¶
GetPostgreSQLVersion reads the PostgreSQL version from PG_VERSION file
func GetSchemaDefaults ¶
GetSchemaDefaults extracts default values from JSON schema metadata This would be used by configuration loaders to set proper defaults
func GetSchemaDefaultsFromPostgres ¶
GetSchemaDefaultsFromPostgres generates schema defaults using embedded PostgreSQL's describe-config This function provides the most accurate and up-to-date defaults based on the actual PostgreSQL version
func IsRunningAsPostgres ¶
func IsRunningAsPostgres() bool
IsRunningAsPostgres checks if the current process is running as postgres user (UID 999)
func IsRunningAsRoot ¶
func IsRunningAsRoot() bool
IsRunningAsRoot checks if the current process is running as root
func MergeSchemaDefaults ¶
MergeSchemaDefaults merges manually curated defaults with auto-generated ones Manual defaults take precedence over auto-generated ones
func MustFileEnv ¶ added in v1.0.4
MustFileEnv is like FileEnv but panics on error
func ParseDuration ¶
ParseDuration parses a duration string and returns the duration
func ResolveBoolDefault ¶
ResolveBoolDefault resolves a boolean default value with environment variable support
func ResolveDefault ¶
ResolveDefault resolves environment variable syntax in default values Supports patterns like: - ${VAR} - returns environment variable VAR or empty string - ${VAR:-default} - returns environment variable VAR or "default" - plain text - returns as-is
func ResolveFloat64Default ¶
ResolveFloat64Default resolves a float64 default value with environment variable support
func ResolveIntDefault ¶
ResolveIntDefault resolves an integer default value with environment variable support
func ValidateWithBinary ¶
func ValidateWithBinary(validator BinaryValidator, configPath string) error
ValidateWithBinary validates a configuration file using a binary tool
Types ¶
type BinaryValidator ¶
type BinaryValidator interface {
GetBinaryPath() string
GetValidationArgs(configPath string) []string
ParseValidationError(output string) (*ValidationError, error)
}
BinaryValidator defines the interface for validating configurations with binaries
type PermissionCheckResult ¶
type PermissionCheckResult struct {
Path string
Exists bool
Readable bool
Writable bool
OwnerUID int
OwnerGID int
CurrentUID int
CurrentGID int
ErrorMsg string
FixCommands []string
}
PermissionCheckResult represents the result of a permission check
func CheckDirectoryPermissions ¶
func CheckDirectoryPermissions(path string) (*PermissionCheckResult, error)
CheckDirectoryPermissions checks if a directory has correct permissions for the current user
type PermissionError ¶
type PermissionError struct {
Path string
Message string
CurrentUID int
OwnerUID int
FixCommands []string
}
PermissionError represents a permission-related error with fix suggestions
func (*PermissionError) Error ¶
func (e *PermissionError) Error() string
type PostgreSQLDirs ¶
PostgreSQLDirs holds detected PostgreSQL directories
func DetectPostgreSQLDirs ¶
func DetectPostgreSQLDirs() (*PostgreSQLDirs, error)
DetectPostgreSQLDirs detects both binary and data directories
type SensitiveString ¶
type SensitiveString string
SensitiveString is a string type that hides sensitive information in logs and JSON output
func NewSensitiveString ¶
func NewSensitiveString(value string) SensitiveString
NewSensitiveString creates a new SensitiveString from a regular string
func SensitiveStringFromEnv ¶
func SensitiveStringFromEnv(key string) SensitiveString
SensitiveStringFromEnv creates a SensitiveString from an environment variable Returns empty SensitiveString if the environment variable doesn't exist
func (SensitiveString) Equals ¶
func (s SensitiveString) Equals(other SensitiveString) bool
Equals compares two sensitive strings for equality (constant-time comparison)
func (SensitiveString) Format ¶
func (s SensitiveString) Format(f fmt.State, verb rune)
Format implements fmt.Formatter to ensure sensitive values are redacted in all format verbs
func (SensitiveString) GoString ¶
func (s SensitiveString) GoString() string
GoString implements fmt.GoStringer to prevent accidental logging in %#v format
func (SensitiveString) IsEmpty ¶
func (s SensitiveString) IsEmpty() bool
IsEmpty returns true if the sensitive string is empty
func (SensitiveString) MarshalJSON ¶
func (s SensitiveString) MarshalJSON() ([]byte, error)
MarshalJSON redacts the value in JSON output
func (SensitiveString) MarshalText ¶
func (s SensitiveString) MarshalText() ([]byte, error)
MarshalText redacts the value in text marshaling (used by many serializers)
func (SensitiveString) String ¶
func (s SensitiveString) String() string
String implements fmt.Stringer to prevent accidental logging of sensitive values
func (SensitiveString) Value ¶
func (s SensitiveString) Value() string
Value returns the actual string value - use with caution and only when necessary
type ValidationError ¶
ValidationError represents a configuration validation error
func ParseErrorWithRegex ¶
func ParseErrorWithRegex(output string, patterns map[string]*regexp.Regexp) (*ValidationError, error)
ParseErrorWithRegex is a helper function to parse validation errors using regex patterns