Help us shape the future of Go! Take the 2026 Go Developer Survey

config

package
v0.1.23 Latest Latest
Warning

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

Go to latest
Published: Oct 14, 2026 License: AGPL-3.0 Imports: 9 Imported by: 0

Documentation

Overview

Package config loads configuration with precedence defaults < YAML < GITDR_* env. Secrets never come from YAML, only env or a mounted file by path, and are wrapped in redact.Secret so they can't leak into logs.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func SplitList added in v0.1.23

func SplitList(s string) []string

SplitList splits a comma-separated list, trims the spaces around each item and drops the empty ones, so "a, b," is a and b. A list setting reads its environment variable with it, and the command line flag that sets it does the same, so the two cannot read one value differently.

Types

type AzureConfig

type AzureConfig struct {
	Account          string        `yaml:"account"`
	Container        string        `yaml:"container"`
	Endpoint         string        `yaml:"endpoint"`
	ConnectionString redact.Secret `yaml:"-"`
	// SubscriptionID and ResourceGroup locate the storage account in Azure Resource Manager,
	// the only API that reports whether the container's immutability policy is locked.
	// Optional; without them gitdr cannot confirm immutability on Azure and says unknown.
	SubscriptionID string `yaml:"subscriptionID"`
	ResourceGroup  string `yaml:"resourceGroup"`
}

AzureConfig configures the Azure Blob backend. The connection string is a secret (env only); real Azure uses DefaultAzureCredential with account/endpoint.

type BackupConfig

type BackupConfig struct {
	Concurrency int  `yaml:"concurrency"` // parallel repos, and artifacts verify reads at once; default 4
	Resume      bool `yaml:"resume"`      // skip repos a manifest records as copied on the run date
	LFS         bool `yaml:"lfs"`         // fetch Git LFS objects; default true
	// Recopy names repositories the run copies even when their refs have not moved, each exactly
	// as the manifest names it: owner/name, or group/subgroup/name on GitLab. --recopy and
	// GITDR_BACKUP_RECOPY take a comma-separated list. A copy made earlier the same UTC date is not
	// replaced, since its keys are create-only. SPEC §11.
	Recopy []string `yaml:"recopy"`
}

BackupConfig configures fan-out across repositories.

type Config

type Config struct {
	Source      SourceConfig      `yaml:"source"`
	Destination DestinationConfig `yaml:"destination"`
	Backup      BackupConfig      `yaml:"backup"`
	Manifest    ManifestConfig    `yaml:"manifest"`
	Metrics     MetricsConfig     `yaml:"metrics"`
	Encryption  EncryptionConfig  `yaml:"encryption"`
	WORM        WORMConfig        `yaml:"worm"`
	Log         LogConfig         `yaml:"log"`
}

Config is the full gitdr configuration.

func Default

func Default() *Config

Default returns the built-in default configuration.

func Load

func Load(path string) (*Config, error)

Load reads config from path (may be empty for "defaults + env only"), then applies environment overrides. The secrets it reads from the environment leave it (envSecret), so a second Load in the same process finds none there.

func (*Config) EncryptionKeyMaterial

func (c *Config) EncryptionKeyMaterial() ([]byte, error)

EncryptionKeyMaterial returns the raw encryption key material (from env) when encryption is enabled, or nil when disabled. The crypto package parses/validates it.

func (*Config) GitHubTokenFile added in v0.1.20

func (c *Config) GitHubTokenFile() (string, error)

GitHubTokenFile says which credential a GitHub run uses: the token file's path when source.github.tokenPath is set, and "" when an App private key is. Both, or neither, is an error.

Both is refused rather than resolved by precedence. The token file exists so that a run never holds the App key, which can mint a token for every installation of the App; a run handed both would hold it anyway, and quietly preferring one would hide that.

It reads nothing, and nothing Validate does touches the file either, so verify, restore and drill run without it. With a token file, appID and installationID are ignored rather than refused: the token already belongs to one installation.

func (*Config) ResolveGitHubPrivateKey

func (c *Config) ResolveGitHubPrivateKey() ([]byte, error)

ResolveGitHubPrivateKey returns the GitHub App private key PEM from env (preferred) or the configured file path.

func (*Config) ResolveManifestPublicKey

func (c *Config) ResolveManifestPublicKey() ([]byte, error)

ResolveManifestPublicKey returns the manifest public key from the configured path.

func (*Config) ResolveManifestSigningKey

func (c *Config) ResolveManifestSigningKey() ([]byte, error)

ResolveManifestSigningKey returns the manifest signing key from env (preferred) or the configured file path.

func (*Config) Validate

func (c *Config) Validate() error

Validate checks structural validity. Credential presence is checked by the source and destination constructors at the point of use, and Validate opens no file: verify, restore and drill call it and never build a source, so they never touch the GitHub token file.

func (*Config) ValidateDestination added in v0.1.21

func (c *Config) ValidateDestination() error

ValidateDestination checks the destination block alone, retention included, and nothing about the source. `gitdr doctor -only destination` checks a bucket with it, so a config written before any source is connected loads there; every other command calls Validate, which checks both.

type DestinationConfig

type DestinationConfig struct {
	Type      string          `yaml:"type"` // "s3" (AWS + S3-compatible) | "gcs" | "azure"
	S3        S3Config        `yaml:"s3"`
	GCS       GCSConfig       `yaml:"gcs"`
	Azure     AzureConfig     `yaml:"azure"`
	Retention RetentionConfig `yaml:"retention"`
}

DestinationConfig configures the storage destination.

type EncryptionConfig

type EncryptionConfig struct {
	Enabled bool          `yaml:"enabled"`
	Key     redact.Secret `yaml:"-"`
}

EncryptionConfig configures optional client-side envelope encryption. The key is a 32-byte AES-256 KEK supplied via env (GITDR_ENCRYPTION_KEY), never YAML.

type GCSConfig

type GCSConfig struct {
	Bucket   string `yaml:"bucket"`
	Endpoint string `yaml:"endpoint"` // empty = real GCS; set for an emulator
}

GCSConfig configures the Google Cloud Storage backend.

type GitHubConfig

type GitHubConfig struct {
	AppID          int64         `yaml:"appID"`
	InstallationID int64         `yaml:"installationID"`
	PrivateKeyPath string        `yaml:"privateKeyPath"`
	PrivateKey     redact.Secret `yaml:"-"` // injected from env only; never from YAML
	// TokenPath names a file holding an installation token, used instead of the App key. It
	// is a path, not a secret: the file is read by the source before every request and never
	// here, so a caller can replace it during a run. SPEC §3, "GitHub token file".
	TokenPath string `yaml:"tokenPath"`
	// MaxRateLimitWait bounds how long one run spends waiting for GitHub's rate limits, as a Go
	// duration such as 90m. Zero, the default, means the source's own: one hour. SPEC §6.
	MaxRateLimitWait time.Duration `yaml:"maxRateLimitWait"`
}

GitHubConfig holds the GitHub credential, which is one of two things: a GitHub App (appID, installationID and its private key), or a file holding an installation token somebody else minted. The private key is supplied via env (GITDR_GITHUB_APP_PRIVATE_KEY) or a file at PrivateKeyPath.

type GitLabConfig

type GitLabConfig struct {
	Token redact.Secret `yaml:"-"`
}

GitLabConfig holds the GitLab read-scoped access token (env only; never YAML).

type LogConfig

type LogConfig struct {
	Level  string `yaml:"level"`  // debug|info|warn|error
	Format string `yaml:"format"` // json|text
}

LogConfig configures structured logging.

type ManifestConfig

type ManifestConfig struct {
	SigningKeyPath string        `yaml:"signingKeyPath"`
	PublicKeyPath  string        `yaml:"publicKeyPath"`
	SigningKey     redact.Secret `yaml:"-"` // injected from env only; never from YAML
}

ManifestConfig configures run-manifest signing/verification keys. The signing key is supplied via env (GITDR_MANIFEST_SIGNING_KEY) or a file at SigningKeyPath.

type MetricsConfig

type MetricsConfig struct {
	// TextfilePath is the .prom file node_exporter's textfile collector scrapes.
	// Empty disables metrics output.
	TextfilePath string `yaml:"textfilePath"`
}

MetricsConfig configures Prometheus textfile-collector output.

type RetentionConfig

type RetentionConfig struct {
	Mode string `yaml:"mode"` // COMPLIANCE (default) | GOVERNANCE
	Days int    `yaml:"days"` // retain-until = now + Days
}

RetentionConfig configures object-lock retention applied to every write.

type S3Config

type S3Config struct {
	Bucket       string `yaml:"bucket"`
	Region       string `yaml:"region"`
	Endpoint     string `yaml:"endpoint"`     // empty = AWS; MinIO/Wasabi/B2 set their endpoint
	UsePathStyle bool   `yaml:"usePathStyle"` // true for MinIO and most S3-compatible stores
	// MultipartThreshold and PartSize are in bytes. An object larger than the threshold (0: 4 GiB)
	// is written in parts of at least PartSize (0: 64 MiB). Each is 5 MiB to 5 GiB when set. They
	// exist so a test can write in parts without writing gigabytes.
	MultipartThreshold int64 `yaml:"multipartThreshold"`
	PartSize           int64 `yaml:"partSize"`
}

S3Config configures the S3 (and S3-compatible) backend.

type SourceConfig

type SourceConfig struct {
	Type    string       `yaml:"type"`    // "github" (only backend in this build)
	BaseURL string       `yaml:"baseURL"` // empty = github.com; GHES sets https://host/api/v3 (M2+)
	Repo    string       `yaml:"repo"`    // single-repo selector "owner/name" (walking skeleton)
	Include []string     `yaml:"include"`
	Exclude []string     `yaml:"exclude"`
	GitHub  GitHubConfig `yaml:"github"`
	GitLab  GitLabConfig `yaml:"gitlab"`
}

SourceConfig configures the VCS source.

type WORMConfig

type WORMConfig struct {
	// Require maps to --require-worm. Default false: if the destination is not provably
	// immutable, gitdr warns loudly and proceeds. Set true to fail closed instead.
	Require bool `yaml:"require"`
}

WORMConfig configures the immutability check. WORM is recommended, not required.

Jump to

Keyboard shortcuts

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