-
Notifications
You must be signed in to change notification settings - Fork 286
/
env.go
54 lines (45 loc) · 1.7 KB
/
env.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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
package nutanix
import (
"fmt"
"os"
"github.com/nutanix-cloud-native/prism-go-client/environment/credentials"
anywherev1 "github.com/aws/eks-anywhere/pkg/api/v1alpha1"
"github.com/aws/eks-anywhere/pkg/constants"
)
const (
nutanixEndpointKey = "NUTANIX_ENDPOINT"
)
var osSetenv = os.Setenv
func setupEnvVars(datacenterConfig *anywherev1.NutanixDatacenterConfig) error {
if nutanixUsername, ok := os.LookupEnv(constants.EksaNutanixUsernameKey); ok && len(nutanixUsername) > 0 {
if err := osSetenv(constants.NutanixUsernameKey, nutanixUsername); err != nil {
return fmt.Errorf("unable to set %s: %v", constants.EksaNutanixUsernameKey, err)
}
} else {
return fmt.Errorf("%s is not set or is empty", constants.EksaNutanixUsernameKey)
}
if nutanixPassword, ok := os.LookupEnv(constants.EksaNutanixPasswordKey); ok && len(nutanixPassword) > 0 {
if err := osSetenv(constants.NutanixPasswordKey, nutanixPassword); err != nil {
return fmt.Errorf("unable to set %s: %v", constants.EksaNutanixPasswordKey, err)
}
} else {
return fmt.Errorf("%s is not set or is empty", constants.EksaNutanixPasswordKey)
}
if err := osSetenv(nutanixEndpointKey, datacenterConfig.Spec.Endpoint); err != nil {
return fmt.Errorf("unable to set %s: %v", nutanixEndpointKey, err)
}
return nil
}
// GetCredsFromEnv returns nutanix credentials based on the environment.
func GetCredsFromEnv() credentials.BasicAuthCredential {
username := os.Getenv(constants.EksaNutanixUsernameKey)
password := os.Getenv(constants.EksaNutanixPasswordKey)
return credentials.BasicAuthCredential{
PrismCentral: credentials.PrismCentralBasicAuth{
BasicAuth: credentials.BasicAuth{
Username: username,
Password: password,
},
},
}
}