mirror of
https://github.com/moby/moby.git
synced 2022-11-09 12:21:53 -05:00
Handled wrong user credentials by re-init the auth file (it was impossible to login after having wrong crendentials)
This commit is contained in:
parent
18796d55a6
commit
0f68042053
1 changed files with 14 additions and 2 deletions
16
auth/auth.go
16
auth/auth.go
|
@ -75,6 +75,9 @@ func LoadConfig(rootPath string) (*AuthConfig, error) {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
arr := strings.Split(string(b), "\n")
|
arr := strings.Split(string(b), "\n")
|
||||||
|
if len(arr) < 2 {
|
||||||
|
return nil, fmt.Errorf("The Auth config file is empty")
|
||||||
|
}
|
||||||
origAuth := strings.Split(arr[0], " = ")
|
origAuth := strings.Split(arr[0], " = ")
|
||||||
origEmail := strings.Split(arr[1], " = ")
|
origEmail := strings.Split(arr[1], " = ")
|
||||||
authConfig, err := DecodeAuth(origAuth[1])
|
authConfig, err := DecodeAuth(origAuth[1])
|
||||||
|
@ -88,9 +91,14 @@ func LoadConfig(rootPath string) (*AuthConfig, error) {
|
||||||
|
|
||||||
// save the auth config
|
// save the auth config
|
||||||
func saveConfig(rootPath, authStr string, email string) error {
|
func saveConfig(rootPath, authStr string, email string) error {
|
||||||
|
confFile := path.Join(rootPath, CONFIGFILE)
|
||||||
|
if len(email) == 0 {
|
||||||
|
os.Remove(confFile)
|
||||||
|
return nil
|
||||||
|
}
|
||||||
lines := "auth = " + authStr + "\n" + "email = " + email + "\n"
|
lines := "auth = " + authStr + "\n" + "email = " + email + "\n"
|
||||||
b := []byte(lines)
|
b := []byte(lines)
|
||||||
err := ioutil.WriteFile(path.Join(rootPath, CONFIGFILE), b, 0600)
|
err := ioutil.WriteFile(confFile, b, 0600)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
@ -145,8 +153,12 @@ func Login(authConfig *AuthConfig) (string, error) {
|
||||||
if resp.StatusCode == 200 {
|
if resp.StatusCode == 200 {
|
||||||
status = "Login Succeeded\n"
|
status = "Login Succeeded\n"
|
||||||
storeConfig = true
|
storeConfig = true
|
||||||
|
} else if resp.StatusCode == 401 {
|
||||||
|
saveConfig(authConfig.rootPath, "", "")
|
||||||
|
return "", fmt.Errorf("Wrong login/password, please try again")
|
||||||
} else {
|
} else {
|
||||||
return "", fmt.Errorf("Login: %s", body)
|
return "", fmt.Errorf("Login: %s (Code: %d; Headers: %s)", body,
|
||||||
|
resp.StatusCode, resp.Header)
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
return "", fmt.Errorf("Registration: %s", reqBody)
|
return "", fmt.Errorf("Registration: %s", reqBody)
|
||||||
|
|
Loading…
Add table
Reference in a new issue