feat: parse secret text as multiple secrets
This commit is contained in:
parent
9a02a817b9
commit
2ed79284e3
@ -44,6 +44,7 @@ metadata:
|
|||||||
kube-1password/username-key: "user" # The key the username should be saved as in the Secret resource (default: `username`)
|
kube-1password/username-key: "user" # The key the username should be saved as in the Secret resource (default: `username`)
|
||||||
kube-1password/password-key: "pass" # The key the password should be saved as in the Secret resource (default: `password`)
|
kube-1password/password-key: "pass" # The key the password should be saved as in the Secret resource (default: `password`)
|
||||||
kube-1password/secret-text-key: "note" # The key the secret text should be saved as in the Secret resource (default: `secretText`)
|
kube-1password/secret-text-key: "note" # The key the secret text should be saved as in the Secret resource (default: `secretText`)
|
||||||
|
kube-1password/secret-text-parse: "true" # Parse the secret texts as individual secret values in format `key=value` (default: ``)
|
||||||
type: Opaque
|
type: Opaque
|
||||||
```
|
```
|
||||||
|
|
||||||
|
13
main.go
13
main.go
@ -6,6 +6,7 @@ import (
|
|||||||
"log"
|
"log"
|
||||||
"os"
|
"os"
|
||||||
"os/user"
|
"os/user"
|
||||||
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"git.cloud.cluster.fun/AverageMarcus/kube-1password-secrets/internal/onepassword"
|
"git.cloud.cluster.fun/AverageMarcus/kube-1password-secrets/internal/onepassword"
|
||||||
@ -21,6 +22,7 @@ const (
|
|||||||
usernameAnnotation = "kube-1password/username-key"
|
usernameAnnotation = "kube-1password/username-key"
|
||||||
passwordAnnotation = "kube-1password/password-key"
|
passwordAnnotation = "kube-1password/password-key"
|
||||||
secretTextAnnotation = "kube-1password/secret-text-key"
|
secretTextAnnotation = "kube-1password/secret-text-key"
|
||||||
|
secretTextParseAnnotation = "kube-1password/secret-text-parse"
|
||||||
)
|
)
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
@ -68,8 +70,19 @@ func main() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if item.SecretText != "" {
|
if item.SecretText != "" {
|
||||||
|
if s.ObjectMeta.Annotations[secretTextParseAnnotation] != "" {
|
||||||
|
// Parse secret text as individual secrets
|
||||||
|
lines := strings.Split(item.SecretText, "\n")
|
||||||
|
for _, line := range lines {
|
||||||
|
parts := strings.Split(line, "=")
|
||||||
|
if len(parts) == 2 {
|
||||||
|
s.Data[parts[0]] = []byte(parts[1])
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
s.Data[keys["secretText"]] = []byte(item.SecretText)
|
s.Data[keys["secretText"]] = []byte(item.SecretText)
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if _, err := clientset.CoreV1().Secrets(s.GetNamespace()).Update(context.Background(), &s, metav1.UpdateOptions{}); err != nil {
|
if _, err := clientset.CoreV1().Secrets(s.GetNamespace()).Update(context.Background(), &s, metav1.UpdateOptions{}); err != nil {
|
||||||
log.Println("[ERROR] Could not update secret value", err)
|
log.Println("[ERROR] Could not update secret value", err)
|
||||||
|
Loading…
Reference in New Issue
Block a user