config

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Mar 6, 2026 License: Apache-2.0 Imports: 10 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ConfigFile string

ConfigFile is the path to the config file (can be set via CONFIG_FILE env var or -config flag).

Functions

func DefaultSecretsPaths

func DefaultSecretsPaths() []string

DefaultSecretsPaths returns the default paths to check for secrets. These are common locations for Kubernetes secrets and Docker secrets.

func LoadSecretsFromDir

func LoadSecretsFromDir(dir string, prefix string, overwrite bool) error

LoadSecretsFromDir loads environment variables from files in a directory. Each file name becomes the environment variable name, and the file content becomes the value. This is useful for Kubernetes secrets mounted as files.

Example:

/etc/secrets/GITHUB_TOKEN contains "ghp_xxxx"
After calling LoadSecretsFromDir("/etc/secrets"), os.Getenv("GITHUB_TOKEN") returns "ghp_xxxx"

Options:

  • prefix: Optional prefix to add to env var names (e.g., "CS_" makes GITHUB_TOKEN -> CS_GITHUB_TOKEN)
  • overwrite: If true, overwrites existing env vars; if false, skips if already set

func LoadSecretsFromPaths

func LoadSecretsFromPaths(paths []string, prefix string, overwrite bool) error

LoadSecretsFromPaths loads secrets from multiple directories. This is useful when you have secrets in multiple locations. Directories are processed in order, so later directories can override earlier ones if overwrite=true.

Types

type CodeHost

type CodeHost struct {
	Type            string       `mapstructure:"type"`             // github, gitlab, bitbucket, github_enterprise, gitlab_self_hosted
	URL             string       `mapstructure:"url"`              // Base URL (required for self-hosted instances)
	Token           string       `mapstructure:"token"`            // Token or env var reference (e.g., "$CS_GITHUB_TOKEN")
	ExcludeArchived bool         `mapstructure:"exclude_archived"` // When true, archived repos are excluded from sync
	CleanupArchived bool         `mapstructure:"cleanup_archived"` // When true, auto-cleanup index for archived repos
	Repos           []string     `mapstructure:"repos"`            // Specific repos to index (optional, if empty syncs all accessible repos)
	RepoConfigs     []RepoConfig `mapstructure:"repo_configs"`     // Detailed per-repo configuration (branches, exclude, etc.)
}

CodeHost represents a code hosting provider configuration Token can be either a literal value or a reference to an environment variable (e.g., "$CS_GITHUB_TOKEN").

func (*CodeHost) ResolveToken

func (ch *CodeHost) ResolveToken() string

ResolveToken resolves the token value, expanding environment variable references If token starts with "$", it's treated as an env var reference (e.g., "$CS_GITHUB_TOKEN").

type Config

type Config struct {
	Server              ServerConfig        `mapstructure:"server"`
	Database            DatabaseConfig      `mapstructure:"database"`
	Redis               RedisConfig         `mapstructure:"redis"`
	Zoekt               ZoektConfig         `mapstructure:"zoekt"`
	Indexer             IndexerConfig       `mapstructure:"indexer"`
	Repos               ReposConfig         `mapstructure:"repos"`
	Scheduler           SchedulerConfig     `mapstructure:"scheduler"`
	Replace             ReplaceConfig       `mapstructure:"replace"`
	Sharding            ShardingConfig      `mapstructure:"sharding"`
	Search              SearchConfig        `mapstructure:"search"`
	RateLimit           RateLimitConfig     `mapstructure:"rate_limit"`
	Metrics             MetricsConfig       `mapstructure:"metrics"`
	Tracing             TracingConfig       `mapstructure:"tracing"`
	UI                  UIConfig            `mapstructure:"ui"`
	Security            SecurityConfig      `mapstructure:"security"`
	SCIP                SCIPConfig          `mapstructure:"scip"`
	CodeHosts           map[string]CodeHost `mapstructure:"codehosts"`
	ConnectionsReadOnly bool                `mapstructure:"connections_readonly"` // When true, connections can only be managed via config
	ReposReadOnly       bool                `mapstructure:"repos_readonly"`       // When true, repos can only be managed via sync (no manual add/delete)
}

Config holds all configuration for the application.

func Load

func Load() (*Config, error)

Load loads configuration with the following priority (highest to lowest): 1. Environment variables 2. Config file (config.yaml) 3. Default values.

func (*Config) GetCodeHost

func (c *Config) GetCodeHost(name string) (*CodeHost, bool)

GetCodeHost returns a code host configuration by name.

type DatabaseConfig

type DatabaseConfig struct {
	Driver          string        `mapstructure:"driver"` // postgres, mysql (auto-detected from URL if not set)
	URL             string        `mapstructure:"url"`
	MaxOpenConns    int           `mapstructure:"max_open_conns"`
	MaxIdleConns    int           `mapstructure:"max_idle_conns"`
	ConnMaxLifetime time.Duration `mapstructure:"conn_max_lifetime"`
}

type IndexerConfig

type IndexerConfig struct {
	Concurrency      int           `mapstructure:"concurrency"`
	IndexPath        string        `mapstructure:"index_path"`
	ReposPath        string        `mapstructure:"repos_path"`
	ReindexInterval  time.Duration `mapstructure:"reindex_interval"`
	ZoektBin         string        `mapstructure:"zoekt_bin"`
	CtagsBin         string        `mapstructure:"ctags_bin"`          // Path to ctags binary (for symbol indexing)
	RequireCtags     bool          `mapstructure:"require_ctags"`      // If true, ctags failures will fail indexing
	IndexAllBranches bool          `mapstructure:"index_all_branches"` // If true, index all branches (not just default)
	IndexTimeout     time.Duration `mapstructure:"index_timeout"`      // Timeout for zoekt-git-index operations (0 = no timeout/infinite, default: 0)
	MaxRepoSizeMB    int64         `mapstructure:"max_repo_size_mb"`   // Skip indexing repos larger than this size in MB (0 = no limit, default: 0)
}

type MetricsConfig

type MetricsConfig struct {
	Enabled bool   `mapstructure:"enabled"` // Enable Prometheus metrics endpoint
	Path    string `mapstructure:"path"`    // Path to expose metrics (default: /metrics)
}

MetricsConfig defines Prometheus metrics settings.

type RateLimitConfig

type RateLimitConfig struct {
	Enabled           bool    `mapstructure:"enabled"`             // Enable rate limiting
	RequestsPerSecond float64 `mapstructure:"requests_per_second"` // Requests per second per client
	BurstSize         int     `mapstructure:"burst_size"`          // Maximum burst size
}

RateLimitConfig defines rate limiting settings.

type RedisConfig

type RedisConfig struct {
	URL           string `mapstructure:"url"`
	Addr          string `mapstructure:"addr"`
	Password      string `mapstructure:"password"`
	DB            int    `mapstructure:"db"`
	TLSEnabled    bool   `mapstructure:"tls_enabled"`      // Enable TLS connection to Redis
	TLSSkipVerify bool   `mapstructure:"tls_skip_verify"`  // Skip TLS certificate verification (insecure)
	TLSCertFile   string `mapstructure:"tls_cert_file"`    // Path to client certificate file (for mTLS)
	TLSKeyFile    string `mapstructure:"tls_key_file"`     // Path to client key file (for mTLS)
	TLSCACertFile string `mapstructure:"tls_ca_cert_file"` // Path to CA certificate file
	TLSServerName string `mapstructure:"tls_server_name"`  // Override server name for TLS verification
}

type ReplaceConfig

type ReplaceConfig struct {
	Concurrency  int           `mapstructure:"concurrency"`   // Number of repositories to process in parallel (default: 3)
	CloneTimeout time.Duration `mapstructure:"clone_timeout"` // Timeout for git clone operations (default: 10m)
	PushTimeout  time.Duration `mapstructure:"push_timeout"`  // Timeout for git push operations (default: 5m)
	MaxFileSize  int64         `mapstructure:"max_file_size"` // Maximum file size to process in bytes (default: 10MB)
	WorkDir      string        `mapstructure:"work_dir"`      // Working directory for temporary clones (default: /tmp/codesearch-replace)
}

type RepoConfig

type RepoConfig struct {
	Name     string   `mapstructure:"name"`     // Repository name (e.g., "owner/repo")
	Branches []string `mapstructure:"branches"` // Specific branches to index (empty = default branch only)
	Exclude  bool     `mapstructure:"exclude"`  // If true, exclude this repo from indexing (can be re-included)
	Delete   bool     `mapstructure:"delete"`   // If true, permanently delete this repo (won't be re-added on sync)
}

RepoConfig represents per-repo configuration options. Used within CodeHost.RepoConfigs for detailed repo settings.

type ReposConfig

type ReposConfig struct {
	BasePath string `mapstructure:"base_path"`
}

type SCIPConfig

type SCIPConfig struct {
	Enabled   bool                          `mapstructure:"enabled"`    // Enable SCIP indexing
	AutoIndex bool                          `mapstructure:"auto_index"` // Auto-index after Zoekt indexing
	Timeout   time.Duration                 `mapstructure:"timeout"`    // Timeout for SCIP indexing operations
	WorkDir   string                        `mapstructure:"work_dir"`   // Working directory for temporary files (empty = system temp)
	CacheDir  string                        `mapstructure:"cache_dir"`  // Directory for SCIP SQLite databases (empty = derived from repos path)
	Languages map[string]SCIPLanguageConfig `mapstructure:"languages"`  // Per-language configuration
}

SCIPConfig defines settings for automatic SCIP code intelligence indexing.

type SCIPLanguageConfig

type SCIPLanguageConfig struct {
	Enabled    bool   `mapstructure:"enabled"`     // Enable this language's indexer
	BinaryPath string `mapstructure:"binary_path"` // Path to the indexer binary (empty = look in PATH)
}

SCIPLanguageConfig defines per-language SCIP indexer settings.

type SchedulerConfig

type SchedulerConfig struct {
	Enabled               bool          `mapstructure:"enabled"`
	PollInterval          time.Duration `mapstructure:"poll_interval"`           // Default time between syncs
	CheckInterval         time.Duration `mapstructure:"check_interval"`          // How often to check for repos needing sync
	StaleThreshold        time.Duration `mapstructure:"stale_threshold"`         // Max time in 'indexing' before repo is reset to 'pending'
	PendingJobTimeout     time.Duration `mapstructure:"pending_job_timeout"`     // Max time in 'pending' before repo is re-queued (default: 5m)
	MaxConcurrentChecks   int           `mapstructure:"max_concurrent_checks"`   // Parallel git fetch checks
	JobRetention          time.Duration `mapstructure:"job_retention"`           // How long to keep completed/failed jobs
	OrphanCleanupInterval time.Duration `mapstructure:"orphan_cleanup_interval"` // How often to check for orphan shards (0 to disable)
}

type SearchConfig

type SearchConfig struct {
	EnableStreaming bool `mapstructure:"enable_streaming"` // Enable true streaming from Zoekt (faster time-to-first-result)
}

SearchConfig defines search behavior settings.

type SecurityConfig

type SecurityConfig struct {
	EncryptionKey string `mapstructure:"encryption_key"` // Key for encrypting tokens at rest (empty = disabled)
}

SecurityConfig defines security settings.

type ServerConfig

type ServerConfig struct {
	Addr         string        `mapstructure:"addr"`
	ReadTimeout  time.Duration `mapstructure:"read_timeout"`
	WriteTimeout time.Duration `mapstructure:"write_timeout"`
}

type ShardingConfig

type ShardingConfig struct {
	Enabled         bool   `mapstructure:"enabled"`          // Enable hash-based sharding
	TotalShards     int    `mapstructure:"total_shards"`     // Total number of shards (indexer replicas)
	IndexerAPIPort  int    `mapstructure:"indexer_api_port"` // Port for indexer HTTP API (default: 8081)
	IndexerService  string `mapstructure:"indexer_service"`  // Headless service name for indexer discovery (default: code-search-indexer-headless)
	FederatedAccess bool   `mapstructure:"federated_access"` // Enable federated file browsing/replace via proxy
}

ShardingConfig defines settings for horizontal scaling with hash-based sharding.

type TracingConfig

type TracingConfig struct {
	Enabled        bool    `mapstructure:"enabled"`         // Enable OpenTelemetry tracing
	ServiceName    string  `mapstructure:"service_name"`    // Service name for traces (default: code-search)
	ServiceVersion string  `mapstructure:"service_version"` // Service version (default: 1.0.0)
	Environment    string  `mapstructure:"environment"`     // Deployment environment (default: development)
	Endpoint       string  `mapstructure:"endpoint"`        // OTLP endpoint (default: localhost:4317)
	Protocol       string  `mapstructure:"protocol"`        // Protocol: grpc or http (default: grpc)
	SampleRate     float64 `mapstructure:"sample_rate"`     // Sampling rate 0.0-1.0 (default: 1.0)
	Insecure       bool    `mapstructure:"insecure"`        // Disable TLS (default: true for local dev)
}

TracingConfig defines OpenTelemetry tracing settings.

type UIConfig

type UIConfig struct {
	HideReadOnlyBanner  bool `mapstructure:"hide_readonly_banner"`  // Hide the read-only mode banner in the UI
	HideFileNavigator   bool `mapstructure:"hide_file_navigator"`   // Hide the browse links in search results
	DisableBrowseAPI    bool `mapstructure:"disable_browse_api"`    // Completely disable the browse API endpoints
	HideReposPage       bool `mapstructure:"hide_repos_page"`       // Hide the Repositories page from navigation
	HideConnectionsPage bool `mapstructure:"hide_connections_page"` // Hide the Connections page from navigation
	HideJobsPage        bool `mapstructure:"hide_jobs_page"`        // Hide the Jobs page from navigation
	HideReplacePage     bool `mapstructure:"hide_replace_page"`     // Hide the Replace page from navigation
}

UIConfig defines UI display settings.

type ZoektConfig

type ZoektConfig struct {
	URL       string `mapstructure:"url"` // Single URL or comma-separated URLs for sharding
	IndexPath string `mapstructure:"index_path"`
	Shards    int    `mapstructure:"shards"` // Number of shards (for auto-discovery in K8s)
}

Jump to

Keyboard shortcuts

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