Skip to content

Commit

Permalink
Add app.GetDecryptedSecrets method
Browse files Browse the repository at this point in the history
  • Loading branch information
Alexander Sheiko committed Apr 8, 2020
1 parent 08a27c5 commit 699b335
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 17 deletions.
23 changes: 23 additions & 0 deletions pkg/app2kube/crypto.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
"fmt"
"io"
"os"
"strings"
)

// CryptPrefix for encrypted values
Expand Down Expand Up @@ -82,3 +83,25 @@ func GetPassword() (string, error) {
}
return password, nil
}

// GetDecryptedSecrets return decrypted secrets of App
func (app *App) GetDecryptedSecrets() (secrets map[string]string, err error) {
secrets = make(map[string]string)
for key, value := range app.Secrets {
if strings.HasPrefix(value, CryptPrefix) {
password, err := GetPassword()
if err != nil {
return nil, err
}
value = value[len(CryptPrefix):]
decrypted, err := DecryptAES(password, value)
if err != nil {
return nil, err
}
secrets[key] = decrypted
} else {
secrets[key] = value
}
}
return secrets, nil
}
23 changes: 6 additions & 17 deletions pkg/app2kube/secret.go
Original file line number Diff line number Diff line change
@@ -1,30 +1,19 @@
package app2kube

import (
"strings"

apiv1 "k8s.io/api/core/v1"
)

// GetSecret resource
func (app *App) GetSecret() (secret *apiv1.Secret, err error) {
if len(app.Secrets) > 0 {
secretBytes := make(map[string][]byte)
for key, value := range app.Secrets {
if strings.HasPrefix(value, CryptPrefix) {
password, err := GetPassword()
if err != nil {
return nil, err
}
value = value[len(CryptPrefix):]
decrypted, err := DecryptAES(password, value)
if err != nil {
return nil, err
}
secretBytes[key] = []byte(decrypted)
} else {
secretBytes[key] = []byte(value)
}
secretDecrypted, err := app.GetDecryptedSecrets()
if err != nil {
return nil, err
}
for key, value := range secretDecrypted {
secretBytes[key] = []byte(value)
}

secret = &apiv1.Secret{
Expand Down

0 comments on commit 699b335

Please sign in to comment.