refactor: make SecretValue internal
This commit is contained in:
parent
fadbbabe09
commit
4e92057f61
|
@ -14,7 +14,9 @@ import (
|
||||||
"github.com/schultz-is/passgen"
|
"github.com/schultz-is/passgen"
|
||||||
)
|
)
|
||||||
|
|
||||||
type SecretValue struct {
|
// secretValue represents a parsed `SECRET_FOO=v1 # length=bar` env var config
|
||||||
|
// secret definition.
|
||||||
|
type secretValue struct {
|
||||||
Version string
|
Version string
|
||||||
Length int
|
Length int
|
||||||
}
|
}
|
||||||
|
@ -73,23 +75,23 @@ func ParseGeneratedSecretName(secret string, appEnv config.App) string {
|
||||||
return withoutAppName[:idx]
|
return withoutAppName[:idx]
|
||||||
}
|
}
|
||||||
|
|
||||||
func ParseSecretEnvVarValue(secretValue string) (SecretValue, error) {
|
func ParseSecretEnvVarValue(secret string) (secretValue, error) {
|
||||||
values := strings.Split(secretValue, "#")
|
values := strings.Split(secret, "#")
|
||||||
if len(values) == 0 {
|
if len(values) == 0 {
|
||||||
return SecretValue{}, fmt.Errorf("unable to parse '%s'", secretValue)
|
return secretValue{}, fmt.Errorf("unable to parse '%s'", secret)
|
||||||
}
|
}
|
||||||
if len(values) == 1 {
|
if len(values) == 1 {
|
||||||
return SecretValue{Version: values[0], Length: 0}, nil
|
return secretValue{Version: values[0], Length: 0}, nil
|
||||||
} else {
|
} else {
|
||||||
split := strings.Split(values[1], "=")
|
split := strings.Split(values[1], "=")
|
||||||
parsed := split[len(split)-1]
|
parsed := split[len(split)-1]
|
||||||
stripped := strings.ReplaceAll(parsed, " ", "")
|
stripped := strings.ReplaceAll(parsed, " ", "")
|
||||||
length, err := strconv.Atoi(stripped)
|
length, err := strconv.Atoi(stripped)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return SecretValue{}, err
|
return secretValue{}, err
|
||||||
}
|
}
|
||||||
version := strings.ReplaceAll(values[0], " ", "")
|
version := strings.ReplaceAll(values[0], " ", "")
|
||||||
return SecretValue{Version: version, Length: length}, nil
|
return secretValue{Version: version, Length: length}, nil
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue