Documentation
¶
Index ¶
- Constants
- Variables
- func CopyFile(src, dst string, perm os.FileMode) error
- func DefaultSSHKeyPath() (string, error)
- func Encrypt(passphrase, sshKeyPath, plaintext string) (string, error)
- func LoadGeneric[T any](defaults func() *T, options ...Option) (*T, error)
- func ResolvePath(path string) string
- func SaveGeneric[T any](cfg *T, options ...Option) error
- func WriteFileAtomic(path string, data []byte, perm os.FileMode) error
- type ConfigValidator
- type CredentialResolver
- type Loader
- type Option
- func WithConfigPath(path string) Option
- func WithConfigPathEnv(name string) Option
- func WithDotEnv(paths ...string) Option
- func WithDotEnvEnabled(enabled bool) Option
- func WithDotEnvOverride(enabled bool) Option
- func WithEmptyConfigAllowed(allowed bool) Option
- func WithEnvironment(enabled bool) Option
- func WithMissingConfigAllowed(allowed bool) Option
- func WithPathResolver(resolver Replacer) Option
- func WithSecurityPath(path string) Option
- func WithSecurityPathEnv(name string) Option
- func WithStrictJSON(enabled bool) Option
- func WithSymlinksAllowed(allowed bool) Option
- func WithValidation(enabled bool) Option
- type Options
- type PathResolver
- func (r PathResolver) CleanAbs(path string) string
- func (r PathResolver) ConfigPath(path string) string
- func (r PathResolver) ExpandMarkers(path string) string
- func (r PathResolver) ResolveAgainst(path string, baseDir string) string
- func (r PathResolver) SecurityPath(path string) string
- func (r PathResolver) WithDefaults() PathResolver
- type Replacer
- type SecureString
- func (s *SecureString) IsZero() bool
- func (s *SecureString) MarshalJSON() ([]byte, error)
- func (s *SecureString) MarshalYAML() (any, error)
- func (s *SecureString) Set(value string) *SecureString
- func (s *SecureString) String() string
- func (s *SecureString) UnmarshalJSON(value []byte) error
- func (s *SecureString) UnmarshalText(text []byte) error
- func (s *SecureString) UnmarshalYAML(value *yaml.Node) error
- type SecureStrings
Constants ¶
View Source
const ( EnvConfig = "APP_CONFIG" EnvSecurity = "APP_SECURITY" FileScheme = "file://" EncScheme = "enc://" PassphraseEnvVar = "CONFIG_KEY_PASSPHRASE" SSHKeyPathEnvVar = "CONFIG_SSH_KEY_PATH" )
Variables ¶
View Source
var ( ErrNilConfig = errors.New("config is nil") ErrUnsafePath = errors.New("unsafe config path") ErrInvalidConfig = errors.New("invalid config") )
View Source
var ErrDecryptionFailed = errors.New("credential: enc:// decryption failed (wrong passphrase or SSH key?)")
View Source
var ErrPassphraseRequired = errors.New("credential: enc:// passphrase required")
View Source
var PassphraseProvider = func() string { return os.Getenv(PassphraseEnvVar) }
View Source
var SSHKeyPathProvider = func() string { return os.Getenv(SSHKeyPathEnvVar) }
Functions ¶
func DefaultSSHKeyPath ¶
func LoadGeneric ¶
func ResolvePath ¶
func SaveGeneric ¶
Types ¶
type ConfigValidator ¶
type ConfigValidator interface {
Validate() error
}
type CredentialResolver ¶
type CredentialResolver struct {
// contains filtered or unexported fields
}
func NewCredentialResolver ¶
func NewCredentialResolver(baseDir string, allowSymlinks bool) *CredentialResolver
type Loader ¶
type Loader struct {
// contains filtered or unexported fields
}
func (*Loader) ConfigPath ¶
func (*Loader) SecurityPath ¶
type Option ¶
type Option func(*Options)
func WithConfigPath ¶
func WithConfigPathEnv ¶
func WithDotEnv ¶
func WithDotEnvEnabled ¶
func WithDotEnvOverride ¶
func WithEmptyConfigAllowed ¶
func WithEnvironment ¶
func WithPathResolver ¶
func WithSecurityPath ¶
func WithSecurityPathEnv ¶
func WithStrictJSON ¶
func WithSymlinksAllowed ¶
func WithValidation ¶
type Options ¶
type Options struct {
// ConfigPath is the main config file path; supported extensions are .env, .json, .yaml, and .yml.
ConfigPath string
// SecurityPath is an optional YAML overlay path for secrets and other private values.
SecurityPath string
// DotEnvPaths are optional additional .env files loaded before process env parsing.
DotEnvPaths []string
// ApplyEnvironment enables parsing values from process environment variables.
ApplyEnvironment bool
// LoadDotEnv enables loading DotEnvPaths; no implicit .env path is used.
LoadDotEnv bool
// OverrideDotEnv allows DotEnvPaths to overwrite already-set process environment values.
OverrideDotEnv bool
// AllowMissing returns defaults when the main config file does not exist.
AllowMissing bool
// AllowEmpty returns defaults when the main config file is empty.
AllowEmpty bool
// AllowSymlinks permits reading or writing through symlink paths.
AllowSymlinks bool
// StrictJSON rejects unknown JSON fields when parsing .json configs.
StrictJSON bool
// Validate runs Validate() hooks after loading and before saving.
Validate bool
// Resolver resolves path markers and environment-based path overrides.
Resolver Replacer
}
type PathResolver ¶
type PathResolver struct {
Getenv func(string) string
Getwd func() (string, error)
UserHomeDir func() (string, error)
TempDir func() string
EnvConfig string
EnvSecurity string
}
func DefaultPathResolver ¶
func DefaultPathResolver() PathResolver
func DefaultReplacer ¶
func DefaultReplacer() PathResolver
func (PathResolver) CleanAbs ¶
func (r PathResolver) CleanAbs(path string) string
func (PathResolver) ConfigPath ¶
func (r PathResolver) ConfigPath(path string) string
func (PathResolver) ExpandMarkers ¶
func (r PathResolver) ExpandMarkers(path string) string
func (PathResolver) ResolveAgainst ¶
func (r PathResolver) ResolveAgainst(path string, baseDir string) string
func (PathResolver) SecurityPath ¶
func (r PathResolver) SecurityPath(path string) string
func (PathResolver) WithDefaults ¶
func (r PathResolver) WithDefaults() PathResolver
type Replacer ¶
type Replacer = PathResolver
type SecureString ¶
type SecureString struct {
// contains filtered or unexported fields
}
func NewSecureString ¶
func NewSecureString(value string) *SecureString
func (*SecureString) IsZero ¶
func (s *SecureString) IsZero() bool
func (*SecureString) MarshalJSON ¶
func (s *SecureString) MarshalJSON() ([]byte, error)
func (*SecureString) MarshalYAML ¶
func (s *SecureString) MarshalYAML() (any, error)
func (*SecureString) Set ¶
func (s *SecureString) Set(value string) *SecureString
func (*SecureString) String ¶
func (s *SecureString) String() string
func (*SecureString) UnmarshalJSON ¶
func (s *SecureString) UnmarshalJSON(value []byte) error
func (*SecureString) UnmarshalText ¶
func (s *SecureString) UnmarshalText(text []byte) error
func (*SecureString) UnmarshalYAML ¶
func (s *SecureString) UnmarshalYAML(value *yaml.Node) error
type SecureStrings ¶
type SecureStrings []*SecureString
func SimpleSecureStrings ¶
func SimpleSecureStrings(val ...string) SecureStrings
func (SecureStrings) MarshalJSON ¶
func (s SecureStrings) MarshalJSON() ([]byte, error)
func (*SecureStrings) UnmarshalJSON ¶
func (s *SecureStrings) UnmarshalJSON(value []byte) error
func (*SecureStrings) Values ¶
func (s *SecureStrings) Values() []string
Click to show internal directories.
Click to hide internal directories.