forked from kyma-project/kyma
-
Notifications
You must be signed in to change notification settings - Fork 0
/
creds_extractor.go
37 lines (30 loc) · 1.13 KB
/
creds_extractor.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
33
34
35
36
37
package azure
import (
"github.com/pkg/errors"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
coreCli "k8s.io/client-go/kubernetes/typed/core/v1"
)
const (
secretKeyAccountName = "storage-account"
secretKeyAccountKey = "storage-key"
)
// ExtractCredsFromSecretOutput contains all information which will be returned from ExtractCredsFromSecret function
type ExtractCredsFromSecretOutput struct {
AccountName string
AccountKey string
}
// ExtractCredsFromSecret returns account info for ABS from given k8s Secret
func ExtractCredsFromSecret(absSecretName string, secretCli coreCli.SecretInterface) (*ExtractCredsFromSecretOutput, error) {
secret, err := secretCli.Get(absSecretName, metav1.GetOptions{})
if err != nil {
return nil, errors.Wrapf(err, "while getting secret %q", absSecretName)
}
if secret.Data == nil || len(secret.Data) == 0 {
return nil, errors.Errorf("Secret %q data cannot be empty", absSecretName)
}
accountName, accountKey := secret.Data[secretKeyAccountName], secret.Data[secretKeyAccountKey]
return &ExtractCredsFromSecretOutput{
AccountKey: string(accountKey),
AccountName: string(accountName),
}, nil
}