config

package
v1.16.3 Latest Latest
Warning

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

Go to latest
Published: Feb 22, 2026 License: GPL-3.0 Imports: 11 Imported by: 0

Documentation

Overview

Package config provides configuration management for GitLab backup application.

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrNotS3Source is returned when trying to parse a non-S3 source as S3.
	ErrNotS3Source = errors.New("not an S3 source")
	// ErrInvalidS3PathFormat is returned when S3 path format is invalid.
	ErrInvalidS3PathFormat = errors.New("invalid S3 path format (expected s3://bucket/key)")
	// ErrInvalidS3Path is returned when S3 bucket or key is empty.
	ErrInvalidS3Path = errors.New("invalid S3 path: bucket and key cannot be empty")
)

Functions

This section is empty.

Types

type Config

type Config struct {
	GitlabGroupID     int64       `env:"GITLABGROUPID"      env-default:"0"                  yaml:"gitlabGroupID"`
	GitlabProjectID   int64       `env:"GITLABPROJECTID"    env-default:"0"                  yaml:"gitlabProjectID"`
	GitlabToken       string      `env:"GITLAB_TOKEN"       yaml:"gitlabToken"`
	GitlabURI         string      `env:"GITLAB_URI"         env-default:"https://gitlab.com" yaml:"gitlabURI"`
	LocalPath         string      `env:"LOCALPATH"          env-default:""                   yaml:"localpath"`
	TmpDir            string      `env:"TMPDIR"             env-default:"/tmp"               yaml:"tmpdir"`
	ExportTimeoutMins int         `env:"EXPORT_TIMEOUT_MIN" env-default:"10"                 yaml:"exportTimeoutMins"`
	Hooks             hooks.Hooks `yaml:"hooks"`
	S3cfg             S3Config    `yaml:"s3cfg"`
	NoLogTime         bool        `env:"NOLOGTIME"          env-default:"false"              yaml:"noLogTime"`
	// Restore-specific fields (set via CLI flags, not config file)
	RestoreSource     string `yaml:"-"` // Archive path (local or s3://)
	RestoreTargetNS   string `yaml:"-"` // Target namespace/group
	RestoreTargetPath string `yaml:"-"` // Target project path
	RestoreOverwrite  bool   `yaml:"-"` // Overwrite existing project content
	StorageType       string `yaml:"-"` // Storage type: "local" or "s3"
}

Config holds the application configuration.

func NewConfigFromEnv

func NewConfigFromEnv() (*Config, error)

NewConfigFromEnv returns a new Config struct from the environment variables. It does not perform validation - validation happens after CLI overrides in main().

func NewConfigFromFile

func NewConfigFromFile(filePath string) (*Config, error)

NewConfigFromFile returns a new Config struct from the given file.

func NewConfigFromFileNoValidate added in v1.16.0

func NewConfigFromFileNoValidate(filePath string) (*Config, error)

NewConfigFromFileNoValidate loads config without validation (for CLI override pattern).

func (*Config) IsConfigValid

func (c *Config) IsConfigValid() bool

IsConfigValid returns true if the config is valid.

func (*Config) IsLocalConfigValid

func (c *Config) IsLocalConfigValid() bool

IsLocalConfigValid returns true if the local config is valid.

func (*Config) IsS3ConfigValid

func (c *Config) IsS3ConfigValid() bool

IsS3ConfigValid returns true if the S3 config is valid.

func (*Config) Redacted added in v1.15.0

func (c *Config) Redacted() string

Redacted returns a YAML representation of the config with sensitive fields redacted.

func (*Config) String

func (c *Config) String() string

func (*Config) Usage

func (c *Config) Usage()

Usage prints the usage of the config.

func (*Config) Validate added in v1.15.0

func (c *Config) Validate() error

Validate performs comprehensive validation of configuration parameters. This validation is for backup operations which require gitlabGroupID or gitlabProjectID.

func (*Config) ValidateForRestore added in v1.16.0

func (c *Config) ValidateForRestore() error

ValidateForRestore validates configuration for restore operations. Unlike Validate(), this does not require gitlabGroupID or gitlabProjectID.

type RestoreConfig added in v1.16.0

type RestoreConfig struct {
	Config

	// RestoreSource is the path to the archive (local or S3)
	RestoreSource string `env:"RESTORE_SOURCE" yaml:"restoreSource"`
	// RestoreTargetNS is the target namespace/group path
	RestoreTargetNS string `env:"RESTORE_TARGET_NS" yaml:"restoreTargetNS"`
	// RestoreTargetPath is the target project path
	RestoreTargetPath string `env:"RESTORE_TARGET_PATH" yaml:"restoreTargetPath"`
	// RestoreOverwrite allows overwriting existing project content
	RestoreOverwrite bool `env:"RESTORE_OVERWRITE" env-default:"false" yaml:"restoreOverwrite"`
}

RestoreConfig extends Config with restore-specific fields.

func (*RestoreConfig) GetFullProjectPath added in v1.16.0

func (c *RestoreConfig) GetFullProjectPath() string

GetFullProjectPath returns the full project path including namespace.

func (*RestoreConfig) IsS3Source added in v1.16.0

func (c *RestoreConfig) IsS3Source() bool

IsS3Source returns true if the restore source is an S3 path.

func (*RestoreConfig) ParseS3Source added in v1.16.0

func (c *RestoreConfig) ParseS3Source() (string, string, error)

ParseS3Source extracts bucket and key from an S3 path (s3://bucket/key).

func (*RestoreConfig) ValidateRestore added in v1.16.0

func (c *RestoreConfig) ValidateRestore() error

ValidateRestore performs validation specific to restore operations.

type S3Config

type S3Config struct {
	Endpoint   string `env:"S3ENDPOINT"            env-default:""   yaml:"endpoint"`
	BucketName string `env:"S3BUCKETNAME"          env-default:""   yaml:"bucketName"`
	BucketPath string `env:"S3BUCKETPATH"          env-default:""   yaml:"bucketPath"`
	Region     string `env:"S3REGION"              env-default:""   yaml:"region"`
	AccessKey  string `env:"AWS_ACCESS_KEY_ID"     yaml:"accessKey"` //nolint:gosec // G117: intentional
	SecretKey  string `env:"AWS_SECRET_ACCESS_KEY" yaml:"secretKey"`
}

S3Config holds the configuration for S3 storage backend.

Jump to

Keyboard shortcuts

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