-
Notifications
You must be signed in to change notification settings - Fork 27
/
config.go
106 lines (99 loc) · 3.93 KB
/
config.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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
package cloudmanager
import (
"fmt"
"log"
"strings"
)
// Config is a struct for user input
type configStruct struct {
RefreshToken string
SaSecretKey string
SaClientID string
Environment string
CVOHostName string
Simulator bool
AWSProfile string
AWSProfileFilePath string
AzureAuthMethods []string
ConnectorHost string
}
// Client is the main function to connect to the APi
func (c *configStruct) clientFun() (*Client, error) {
var client *Client
if c.Environment == "prod" {
log.Print("Prod Environment")
client = &Client{
CloudManagerHost: "https://api.bluexp.netapp.com",
AuthHost: "https://api.bluexp.netapp.com/auth/oauth/token",
SaAuthHost: "https://api.bluexp.netapp.com/auth/oauth/token",
Audience: "https://api.cloud.netapp.com",
Auth0Client: "Mu0V1ywgYteI6w1MbD15fKfVIUrNXGWC",
AMIFilter: "Setup-As-Service-AMI-Prod*",
AWSAccount: "952013314444",
GCPDeploymentManager: "https://www.googleapis.com",
GCPCompute: "https://compute.googleapis.com",
GCPImageProject: "netapp-cloudmanager",
GCPImageFamily: "cloudmanager",
CVSHostName: "https://api.bluexp.netapp.com/cloud-volumes/cvs",
}
} else if c.Environment == "stage" {
log.Print("Stage Environment")
client = &Client{
CloudManagerHost: "https://staging.api.bluexp.netapp.com",
AuthHost: "https://staging.api.bluexp.netapp.com/auth/oauth/token",
SaAuthHost: "https://staging.api.bluexp.netapp.com/auth/oauth/token",
Audience: "https://api.cloud.netapp.com",
Auth0Client: "O6AHa7kedZfzHaxN80dnrIcuPBGEUvEv",
AMIFilter: "Setup-As-Service-AMI-*",
AWSAccount: "282316784512",
GCPDeploymentManager: "https://www.googleapis.com",
GCPCompute: "https://compute.googleapis.com",
GCPImageProject: "tlv-automation",
GCPImageFamily: "occm-automation",
AzureEnvironmentForOCCM: "stage",
CVSHostName: "https://staging.api.bluexp.netapp.com/cloud-volumes/cvs",
}
} else if c.Environment == "dev" {
log.Print("Dev Environment")
client = &Client{
CloudManagerHost: "https://dev.api.bluexp.netapp.com",
AuthHost: "https://staging.api.bluexp.netapp.com/auth/oauth/token",
SaAuthHost: "https://staging.api.bluexp.netapp.com/auth/oauth/token",
Audience: "https://api.cloud.netapp.com",
Auth0Client: "O6AHa7kedZfzHaxN80dnrIcuPBGEUvEv",
AMIFilter: "Setup-As-Service-AMI-*",
AWSAccount: "282316784512",
GCPDeploymentManager: "https://www.googleapis.com",
GCPCompute: "https://compute.googleapis.com",
GCPImageProject: "tlv-automation",
GCPImageFamily: "occm-automation",
AzureEnvironmentForOCCM: "stage",
CVSHostName: "https://dev.api.bluexp.netapp.com/cloud-volumes/cvs",
}
} else {
return &Client{}, fmt.Errorf("expected environment to be one of [prod stage dev]: %s", c.Environment)
}
if c.SaSecretKey != "" && c.SaClientID != "" {
client.SetServiceCredential(c.SaSecretKey, c.SaClientID)
} else if c.RefreshToken != "" {
client.SetRefreshToken(c.RefreshToken)
} else {
return &Client{}, fmt.Errorf("expected refresh_token or sa_secret_key and sa_client_id")
}
if c.ConnectorHost != "" {
if strings.HasPrefix(c.ConnectorHost, "https://") {
client.CloudManagerHost = c.ConnectorHost
} else if strings.HasPrefix(c.ConnectorHost, "http://") {
client.CloudManagerHost = c.ConnectorHost
} else {
client.CloudManagerHost = fmt.Sprintf("https://%s", c.ConnectorHost)
}
}
if c.Simulator {
client.SetSimulator(c.Simulator)
}
client.AWSProfile = c.AWSProfile
client.AWSProfileFilePath = c.AWSProfileFilePath
client.AzureAuthMethods = c.AzureAuthMethods
return client, nil
}