-
Notifications
You must be signed in to change notification settings - Fork 929
/
login.go
121 lines (102 loc) · 2.46 KB
/
login.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
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
package helpers
import (
"fmt"
"os"
"strconv"
"strings"
"time"
. "github.com/onsi/gomega"
. "github.com/onsi/gomega/gexec"
)
func SetAPI() (string, string) {
apiURL := GetAPI()
skipSSLValidation := skipSSLValidation()
Eventually(CF("api", apiURL, skipSSLValidation)).Should(Exit(0))
return apiURL, skipSSLValidation
}
func UnsetAPI() {
Eventually(CF("api", "--unset")).Should(Exit(0))
}
func skipSSLValidation() string {
if skip, err := strconv.ParseBool(os.Getenv("SKIP_SSL_VALIDATION")); err == nil && !skip {
return ""
}
return "--skip-ssl-validation"
}
func GetAPI() string {
apiURL := os.Getenv("CF_INT_API")
if apiURL == "" {
return "https://api.bosh-lite.com"
}
if !strings.HasPrefix(apiURL, "http") {
apiURL = fmt.Sprintf("https://%s", apiURL)
}
return apiURL
}
func LoginCF() string {
username, password := GetCredentials()
env := map[string]string{
"CF_USERNAME": username,
"CF_PASSWORD": password,
}
for i := 0; i < 3; i++ {
session := CFWithEnv(env, "auth")
Eventually(session).Should(Exit())
if session.ExitCode() == 0 {
break
}
time.Sleep(3 * time.Second)
}
return username
}
func LoginCFWithClientCredentials() string {
username, password := SkipIfClientCredentialsNotSet()
env := map[string]string{
"CF_USERNAME": username,
"CF_PASSWORD": password,
}
Eventually(CFWithEnv(env, "auth", "--client-credentials")).Should(Exit(0))
return username
}
// GetCredentials returns back the username and the password.
func GetCredentials() (string, string) {
username := os.Getenv("CF_INT_USERNAME")
if username == "" {
username = "admin"
}
password := os.Getenv("CF_INT_PASSWORD")
if password == "" {
password = "admin"
}
return username, password
}
// GetOIDCCredentials returns back the username and the password for OIDC origin.
func GetOIDCCredentials() (string, string) {
username := os.Getenv("CF_INT_OIDC_USERNAME")
if username == "" {
username = "admin_oidc"
}
password := os.Getenv("CF_INT_OIDC_PASSWORD")
if password == "" {
password = "admin"
}
return username, password
}
func LogoutCF() {
Eventually(CF("logout")).Should(Exit(0))
}
func TargetOrgAndSpace(org string, space string) {
Eventually(CF("target", "-o", org, "-s", space)).Should(Exit(0))
}
func TargetOrg(org string) {
Eventually(CF("target", "-o", org)).Should(Exit(0))
}
func ClearTarget() {
LogoutCF()
LoginCF()
}
func SetupCF(org string, space string) {
LoginCF()
CreateOrgAndSpace(org, space)
TargetOrgAndSpace(org, space)
}