config

package
v1.13.0 Latest Latest
Warning

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

Go to latest
Published: Sep 25, 2026 License: Apache-2.0 Imports: 13 Imported by: ? modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Index

Constants

View Source
const MinBucketTokenLength = 32

MinBucketTokenLength is the minimum accepted length of a bucket-scoped token secret. Bucket tokens are machine-generated credentials, so there is no reason for a short one and a weak entry would silently widen the write surface.

Variables

This section is empty.

Functions

func BucketTokenCount added in v1.8.0

func BucketTokenCount() int

BucketTokenCount returns the number of loaded bucket-scoped tokens.

func BucketTokenExpiryWarnings added in v1.9.0

func BucketTokenExpiryWarnings(now time.Time, within time.Duration) (expired []string, expiringSoon []string)

BucketTokenExpiryWarnings reports which loaded tokens have already expired and which expire within the given window.

Returned rather than logged so that this package stays free of a logging dependency; the caller logs them at boot. An expired token is not an error: the deployment is still safe, it is the callers who will start failing, and an operator should hear about that before they do.

func BucketTokenMatches added in v1.8.0

func BucketTokenMatches(bucketName, secret string) bool

BucketTokenMatches reports whether secret is the configured, unexpired token for bucketName.

func BucketTokenMatchesAt added in v1.9.0

func BucketTokenMatchesAt(bucketName, secret string, now time.Time) bool

BucketTokenMatchesAt is BucketTokenMatches with an explicit clock, so expiry can be tested without waiting for it.

Expiry is evaluated here, per request, rather than at load time. The file is only read at boot, so checking it there would mean a token stayed valid until the next restart; checking it here makes it stop working at the moment it expires.

The comparison is constant time, and an unknown bucket still runs a full comparison against a zero digest so that "no token configured for this bucket" and "wrong secret" cost the same.

func GetEnvAsBoolOrDefault

func GetEnvAsBoolOrDefault(key string, defaultValue bool) bool

func GetEnvAsIntOrDefault

func GetEnvAsIntOrDefault(key string, defaultValue int) int

func GetEnvOrDefault

func GetEnvOrDefault(key, defaultValue string) string

func LoadBucketTokens added in v1.8.0

func LoadBucketTokens(path string) (int, error)

LoadBucketTokens reads bucket-scoped tokens from path and returns how many were loaded.

The line this draws is between "no scoped tokens" and "scoped tokens that cannot be read", not between "no file" and "some file".

Boot succeeds with zero bucket tokens when the file is missing, empty, or holds no entries ({}, {"buckets":[]}, {"buckets":null}). All of those are an operator saying there are none yet, which is the normal state of a deployment running on the general TOKEN alone, and none of them can be hiding a credential.

Boot fails when the file has content that cannot be parsed, or entries that fail validation. There the operator wrote definitions and believes they are active; starting anyway would serve with fewer credentials than configured and the callers using them would get "invalid token" with nothing to explain it.

Neither outcome affects the general TOKEN, which is validated separately and is accepted on every route regardless of what this file contains.

func ValidateGeneralToken added in v1.9.0

func ValidateGeneralToken(token string) error

ValidateGeneralToken reports whether the general TOKEN is fit to authenticate with. It is enforced at boot, not per request, so a bad value fails loudly at deploy time instead of quietly weakening every authenticated endpoint.

The same floor as bucket-scoped tokens applies: MinBucketTokenLength. A general token is strictly more powerful than a scoped one, since it is accepted on the operator routes as well, so it cannot reasonably be held to a weaker standard.

Errors never contain the token itself: they end up in the boot log.

Types

type AWSConfig

type AWSConfig struct {
	AccessKeyID     string
	SecretAccessKey string
	SessionToken    string
	Region          string
	Bucket          string
}

type AppConfig

type AppConfig struct {
	Name  string
	Port  int
	URL   string
	Token string
}

type BucketToken added in v1.8.0

type BucketToken struct {
	Bucket string `json:"bucket"`
	Token  string `json:"token"`
	// Label is an optional free-text note (who or what uses this token). It is
	// never used for authorization.
	Label string `json:"label,omitempty"`
	// ExpiresAt is an optional RFC 3339 timestamp. Empty means the token never
	// expires, which is what every entry written before this field existed means.
	ExpiresAt string `json:"expires_at,omitempty"`
}

BucketToken is one entry of the token file.

type Config

type Config struct {
	App      AppConfig
	Minio    MinioConfig
	AWS      AWSConfig
	Redis    RedisConfig
	Worker   WorkerConfig
	Features FeatureConfig
}

func Load

func Load() (*Config, error)

Load loads configuration from environment variables

func (*Config) Validate

func (c *Config) Validate() error

Validate validates the configuration

type FeatureConfig

type FeatureConfig struct {
	DisableDelete bool
	DisableUpload bool
	DisableGet    bool
}

type MinioConfig

type MinioConfig struct {
	Endpoint string
	User     string
	Password string
	UseSSL   bool
}

type RedisConfig

type RedisConfig struct {
	URL string
}

type TokenConfig added in v1.8.0

type TokenConfig struct {
	Buckets []BucketToken `json:"buckets"`
}

TokenConfig is the on-disk shape of the token file.

type WorkerConfig

type WorkerConfig struct {
	PoolSize      int
	QueueSize     int
	MaxRetries    int
	RetryDelay    time.Duration
	BatchSize     int
	FlushTimeout  time.Duration
	MaxConcurrent int
}

Jump to

Keyboard shortcuts

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