Files
archie/internal/infrastructure/configuration/setup/secretref.go
T
sam dcc4a8fd07 chore: remove Yaegi
yaegiutil, the go.mod dependency, the .yaegi host-code entry and the legacy
guard stages for .archie/gate.go and .archie/stages are gone.
2026-10-04 03:08:46 +11:00

34 lines
1.2 KiB
Go

package setup
import (
"fmt"
"regexp"
"strings"
"github.com/samcharles93/archie-core/internal/config"
)
// engineNameRe is the shape a secret engine name must have. Engine names are
// identifiers -- "env", "bws", "vault" -- and an installed extension's package
// name, so this is deliberately no tighter than an identifier.
var engineNameRe = regexp.MustCompile(`^[A-Za-z0-9_-]+$`)
// ParseSecretRef parses an "engine:key" secret reference.
func ParseSecretRef(s string) (config.SecretRef, error) {
engine, key, ok := strings.Cut(s, ":")
if !ok {
return config.SecretRef{}, fmt.Errorf("secret reference %q must be engine:key, e.g. env:ARCHIE_GITHUB_TOKEN", s)
}
engine, key = strings.TrimSpace(engine), strings.TrimSpace(key)
if engine == "" || key == "" {
return config.SecretRef{}, fmt.Errorf("secret reference %q must name both an engine and a key, e.g. env:ARCHIE_GITHUB_TOKEN", s)
}
if !engineNameRe.MatchString(engine) {
return config.SecretRef{}, fmt.Errorf("secret reference engine %q is not a valid engine name", engine)
}
if strings.ContainsAny(key, ": \t\n") {
return config.SecretRef{}, fmt.Errorf("secret reference key %q must not contain whitespace or a colon", key)
}
return config.SecretRef{Engine: engine, Key: key}, nil
}