cliconfig

package
v1.26.4 Latest Latest
Warning

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

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

Documentation

Overview

Package cliconfig holds the tdtpcli YAML configuration model, shared by the v1 and v2 command lines. It used to live in cmd/tdtpcli (package main, unimportable); v2's database commands need the same file format, so the model moved here. Behaviour is unchanged — cmd/tdtpcli keeps type aliases below, and its code did not move.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func SaveConfig

func SaveConfig(filename string, config *Config) error

SaveConfig saves configuration to YAML file

Types

type AuditConfig

type AuditConfig struct {
	Enabled  bool                 `yaml:"enabled"`
	Level    string               `yaml:"level"` // minimal, standard, full
	File     string               `yaml:"file,omitempty"`
	MaxSize  int                  `yaml:"max_size_mb,omitempty"` // Max file size in MB
	Console  bool                 `yaml:"console,omitempty"`     // Log to console
	Database *AuditDatabaseConfig `yaml:"database,omitempty"`    // Log to a SQL database, in addition to file/console
}

AuditConfig for audit logging settings

type AuditDatabaseConfig

type AuditDatabaseConfig struct {
	Type            string `yaml:"type"`                        // sqlite, mysql, mssql, postgres
	DSN             string `yaml:"dsn"`                         // Raw connection string
	Table           string `yaml:"table,omitempty"`             // Table name (default: audit_log)
	BatchSize       int    `yaml:"batch_size,omitempty"`        // 0 = no batching (insert one row per entry)
	AutoCreateTable bool   `yaml:"auto_create_table,omitempty"` // Create the table (and indexes) if missing
}

AuditDatabaseConfig configures the audit log's own database sink. Deliberately separate from the pipeline's own Database config (which the audited operation reads/writes) — reusing that same connection would let the very process being audited also rewrite its own audit trail.

Migrating a SQLite audit database written before v1.20.1: rows from then carry Go's time.Time.String() form, complete with a zone abbreviation and a monotonic clock reading —

2026-07-28 11:12:31.8174159 +0300 EEST m=+10.312223101

New rows are canonical UTC. The two forms do not sort against each other, so range queries and retention stay unreliable for the old rows until they are rewritten or aged out. Nothing rewrites them automatically: an audit trail should not be edited as a side effect of an upgrade. To do it deliberately, after taking a copy:

UPDATE audit_log
   SET timestamp = strftime('%Y-%m-%d %H:%M:%f',
         rtrim(substr(timestamp, 1, 10 + instr(substr(timestamp, 12), ' ')))
         || substr(substr(timestamp, 12 + instr(substr(timestamp, 12), ' '), 5), 1, 3)
         || ':'
         || substr(substr(timestamp, 12 + instr(substr(timestamp, 12), ' '), 5), 4, 2)
       ) || '+00:00'
 WHERE timestamp LIKE '% m=%';

It reads each row's own recorded offset rather than assuming one, so a table spanning a DST change converts correctly. Sub-second precision drops to milliseconds, which is what SQLite's %f emits.

type BrokerConfig

type BrokerConfig struct {
	Type           string `yaml:"type"`                      // rabbitmq, msmq, kafka
	Host           string `yaml:"host,omitempty"`            // Broker host
	Port           int    `yaml:"port,omitempty"`            // Broker port
	User           string `yaml:"user,omitempty"`            // Username
	Password       string `yaml:"password,omitempty"`        // Password
	Queue          string `yaml:"queue,omitempty"`           // Queue/topic name
	VHost          string `yaml:"vhost,omitempty"`           // RabbitMQ vhost
	UseTLS         bool   `yaml:"use_tls,omitempty"`         // Use TLS/SSL (amqps) for RabbitMQ
	TLSSkipVerify  bool   `yaml:"tls_skip_verify,omitempty"` // Skip TLS certificate verification (self-signed certs)
	Exchange       string `yaml:"exchange,omitempty"`        // RabbitMQ exchange (default = "")
	RoutingKey     string `yaml:"routing_key,omitempty"`     // RabbitMQ routing key (default = queue name)
	Durable        bool   `yaml:"durable,omitempty"`         // Queue survives broker restart
	AutoDelete     bool   `yaml:"auto_delete,omitempty"`     // Queue deleted when no consumers
	Exclusive      bool   `yaml:"exclusive,omitempty"`       // Queue accessible by one connection only
	PassiveDeclare bool   `yaml:"passive_declare,omitempty"` // Don't create queue, just check it exists (avoids 406 PRECONDITION_FAILED)
	QueuePath      string `yaml:"queue_path,omitempty"`      // MSMQ: полный путь к очереди (например: ".\private$\tdtp_in")
	// Kafka-specific
	Brokers       []string `yaml:"brokers,omitempty"`        // Kafka: список брокеров (["localhost:9092"])
	ConsumerGroup string   `yaml:"consumer_group,omitempty"` // Kafka: consumer group ID
}

BrokerConfig contains message broker settings

type CircuitBreakerConfig

type CircuitBreakerConfig struct {
	Enabled          bool   `yaml:"enabled"`
	Threshold        uint32 `yaml:"threshold"`         // Failure threshold
	Timeout          int    `yaml:"timeout"`           // Timeout in seconds
	MaxConcurrent    int    `yaml:"max_concurrent"`    // Max concurrent calls
	SuccessThreshold uint32 `yaml:"success_threshold"` // Success threshold for recovery
}

CircuitBreakerConfig for circuit breaker settings

type Config

type Config struct {
	Database   DatabaseConfig   `yaml:"database"`
	Storage    storage.Config   `yaml:"storage,omitempty"`
	Export     ExportConfig     `yaml:"export,omitempty"`
	Tables     []string         `yaml:"tables,omitempty"`
	Broker     BrokerConfig     `yaml:"broker,omitempty"`
	Resilience ResilienceConfig `yaml:"resilience,omitempty"`
	Audit      AuditConfig      `yaml:"audit,omitempty"`
	Processors ProcessorsConfig `yaml:"processors,omitempty"`
	Security   SecurityConfig   `yaml:"security,omitempty"`
}

Config represents the main configuration structure

func CreateSampleConfig

func CreateSampleConfig(dbType string) *Config

CreateSampleConfig creates sample configuration for different database types

func LoadConfig

func LoadConfig(filename string) (*Config, error)

LoadConfig loads configuration from YAML file

type DatabaseConfig

type DatabaseConfig struct {
	Type        string `yaml:"type"`                   // sqlite, postgres, mssql, access
	Host        string `yaml:"host,omitempty"`         // For network databases
	Port        int    `yaml:"port,omitempty"`         // Database port
	Database    string `yaml:"database,omitempty"`     // Database name or file path
	User        string `yaml:"user,omitempty"`         // Username
	Password    string `yaml:"password,omitempty"`     // Password
	Schema      string `yaml:"schema,omitempty"`       // PostgreSQL schema (default: public)
	WindowsAuth bool   `yaml:"windows_auth,omitempty"` // MS SQL Windows authentication
	SSLMode     string `yaml:"sslmode,omitempty"`      // PostgreSQL SSL mode
	DSN         string `yaml:"dsn,omitempty"`          // Raw connection string (overrides other fields; required for access)
	Charset     string `yaml:"charset,omitempty"`      // Charset for string decoding, e.g. "windows-1251" (ODBC/legacy drivers)

	// StrictSchema restores VARCHAR(n)/CHAR(n) instead of TEXT when a
	// table is created during import (PostgreSQL adapter only). Off by
	// default: an oversized value then fails the insert instead of being
	// silently widened to TEXT. See adapters.Config.StrictSchema.
	StrictSchema bool `yaml:"strict_schema,omitempty"`
}

DatabaseConfig contains database connection settings

func (*DatabaseConfig) BuildDSN

func (c *DatabaseConfig) BuildDSN() string

BuildDSN constructs database connection string from config. If DSN is set explicitly, it is returned as-is (adapter handles raw connection strings).

type ExportConfig

type ExportConfig struct {
	Compress      bool   `yaml:"compress"`       // Enable compression by default
	CompressLevel int    `yaml:"compress_level"` // Compression level: 1-19 (zstd) or 6-7 (kanzi)
	CompressAlgo  string `yaml:"compress_algo"`  // Algorithm: "zstd" (default) or "kanzi"
}

ExportConfig contains export settings

type MaskRule

type MaskRule struct {
	Field    string `yaml:"field"`
	Strategy string `yaml:"strategy"` // email, phone, card, partial
}

MaskRule for field masking

type NormalizeRule

type NormalizeRule struct {
	Field    string `yaml:"field"`
	Strategy string `yaml:"strategy"` // email, phone, date, trim, uppercase, lowercase
}

NormalizeRule for field normalization

type ProcessorsConfig

type ProcessorsConfig struct {
	Mask      []MaskRule      `yaml:"mask,omitempty"`
	Validate  []ValidateRule  `yaml:"validate,omitempty"`
	Normalize []NormalizeRule `yaml:"normalize,omitempty"`
}

ProcessorsConfig for data processing settings

type ResilienceConfig

type ResilienceConfig struct {
	CircuitBreaker CircuitBreakerConfig `yaml:"circuit_breaker,omitempty"`
	Retry          RetryConfig          `yaml:"retry,omitempty"`
}

ResilienceConfig contains circuit breaker and retry settings

type RetryConfig

type RetryConfig struct {
	Enabled     bool   `yaml:"enabled"`
	MaxAttempts int    `yaml:"max_attempts"`
	Strategy    string `yaml:"strategy"` // constant, linear, exponential
	InitialWait int    `yaml:"initial_wait_ms"`
	MaxWait     int    `yaml:"max_wait_ms"`
	Jitter      bool   `yaml:"jitter"`
}

RetryConfig for retry mechanism settings

type SecurityConfig

type SecurityConfig struct {
	// MercuryURL is the xZMercury base URL used to bind and resolve encryption
	// keys. --mercury-url overrides it, so a one-off run can point elsewhere
	// without editing the file.
	MercuryURL string `yaml:"mercury_url,omitempty"`
}

SecurityConfig holds settings shared by every command that touches encryption, so they do not have to be repeated on each invocation.

It exists because the Mercury URL is needed symmetrically: by the exporter that binds a key and by every listener that decrypts. Passing it as a flag meant repeating one URL across eight workflow steps and every listener process, where a single stale copy silently produces packets nobody on the other side can open.

type ValidateRule

type ValidateRule struct {
	Field   string `yaml:"field"`
	Type    string `yaml:"type"` // regex, range, format
	Pattern string `yaml:"pattern,omitempty"`
	Min     string `yaml:"min,omitempty"`
	Max     string `yaml:"max,omitempty"`
}

ValidateRule for field validation

Jump to

Keyboard shortcuts

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