forked from rancher/rancher
-
Notifications
You must be signed in to change notification settings - Fork 0
/
password.go
32 lines (30 loc) · 951 Bytes
/
password.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
package store
import (
"fmt"
"github.com/rancher/rancher/pkg/namespace"
"github.com/rancher/types/apis/core/v1"
"k8s.io/apimachinery/pkg/api/errors"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"strings"
)
func GetValueForPasswordField(name string, secrets v1.SecretInterface) (string, error) {
var value string
if name == "" {
return value, fmt.Errorf("empty secret name %s", name)
}
split := strings.SplitN(name, ":", 2)
if len(split) != 2 {
return value, fmt.Errorf("not a secret reference %s", name)
}
if split[0] != namespace.GlobalNamespace {
return value, fmt.Errorf("not rancher referenced secret %s", name)
}
secret, err := secrets.Controller().Lister().Get(namespace.GlobalNamespace, split[1])
if err != nil && errors.IsNotFound(err) {
secret, err = secrets.GetNamespaced(namespace.GlobalNamespace, name, metav1.GetOptions{})
}
if err != nil {
return value, err
}
return string(secret.Data[split[1]]), nil
}