github.com/pluralsh/plural-cli@v0.9.5/pkg/proxy/secret.go (about) 1 package proxy 2 3 import ( 4 "fmt" 5 6 "github.com/pluralsh/plural-cli/pkg/kubernetes" 7 "github.com/pluralsh/plural-operator/apis/platform/v1alpha1" 8 9 v1 "k8s.io/api/core/v1" 10 ) 11 12 type UserCredentials struct { 13 User string 14 Password string 15 } 16 17 func fetchSecret(namespace string, k kubernetes.Kube, creds *v1alpha1.Credentials) (string, error) { 18 secret, err := k.Secret(namespace, creds.Secret) 19 if err != nil { 20 return "", err 21 } 22 23 val, ok := secret.Data[creds.Key] 24 if !ok { 25 return "", fmt.Errorf("Could not find credential key") 26 } 27 28 return string(val), nil 29 } 30 31 func fetchUserPassword(secret *v1.Secret, creds *v1alpha1.Credentials) (user *UserCredentials, err error) { 32 pwd, ok := secret.Data[creds.Key] 33 if !ok { 34 err = fmt.Errorf("Could not find password key") 35 return 36 } 37 38 username := creds.User 39 if creds.UserKey != "" { 40 uname, ok := secret.Data[creds.UserKey] 41 if !ok { 42 err = fmt.Errorf("Could not find password key") 43 return 44 } 45 username = string(uname) 46 } 47 48 if username == "" { 49 err = fmt.Errorf("No username found") 50 return 51 } 52 53 user = &UserCredentials{User: username, Password: string(pwd)} 54 return 55 }