config

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Mar 26, 2026 License: MIT Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

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 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 File

type File struct {
	SSHProxies map[string]SSHProxy `yaml:"ssh_proxies"`
	Profiles   map[string]Profile  `yaml:"profiles"`
	MCP        MCPConfig           `yaml:"mcp"`
}

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

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"` // stdio | streamable_http
	HTTP      MCPHTTPConfig `yaml:"http"`
}

MCPConfig defines the MCP server configuration.

type MCPHTTPConfig added in v0.0.6

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

MCPHTTPConfig defines the MCP Streamable HTTP transport configuration.

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

	// ENV (injected by caller for testability)
	EnvProfile string
	EnvFormat  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"` // description to distinguish databases
	Format      string `yaml:"format"`

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

	// Security options
	AllowPlaintext   bool `yaml:"allow_plaintext"`    // allow plaintext password
	UnsafeAllowWrite bool `yaml:"unsafe_allow_write"` // allow write operations (bypass read-only protection)

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

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

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

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

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
}

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"`
	Port           int    `yaml:"port"`
	User           string `yaml:"user"`
	IdentityFile   string `yaml:"identity_file"`
	Passphrase     string `yaml:"passphrase"` // supports keyring:xxx reference
	KnownHostsFile string `yaml:"known_hosts_file"`
	SkipHostKey    bool   `yaml:"skip_host_key"` // strongly discouraged
}

SSHProxy defines a reusable SSH proxy configuration.

Jump to

Keyboard shortcuts

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