Skip to content

Commit f5ad5a9

Browse files
Merge pull request #13 from giusdp/store-user-login
Store logged in user in config key
2 parents dc51b99 + 4ff1a71 commit f5ad5a9

1 file changed

Lines changed: 16 additions & 7 deletions

File tree

auth/login.go

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -92,13 +92,7 @@ func LoginCmd() (*LoginResult, error) {
9292
}
9393
url := apihost + whiskLoginPath
9494

95-
if !strings.HasPrefix(apihost, "http://") && !strings.HasPrefix(apihost, "https://") {
96-
if apihost == "localhost" {
97-
apihost = "http://" + apihost
98-
} else {
99-
apihost = "https://" + apihost
100-
}
101-
}
95+
apihost = ensureSchema(apihost)
10296

10397
// try to get the user from the environment
10498
user := os.Getenv("OPS_USER")
@@ -164,6 +158,10 @@ func LoginCmd() (*LoginResult, error) {
164158
}
165159
}
166160

161+
if err := configMap.Insert("STATUS_LOGGED_USER", user); err != nil {
162+
log.Println("[Warning] Failed to insert STATUS_LOGGED_USER")
163+
}
164+
167165
err = configMap.SaveConfig()
168166
if err != nil {
169167
return nil, err
@@ -185,6 +183,17 @@ func LoginCmd() (*LoginResult, error) {
185183
}, nil
186184
}
187185

186+
func ensureSchema(apihost string) string {
187+
if !strings.HasPrefix(apihost, "http://") && !strings.HasPrefix(apihost, "https://") {
188+
if apihost == "localhost" {
189+
apihost = "http://" + apihost
190+
} else {
191+
apihost = "https://" + apihost
192+
}
193+
}
194+
return apihost
195+
}
196+
188197
func doLogin(url, user, password string) (map[string]string, error) {
189198
data := map[string]string{
190199
"login": user,

0 commit comments

Comments
 (0)