config

package
v0.4.0 Latest Latest
Warning

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

Go to latest
Published: Sep 1, 2026 License: Apache-2.0 Imports: 19 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 (
	DefaultJWTHeader        = "Authorization"
	DefaultJWTIdentityClaim = "email"
)
View Source
const EnvPrefix = "HYPERFLEET"

EnvPrefix is the environment variable prefix for all HyperFleet configuration. All configuration can be set via environment variables using the format:

HYPERFLEET_<SECTION>_<KEY>=value

For example:

  • HYPERFLEET_SERVER_HOST=0.0.0.0
  • HYPERFLEET_DATABASE_PASSWORD=secret
  • HYPERFLEET_LOGGING_LEVEL=debug
View Source
const (
	// RedactedValue is used to mask sensitive data in logs and JSON output
	// Must match pkg/middleware/masking.go RedactedValue for consistency
	RedactedValue = "***REDACTED***"
)

Variables

This section is empty.

Functions

func AddAllConfigFlags added in v0.2.0

func AddAllConfigFlags(cmd *cobra.Command)

AddAllConfigFlags adds all configuration flags to the command This is a convenience function that adds all flag groups

func AddConfigFlag added in v0.2.0

func AddConfigFlag(cmd *cobra.Command)

AddConfigFlags adds the --config flag to the command This flag has highest priority in config file resolution

func AddDatabaseFlags added in v0.2.0

func AddDatabaseFlags(cmd *cobra.Command)

AddDatabaseFlags adds database configuration flags following standard naming Format: --db-<field> maps to HYPERFLEET_DATABASE_<FIELD> and database.<field>

func AddHealthFlags added in v0.2.0

func AddHealthFlags(cmd *cobra.Command)

AddHealthFlags adds health check configuration flags following standard naming Format: --health-<field> maps to HYPERFLEET_HEALTH_<FIELD> and health.<field>

func AddLoggingFlags added in v0.2.0

func AddLoggingFlags(cmd *cobra.Command)

AddLoggingFlags adds logging configuration flags following standard naming Format: --log-<field> maps to HYPERFLEET_LOGGING_<FIELD> and logging.<field>

func AddMetricsFlags added in v0.2.0

func AddMetricsFlags(cmd *cobra.Command)

AddMetricsFlags adds metrics configuration flags following standard naming Format: --metrics-<field> maps to HYPERFLEET_METRICS_<FIELD> and metrics.<field>

func AddServerFlags added in v0.2.0

func AddServerFlags(cmd *cobra.Command)

AddServerFlags adds server configuration flags following standard naming Format: --server-<field> maps to HYPERFLEET_SERVER_<FIELD> and server.<field>

func DumpConfig added in v0.2.0

func DumpConfig(config *ApplicationConfig) string

DumpConfig returns a human-readable string representation of configuration with sensitive fields redacted. Useful for debugging.

Types

type ApplicationConfig

type ApplicationConfig struct {
	Server   *ServerConfig               `mapstructure:"server" json:"server" validate:"required"`
	Metrics  *MetricsConfig              `mapstructure:"metrics" json:"metrics" validate:"required"`
	Health   *HealthConfig               `mapstructure:"health" json:"health" validate:"required"`
	Database *DatabaseConfig             `mapstructure:"database" json:"database" validate:"required"`
	Logging  *LoggingConfig              `mapstructure:"logging" json:"logging" validate:"required"`
	Tracing  *TracingConfig              `mapstructure:"tracing" json:"tracing" validate:"required"`
	Entities []registry.EntityDescriptor `mapstructure:"entities" json:"entities"`
}

ApplicationConfig holds all application configuration Follows HyperFleet Configuration Standard with validation and structured marshaling

func NewApplicationConfig

func NewApplicationConfig() *ApplicationConfig

NewApplicationConfig returns default ApplicationConfig with all sub-configs initialized These defaults can be overridden by config file, env vars, or CLI flags

type ConfigLoader added in v0.2.0

type ConfigLoader struct {
	// contains filtered or unexported fields
}

ConfigLoader handles loading and validating application configuration following the HyperFleet Configuration Standard.

func NewConfigLoader added in v0.2.0

func NewConfigLoader() *ConfigLoader

NewConfigLoader creates a new configuration loader

func (*ConfigLoader) Load added in v0.2.0

Load loads configuration from all sources according to priority: 1. Command-line flags (highest priority) 2. Environment variables 3. Configuration files 4. Defaults (lowest priority)

Returns validated ApplicationConfig or error if validation fails.

type DatabaseConfig

type DatabaseConfig struct {
	Dialect      string     `mapstructure:"dialect" json:"dialect" validate:"required,oneof=postgres"`
	Host         string     `mapstructure:"host" json:"host" validate:"required,hostname|ip"`
	HostFile     string     `mapstructure:"host_file" json:"host_file"`
	Name         string     `mapstructure:"name" json:"name" validate:"required"`
	NameFile     string     `mapstructure:"name_file" json:"name_file"`
	Username     string     `mapstructure:"username" json:"-"`
	UsernameFile string     `mapstructure:"username_file" json:"username_file"`
	Password     string     `mapstructure:"password" json:"-"`
	PasswordFile string     `mapstructure:"password_file" json:"password_file"`
	PortFile     string     `mapstructure:"port_file" json:"port_file"`
	SSL          SSLConfig  `mapstructure:"ssl" json:"ssl" validate:"required"`
	Pool         PoolConfig `mapstructure:"pool" json:"pool" validate:"required"`
	Port         int        `mapstructure:"port" json:"port" validate:"required,min=1,max=65535"`
	Debug        bool       `mapstructure:"debug" json:"debug"`
}

DatabaseConfig holds database connection configuration Follows HyperFleet Configuration Standard

func NewDatabaseConfig

func NewDatabaseConfig() *DatabaseConfig

NewDatabaseConfig returns default DatabaseConfig values These defaults can be overridden by config file, env vars, or CLI flags Includes defaults from HYPERFLEET-694 for connection pool management

func (*DatabaseConfig) ConnectionString

func (c *DatabaseConfig) ConnectionString(ssl bool) string

ConnectionString generates database connection string ssl parameter controls whether to include SSL settings

func (*DatabaseConfig) ConnectionStringWithName

func (c *DatabaseConfig) ConnectionStringWithName(name string, ssl bool) string

ConnectionStringWithName generates database connection string with custom database name This is useful for test databases. ssl parameter controls whether to include SSL settings.

func (*DatabaseConfig) LogSafeConnectionString

func (c *DatabaseConfig) LogSafeConnectionString(ssl bool) string

LogSafeConnectionString returns connection string with username and password redacted

func (*DatabaseConfig) LogSafeConnectionStringWithName

func (c *DatabaseConfig) LogSafeConnectionStringWithName(name string, ssl bool) string

LogSafeConnectionStringWithName returns connection string with custom name and username/password redacted This is useful for test databases.

func (DatabaseConfig) MarshalJSON added in v0.2.0

func (c DatabaseConfig) MarshalJSON() ([]byte, error)

MarshalJSON implements custom JSON marshaling to redact sensitive fields

func (*DatabaseConfig) ResolveFileOverrides added in v0.4.0

func (c *DatabaseConfig) ResolveFileOverrides() error

ResolveFileOverrides applies HYPERFLEET_DATABASE_*_FILE overrides

func (*DatabaseConfig) SetLogLevel added in v0.2.0

func (c *DatabaseConfig) SetLogLevel(globalLogLevel string) logger.LogLevel

SetLogLevel determines the GORM logger level based on database.debug flag and global logging level. Priority: database.debug > global logging level > default

Behavior:

  • database.debug=true → logger.Info (show all SQL queries)
  • logging.level=debug → logger.Info (show all SQL queries)
  • logging.level=error → logger.Silent (suppress all SQL logs)
  • default → logger.Warn (show only slow queries and errors)

type DeprecatedOTelConfig added in v0.4.0

type DeprecatedOTelConfig struct {
	Enabled bool `mapstructure:"enabled" json:"enabled"`
}

DeprecatedOTelConfig exists solely to let viper unmarshal the old logging.otel key without rejecting it as unknown.

type HealthConfig

type HealthConfig struct {
	Host            string        `mapstructure:"host" json:"host" validate:"required"`
	TLS             TLSConfig     `mapstructure:"tls" json:"tls" validate:"required"`
	Port            int           `mapstructure:"port" json:"port" validate:"required,min=1,max=65535"`
	ShutdownTimeout time.Duration `mapstructure:"shutdown_timeout" json:"shutdown_timeout" validate:"required"`
	DBPingTimeout   time.Duration `mapstructure:"db_ping_timeout" json:"db_ping_timeout"`
}

HealthConfig holds health check server configuration Follows HyperFleet Configuration Standard

func NewHealthConfig

func NewHealthConfig() *HealthConfig

NewHealthConfig returns default HealthConfig values These defaults can be overridden by config file, env vars, or CLI flags

func (*HealthConfig) BindAddress

func (h *HealthConfig) BindAddress() string

BindAddress returns bind address in host:port format Uses net.JoinHostPort to correctly handle IPv6 addresses

func (*HealthConfig) PingTimeout added in v0.4.0

func (h *HealthConfig) PingTimeout() time.Duration

func (*HealthConfig) TLSCertFile added in v0.4.0

func (h *HealthConfig) TLSCertFile() string

func (*HealthConfig) TLSEnabled added in v0.4.0

func (h *HealthConfig) TLSEnabled() bool

func (*HealthConfig) TLSKeyFile added in v0.4.0

func (h *HealthConfig) TLSKeyFile() string

func (*HealthConfig) Validate added in v0.2.0

func (h *HealthConfig) Validate() error

Validate validates health config durations

type JWTConfig added in v0.2.0

type JWTConfig struct {
	Configs []JWTIssuerConfig `mapstructure:"configs" json:"configs"`
	Enabled bool              `mapstructure:"enabled" json:"enabled"`
}

JWTConfig holds JWT authentication configuration with support for multiple issuers.

func (*JWTConfig) ApplyDefaults added in v0.3.1

func (c *JWTConfig) ApplyDefaults()

ApplyDefaults sets default values for optional fields in each issuer config. Call this after config loading and before Validate().

func (*JWTConfig) Validate added in v0.3.0

func (c *JWTConfig) Validate() error

type JWTIssuerConfig added in v0.3.1

type JWTIssuerConfig struct {
	CompiledPattern      *regexp.Regexp `mapstructure:"-" json:"-"`
	IssuerURL            string         `mapstructure:"issuer_url" json:"issuer_url" validate:"required,url"`
	JWKCertURL           string         `mapstructure:"jwk_cert_url" json:"jwk_cert_url" validate:"omitempty,url"`
	JWKCertFile          string         `mapstructure:"jwk_cert_file" json:"jwk_cert_file" validate:"omitempty,filepath"`
	JWKCertCAFile        string         `mapstructure:"jwk_cert_ca_file" json:"jwk_cert_ca_file" validate:"omitempty,filepath"` //nolint:lll
	Header               string         `mapstructure:"header" json:"header"`
	IdentityHeader       string         `mapstructure:"identity_header" json:"identity_header"`
	Audience             string         `mapstructure:"audience" json:"audience"`
	IdentityClaim        string         `mapstructure:"identity_claim" json:"identity_claim"`
	IdentityClaimPattern string         `mapstructure:"identity_claim_pattern" json:"identity_claim_pattern"`
}

JWTIssuerConfig holds configuration for a single JWT issuer (trust anchor). Each entry defines how to validate tokens from one identity provider.

type LoggingConfig

type LoggingConfig struct {
	Level   string        `mapstructure:"level" json:"level" validate:"required,oneof=debug info warn error"`
	Format  string        `mapstructure:"format" json:"format" validate:"required,oneof=json text"`
	Output  string        `mapstructure:"output" json:"output" validate:"required,oneof=stdout stderr"`
	Masking MaskingConfig `mapstructure:"masking" json:"masking" validate:"required"`
	// Deprecated: use TracingConfig.Enabled. Kept so UnmarshalExact accepts
	// existing config files that still carry logging.otel.enabled.
	OTel DeprecatedOTelConfig `mapstructure:"otel" json:"otel,omitempty"`
}

LoggingConfig holds logging configuration Follows HyperFleet Configuration Standard

func NewLoggingConfig

func NewLoggingConfig() *LoggingConfig

NewLoggingConfig returns default LoggingConfig values These defaults can be overridden by config file, env vars, or CLI flags

func (*LoggingConfig) GetSensitiveFieldsList

func (l *LoggingConfig) GetSensitiveFieldsList() []string

GetSensitiveFieldsList returns list of sensitive fields This is used by logger for masking

func (*LoggingConfig) GetSensitiveFieldsString added in v0.2.0

func (l *LoggingConfig) GetSensitiveFieldsString() string

GetSensitiveFieldsString returns fields as comma-separated string

func (*LoggingConfig) GetSensitiveHeadersList

func (l *LoggingConfig) GetSensitiveHeadersList() []string

GetSensitiveHeadersList returns list of sensitive headers This is used by logger for masking

func (*LoggingConfig) GetSensitiveHeadersString added in v0.2.0

func (l *LoggingConfig) GetSensitiveHeadersString() string

GetSensitiveHeadersString returns headers as comma-separated string

type MaskingConfig

type MaskingConfig struct {
	Headers []string `mapstructure:"headers" json:"headers"`
	Fields  []string `mapstructure:"fields" json:"fields"`
	Enabled bool     `mapstructure:"enabled" json:"enabled"`
}

MaskingConfig holds log masking configuration

type MetricsConfig

type MetricsConfig struct {
	Host                          string        `mapstructure:"host" json:"host" validate:"required"`
	TLS                           TLSConfig     `mapstructure:"tls" json:"tls" validate:"required"`
	Port                          int           `mapstructure:"port" json:"port" validate:"required,min=1,max=65535"`
	LabelMetricsInclusionDuration time.Duration `mapstructure:"label_metrics_inclusion_duration" json:"label_metrics_inclusion_duration" validate:"required"` //nolint:lll
	ReconciliationStuckThreshold  time.Duration `mapstructure:"reconciliation_stuck_threshold" json:"reconciliation_stuck_threshold" validate:"required"`     //nolint:lll
}

MetricsConfig holds Prometheus metrics server configuration Follows HyperFleet Configuration Standard

func NewMetricsConfig

func NewMetricsConfig() *MetricsConfig

NewMetricsConfig returns default MetricsConfig values These defaults can be overridden by config file, env vars, or CLI flags

func (*MetricsConfig) BindAddress

func (m *MetricsConfig) BindAddress() string

BindAddress returns bind address in host:port format Uses net.JoinHostPort to correctly handle IPv6 addresses

func (*MetricsConfig) TLSCertFile added in v0.4.0

func (m *MetricsConfig) TLSCertFile() string

func (*MetricsConfig) TLSEnabled added in v0.4.0

func (m *MetricsConfig) TLSEnabled() bool

func (*MetricsConfig) TLSKeyFile added in v0.4.0

func (m *MetricsConfig) TLSKeyFile() string

func (*MetricsConfig) Validate added in v0.3.0

func (m *MetricsConfig) Validate() error

Validate validates MetricsConfig fields that struct tags cannot enforce

type PoolConfig added in v0.2.0

type PoolConfig struct {
	MaxConnections     int           `mapstructure:"max_connections" json:"max_connections" validate:"required,min=1,max=200"` //nolint:lll // gofmt alignment
	MaxIdleConnections int           `mapstructure:"max_idle_connections" json:"max_idle_connections" validate:"min=0"`
	ConnMaxLifetime    time.Duration `mapstructure:"conn_max_lifetime" json:"conn_max_lifetime"`
	ConnMaxIdleTime    time.Duration `mapstructure:"conn_max_idle_time" json:"conn_max_idle_time"`
	RequestTimeout     time.Duration `mapstructure:"request_timeout" json:"request_timeout"`
	ConnRetryAttempts  int           `mapstructure:"conn_retry_attempts" json:"conn_retry_attempts" validate:"min=1"`
	ConnRetryInterval  time.Duration `mapstructure:"conn_retry_interval" json:"conn_retry_interval"`
	// HYPERFLEET-618: prevents indefinite blocking during migrations
	AdvisoryLockTimeout time.Duration `mapstructure:"advisory_lock_timeout" json:"advisory_lock_timeout"`
}

PoolConfig holds connection pool configuration Includes fields from HYPERFLEET-694 for connection lifecycle management

type SSLConfig added in v0.2.0

type SSLConfig struct {
	Mode         string `mapstructure:"mode" json:"mode" validate:"required,oneof=disable require verify-ca verify-full"`
	RootCertFile string `mapstructure:"root_cert_file" json:"root_cert_file"`
}

SSLConfig holds SSL/TLS configuration

type ServerConfig

type ServerConfig struct {
	Hostname          string         `mapstructure:"hostname" json:"hostname" validate:"omitempty,hostname|ip"`
	Host              string         `mapstructure:"host" json:"host" validate:"required,hostname|ip"`
	OpenAPISchemaPath string         `mapstructure:"openapi_schema_path" json:"openapi_schema_path"`
	TLS               TLSConfig      `mapstructure:"tls" json:"tls" validate:"required"`
	JWT               JWTConfig      `mapstructure:"jwt" json:"jwt" validate:"required"`
	Tenant            TenantConfig   `mapstructure:"tenant" json:"tenant" validate:"required"`
	Timeouts          TimeoutsConfig `mapstructure:"timeouts" json:"timeouts" validate:"required"`
	Port              int            `mapstructure:"port" json:"port" validate:"required,min=1,max=65535"`
}

ServerConfig holds HTTP/HTTPS server configuration Follows HyperFleet Configuration Standard

func NewServerConfig

func NewServerConfig() *ServerConfig

NewServerConfig returns default ServerConfig values These defaults can be overridden by config file, env vars, or CLI flags

func (*ServerConfig) BindAddress

func (s *ServerConfig) BindAddress() string

BindAddress returns bind address in host:port format Uses net.JoinHostPort to correctly handle IPv6 addresses

func (*ServerConfig) ReadTimeout

func (s *ServerConfig) ReadTimeout() time.Duration

func (*ServerConfig) TLSCertFile added in v0.3.1

func (s *ServerConfig) TLSCertFile() string

func (*ServerConfig) TLSEnabled added in v0.3.1

func (s *ServerConfig) TLSEnabled() bool

func (*ServerConfig) TLSKeyFile added in v0.3.1

func (s *ServerConfig) TLSKeyFile() string

func (*ServerConfig) WriteTimeout

func (s *ServerConfig) WriteTimeout() time.Duration

type TLSConfig added in v0.2.0

type TLSConfig struct {
	CertFile string `mapstructure:"cert_file" json:"cert_file" validate:"omitempty,filepath"`
	KeyFile  string `mapstructure:"key_file" json:"key_file" validate:"omitempty,filepath"`
	Enabled  bool   `mapstructure:"enabled" json:"enabled"`
}

TLSConfig holds TLS configuration

func (*TLSConfig) Validate added in v0.2.0

func (c *TLSConfig) Validate() error

Validate validates TLS configuration

type TenantConfig added in v0.4.0

type TenantConfig struct {
	SystemHeader string            `mapstructure:"system_header" json:"system_header"`
	Dimensions   []TenantDimension `mapstructure:"dimensions" json:"dimensions"`
	Enabled      bool              `mapstructure:"enabled" json:"enabled"`
}

TenantConfig holds tenant enforcement middleware configuration. Identity arrives as trusted headers injected by the gateway (Envoy + Authorino); the API never extracts JWT claims for tenancy.

func (*TenantConfig) Validate added in v0.4.0

func (c *TenantConfig) Validate() error

Validate enforces the tenant configuration invariants. A caller resolving zero dimensions must never reach the data layer (an empty tenancy map would contain-match every row), so at least one dimension must be required.

type TenantDimension added in v0.4.0

type TenantDimension struct {
	Header   string `mapstructure:"header" json:"header"`
	Key      string `mapstructure:"key" json:"key"`
	Required bool   `mapstructure:"required" json:"required"`
}

TenantDimension maps one trusted gateway-injected header to a tenancy key. Required dimensions must be present for a non-system caller to be granted a tenant context; see TenantConfig.Validate for the at-least-one-required rule.

type TimeoutsConfig added in v0.2.0

type TimeoutsConfig struct {
	Read  time.Duration `mapstructure:"read" json:"read" validate:"required"`
	Write time.Duration `mapstructure:"write" json:"write" validate:"required"`
}

TimeoutsConfig holds HTTP timeout configuration

func (*TimeoutsConfig) Validate added in v0.2.0

func (c *TimeoutsConfig) Validate() error

Validate validates timeout durations

type TracingConfig added in v0.4.0

type TracingConfig struct {
	ServiceName string `mapstructure:"service_name" json:"service_name"`
	Enabled     bool   `mapstructure:"enabled" json:"enabled"`
}

func NewTracingConfig added in v0.4.0

func NewTracingConfig() *TracingConfig

func (*TracingConfig) Validate added in v0.4.0

func (c *TracingConfig) Validate() error

Jump to

Keyboard shortcuts

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