Handle newlines in secrets

Signed-off-by: Marcus Noble <github@marcusnoble.co.uk>
This commit is contained in:
Marcus Noble 2022-01-29 08:43:40 +00:00
parent 167c14cd6d
commit b5dda17f66
Signed by: AverageMarcus
GPG Key ID: B8F2DB8A7AEBAF78

12
main.go
View File

@ -62,11 +62,11 @@ func main() {
s.Data = make(map[string][]byte) s.Data = make(map[string][]byte)
if item.Username != "" { if item.Username != "" {
s.Data[keys["username"]] = []byte(item.Username) s.Data[keys["username"]] = []byte(parseNewlines(item.Username))
} }
if item.Password != "" { if item.Password != "" {
s.Data[keys["password"]] = []byte(item.Password) s.Data[keys["password"]] = []byte(parseNewlines(item.Password))
} }
if item.SecretText != "" { if item.SecretText != "" {
@ -76,11 +76,11 @@ func main() {
for _, line := range lines { for _, line := range lines {
parts := strings.SplitN(line, "=", 2) parts := strings.SplitN(line, "=", 2)
if len(parts) == 2 { if len(parts) == 2 {
s.Data[parts[0]] = []byte(parts[1]) s.Data[parts[0]] = []byte(parseNewlines(parts[1]))
} }
} }
} else { } else {
s.Data[keys["secretText"]] = []byte(item.SecretText) s.Data[keys["secretText"]] = []byte(parseNewlines(item.SecretText))
} }
} }
@ -145,3 +145,7 @@ func parseAnnotations(annotations map[string]string) map[string]string {
return keys return keys
} }
func parseNewlines(in string) string {
return strings.ReplaceAll(in, "\\n", "\n")
}