diff --git a/internal/config/config.go b/internal/config/config.go index ef53cd5a21b7cc1789847df0d8aa39381171864d..3681b3e35cd40a2fa7d501b637729c39ed7e2d3e 100644 --- a/internal/config/config.go +++ b/internal/config/config.go @@ -63,13 +63,13 @@ func (rc *ResolvedConfig) HasFlag(name string) bool { return false } -// commandSuffix is the suffix keld recognises in .environ keys to indicate +// CommandSuffix is the suffix keld recognises in .environ keys to indicate // that the value is a shell command whose stdout should be captured and // used as the actual variable value (with the suffix stripped). // // For example, RESTIC_REPOSITORY_COMMAND = "op read ..." resolves to // RESTIC_REPOSITORY at execution time. -const commandSuffix = "_COMMAND" +const CommandSuffix = "_COMMAND" // HasEnvSource reports whether the given environment variable will have // a value when the restic process runs. It checks three sources in @@ -87,7 +87,7 @@ func (rc *ResolvedConfig) HasEnvSource(key string) bool { if _, ok := rc.Environ[key]; ok { return true } - if _, ok := rc.Environ[key+commandSuffix]; ok { + if _, ok := rc.Environ[key+CommandSuffix]; ok { return true } } diff --git a/internal/restic/exec.go b/internal/restic/exec.go index fe55d6c3086a1145d6f4ae20e2a9641f634c9651..eb0031b7dbbd652d84301888d07a883fb3cc3b5c 100644 --- a/internal/restic/exec.go +++ b/internal/restic/exec.go @@ -12,10 +12,7 @@ import ( "git.secluded.site/keld/internal/config" ) -// commandSuffix is the suffix keld recognises in .environ keys to indicate -// that the value is a shell command whose stdout should be captured and used -// as the actual environment variable value (with the suffix stripped). -const commandSuffix = "_COMMAND" + // resticNativeCommands lists .environ keys that restic handles natively. // Keld passes these through as-is rather than executing them. @@ -122,14 +119,14 @@ func buildArgv(exe string, cfg *config.ResolvedConfig) []string { // and FOO_COMMAND is removed from the map. func resolveEnvironCommands(environ map[string]string) error { for key, cmd := range environ { - if !strings.HasSuffix(key, commandSuffix) { + if !strings.HasSuffix(key, config.CommandSuffix) { continue } if resticNativeCommands[key] { continue } - baseKey := strings.TrimSuffix(key, commandSuffix) + baseKey := strings.TrimSuffix(key, config.CommandSuffix) if baseKey == "" { continue }