config

package
v1.21.0 Latest Latest
Warning

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

Go to latest
Published: Oct 10, 2026 License: MIT Imports: 9 Imported by: 0

Documentation

Index

Constants

View Source
const MaskedSecret = "***"

MaskedSecret is the placeholder returned by Web/CLI APIs for stored plaintext secrets.

Variables

This section is empty.

Functions

func CoalesceSecret added in v1.21.0

func CoalesceSecret(incoming, existing string) string

CoalesceSecret chooses the stored secret when the client omitted it or sent the mask placeholder.

func DeleteProfile added in v1.1.0

func DeleteProfile(configPath, name string) *errors.XError

DeleteProfile deletes a profile from the specified config file.

func DeleteSSHProxy added in v1.1.0

func DeleteSSHProxy(configPath, name string) *errors.XError

DeleteSSHProxy deletes an SSH proxy from the specified config file.

func FindConfigPath added in v0.0.10

func FindConfigPath(opts Options) string

FindConfigPath returns the path to the config file being used (or default path).

func InitConfig added in v0.0.10

func InitConfig(path string) (string, *errors.XError)

InitConfig creates a template config file at the given path. If path is empty, uses the default path ($HOME/.config/xsql/xsql.yaml).

func IsMaskedSecret added in v1.21.0

func IsMaskedSecret(s string) bool

IsMaskedSecret reports whether s is the API mask placeholder (not a real secret).

func MaskSecretForDisplay added in v1.21.0

func MaskSecretForDisplay(raw string) string

MaskSecretForDisplay returns a safe value for API responses. Keyring references are shown as-is.

func SaveAI added in v1.20.0

func SaveAI(configPath string, ai AIConfig) *errors.XError

SaveAI creates or updates the AI configuration in the specified config file.

func SaveProfile added in v1.1.0

func SaveProfile(configPath, name string, p Profile) *errors.XError

SaveProfile creates or updates a profile in the specified config file.

func SaveSSHProxy added in v1.1.0

func SaveSSHProxy(configPath, name string, sp SSHProxy) *errors.XError

SaveSSHProxy creates or updates an SSH proxy in the specified config file.

func SetConfigValue added in v0.0.10

func SetConfigValue(configPath, key, value string) *errors.XError

SetConfigValue sets a value in the config file using dot-notation key. Supported key patterns:

  • profile.<name>.<field>
  • ssh_proxy.<name>.<field>

Types

type AIConfig added in v1.20.0

type AIConfig struct {
	Provider       string `yaml:"provider" json:"provider"`               // default "openai"
	BaseURL        string `yaml:"base_url" json:"base_url"`               // default "https://api.openai.com/v1"
	APIKey         string `yaml:"api_key" json:"api_key"`                 // supports keyring:xxx reference
	AllowPlaintext bool   `yaml:"allow_plaintext" json:"allow_plaintext"` // allow plaintext API key
	Model          string `yaml:"model" json:"model"`                     // default "gpt-4o"
	MaxTokens      int    `yaml:"max_tokens" json:"max_tokens"`           // default 8192
}

AIConfig defines the AI LLM service configuration.

func AIConfigForAPI added in v1.21.0

func AIConfigForAPI(ai AIConfig) AIConfig

AIConfigForAPI returns a copy of ai with sensitive fields redacted for HTTP responses.

func MergeAIConfigSecrets added in v1.21.0

func MergeAIConfigSecrets(incoming, existing AIConfig) AIConfig

MergeAIConfigSecrets copies stored secrets from existing when incoming values are omitted or masked.

type File

type File struct {
	SSHProxies map[string]SSHProxy `yaml:"ssh_proxies" json:"ssh_proxies"`
	Profiles   map[string]Profile  `yaml:"profiles" json:"profiles"`
	MCP        MCPConfig           `yaml:"mcp" json:"mcp"`
	Web        WebConfig           `yaml:"web" json:"web"`
	Stats      stats.StatsConfig   `yaml:"stats" json:"stats"`
	AI         AIConfig            `yaml:"ai" json:"ai"`
}

File represents the xsql.yaml configuration structure. Constraint: config priority is CLI > ENV > Config.

func FileForAPI added in v1.21.0

func FileForAPI(f File) File

FileForAPI returns a copy of the config file with secrets redacted for HTTP responses.

func LoadConfig

func LoadConfig(opts Options) (File, string, *errors.XError)

LoadConfig loads the configuration file and returns the full config along with its path.

type MCPConfig added in v0.0.6

type MCPConfig struct {
	Transport        string        `yaml:"transport" json:"transport"` // stdio | streamable_http
	HTTP             MCPHTTPConfig `yaml:"http" json:"http"`
	MaxRows          int           `yaml:"max_rows" json:"max_rows"`                     // default MCP query row cap
	MaxRowsLimit     int           `yaml:"max_rows_limit" json:"max_rows_limit"`         // hard MCP ceiling for max_rows
	MaxResponseBytes int           `yaml:"max_response_bytes" json:"max_response_bytes"` // MCP query JSON size cap
}

MCPConfig defines the MCP server configuration.

type MCPHTTPConfig added in v0.0.6

type MCPHTTPConfig struct {
	Addr                string `yaml:"addr" json:"addr"`
	AuthToken           string `yaml:"auth_token" json:"auth_token"`                       // supports keyring:xxx reference
	AllowPlaintextToken bool   `yaml:"allow_plaintext_token" json:"allow_plaintext_token"` // allow plaintext token
}

MCPHTTPConfig defines the MCP Streamable HTTP transport configuration.

func MCPHTTPConfigForAPI added in v1.21.0

func MCPHTTPConfigForAPI(c MCPHTTPConfig) MCPHTTPConfig

MCPHTTPConfigForAPI redacts auth tokens for HTTP responses.

type Options

type Options struct {
	// ConfigPath: if non-empty, only this file is read (error if not found).
	ConfigPath string

	// CLI
	CLIProfile    string
	CLIProfileSet bool
	CLIFormat     string
	CLIFormatSet  bool

	// CLI AI
	CLIAIModel      string
	CLIAIModelSet   bool
	CLIAIBaseURL    string
	CLIAIBaseURLSet bool
	CLIAIAPIKey     string
	CLIAIAPIKeySet  bool

	// ENV (injected by caller for testability)
	EnvProfile   string
	EnvFormat    string
	EnvAIModel   string
	EnvAIBaseURL string
	EnvAIAPIKey  string

	// HomeDir is used for default path resolution (auto-detected if empty).
	HomeDir string

	// WorkDir is used for default paths (falls back to process cwd if empty).
	WorkDir string
}

type Profile

type Profile struct {
	Description string `yaml:"description" json:"description"` // description to distinguish databases
	Format      string `yaml:"format" json:"format"`

	// DB connection
	DB       string `yaml:"db" json:"db"`   // mysql | pg
	DSN      string `yaml:"dsn" json:"dsn"` // raw DSN (takes precedence)
	Host     string `yaml:"host" json:"host"`
	Port     int    `yaml:"port" json:"port"`
	User     string `yaml:"user" json:"user"`
	Password string `yaml:"password" json:"password"` // supports keyring:xxx reference
	Database string `yaml:"database" json:"database"`

	// Security options
	AllowPlaintext   bool `yaml:"allow_plaintext" json:"allow_plaintext"`       // allow plaintext password
	UnsafeAllowWrite bool `yaml:"unsafe_allow_write" json:"unsafe_allow_write"` // permit write-capable entrypoints; CLI also requires its runtime flag

	// Timeout settings (seconds)
	QueryTimeout  int `yaml:"query_timeout" json:"query_timeout"`   // query timeout, default 30s
	SchemaTimeout int `yaml:"schema_timeout" json:"schema_timeout"` // schema export timeout, default 60s

	// MaxRows caps rows returned by query (0 = unset; use CLI/API 0 for unlimited)
	MaxRows int `yaml:"max_rows" json:"max_rows"`

	// SSH proxy reference (refers to a name defined in ssh_proxies)
	SSHProxy string `yaml:"ssh_proxy" json:"ssh_proxy"`

	// Local port for the proxy (used by xsql proxy command)
	LocalPort int `yaml:"local_port" json:"local_port"`

	// Resolved SSH config (populated by Resolve, not read from YAML)
	SSHConfig *SSHProxy `yaml:"-" json:"-"`
}

func MergeProfileSecrets added in v1.21.0

func MergeProfileSecrets(incoming, existing Profile) Profile

MergeProfileSecrets copies stored secrets from existing when incoming values are omitted or masked.

func ProfileForAPI added in v1.21.0

func ProfileForAPI(p Profile) Profile

ProfileForAPI returns a copy of p with sensitive fields redacted for HTTP responses.

type ProfileInfo added in v0.0.10

type ProfileInfo struct {
	Name        string `json:"name"`
	Description string `json:"description,omitempty"`
	DB          string `json:"db"`
	Mode        string `json:"mode"` // "read-only" or "read-write"
}

func ProfileToInfo added in v0.0.10

func ProfileToInfo(name string, p Profile) ProfileInfo

type Resolved

type Resolved struct {
	ConfigPath  string
	ProfileName string
	Format      string
	Profile     Profile            // full profile for query use
	AllProfiles map[string]Profile // all configured profiles
	AI          AIConfig
}

func Resolve

func Resolve(opts Options) (Resolved, *errors.XError)

Resolve performs phase-1 config/profile/format merging: CLI > ENV > Config.

type SSHProxy

type SSHProxy struct {
	Host           string `yaml:"host" json:"host"`
	Port           int    `yaml:"port" json:"port"`
	User           string `yaml:"user" json:"user"`
	IdentityFile   string `yaml:"identity_file" json:"identity_file"`
	Passphrase     string `yaml:"passphrase" json:"passphrase"` // supports keyring:xxx reference
	KnownHostsFile string `yaml:"known_hosts_file" json:"known_hosts_file"`
	SkipHostKey    bool   `yaml:"skip_host_key" json:"skip_host_key"` // strongly discouraged
}

SSHProxy defines a reusable SSH proxy configuration.

func MergeSSHProxySecrets added in v1.21.0

func MergeSSHProxySecrets(incoming, existing SSHProxy) SSHProxy

MergeSSHProxySecrets copies stored secrets from existing when incoming values are omitted or masked.

func SSHProxyForAPI added in v1.21.0

func SSHProxyForAPI(sp SSHProxy) SSHProxy

SSHProxyForAPI returns a copy of sp with sensitive fields redacted for HTTP responses.

type WebConfig added in v1.0.0

type WebConfig struct {
	HTTP WebHTTPConfig `yaml:"http" json:"http"`
}

WebConfig defines the local web server configuration.

type WebHTTPConfig added in v1.0.0

type WebHTTPConfig struct {
	Addr                string `yaml:"addr" json:"addr"`
	AuthToken           string `yaml:"auth_token" json:"auth_token"`                       // supports keyring:xxx reference
	AllowPlaintextToken bool   `yaml:"allow_plaintext_token" json:"allow_plaintext_token"` // allow plaintext token
}

WebHTTPConfig defines the web HTTP transport configuration.

func WebHTTPConfigForAPI added in v1.21.0

func WebHTTPConfigForAPI(c WebHTTPConfig) WebHTTPConfig

WebHTTPConfigForAPI redacts auth tokens for HTTP responses.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL