Signed-off-by: mqliang <mqliang.zju@gmail.com>
| ... | ... |
@@ -23,11 +23,11 @@ func Login(authConfig *cliconfig.AuthConfig, registryEndpoint *Endpoint) (string |
| 23 | 23 |
// loginV1 tries to register/login to the v1 registry server. |
| 24 | 24 |
func loginV1(authConfig *cliconfig.AuthConfig, registryEndpoint *Endpoint) (string, error) {
|
| 25 | 25 |
var ( |
| 26 |
- status string |
|
| 27 |
- reqBody []byte |
|
| 28 |
- err error |
|
| 29 |
- reqStatusCode = 0 |
|
| 30 |
- serverAddress = authConfig.ServerAddress |
|
| 26 |
+ status string |
|
| 27 |
+ respBody []byte |
|
| 28 |
+ err error |
|
| 29 |
+ respStatusCode = 0 |
|
| 30 |
+ serverAddress = authConfig.ServerAddress |
|
| 31 | 31 |
) |
| 32 | 32 |
|
| 33 | 33 |
logrus.Debugf("attempting v1 login to registry endpoint %s", registryEndpoint)
|
| ... | ... |
@@ -49,18 +49,18 @@ func loginV1(authConfig *cliconfig.AuthConfig, registryEndpoint *Endpoint) (stri |
| 49 | 49 |
|
| 50 | 50 |
// using `bytes.NewReader(jsonBody)` here causes the server to respond with a 411 status. |
| 51 | 51 |
b := strings.NewReader(string(jsonBody)) |
| 52 |
- req1, err := registryEndpoint.client.Post(serverAddress+"users/", "application/json; charset=utf-8", b) |
|
| 52 |
+ resp1, err := registryEndpoint.client.Post(serverAddress+"users/", "application/json; charset=utf-8", b) |
|
| 53 | 53 |
if err != nil {
|
| 54 | 54 |
return "", fmt.Errorf("Server Error: %s", err)
|
| 55 | 55 |
} |
| 56 |
- defer req1.Body.Close() |
|
| 57 |
- reqStatusCode = req1.StatusCode |
|
| 58 |
- reqBody, err = ioutil.ReadAll(req1.Body) |
|
| 56 |
+ defer resp1.Body.Close() |
|
| 57 |
+ respStatusCode = resp1.StatusCode |
|
| 58 |
+ respBody, err = ioutil.ReadAll(resp1.Body) |
|
| 59 | 59 |
if err != nil {
|
| 60 |
- return "", fmt.Errorf("Server Error: [%#v] %s", reqStatusCode, err)
|
|
| 60 |
+ return "", fmt.Errorf("Server Error: [%#v] %s", respStatusCode, err)
|
|
| 61 | 61 |
} |
| 62 | 62 |
|
| 63 |
- if reqStatusCode == 201 {
|
|
| 63 |
+ if respStatusCode == 201 {
|
|
| 64 | 64 |
if loginAgainstOfficialIndex {
|
| 65 | 65 |
status = "Account created. Please use the confirmation link we sent" + |
| 66 | 66 |
" to your e-mail to activate it." |
| ... | ... |
@@ -68,8 +68,8 @@ func loginV1(authConfig *cliconfig.AuthConfig, registryEndpoint *Endpoint) (stri |
| 68 | 68 |
// *TODO: Use registry configuration to determine what this says, if anything? |
| 69 | 69 |
status = "Account created. Please see the documentation of the registry " + serverAddress + " for instructions how to activate it." |
| 70 | 70 |
} |
| 71 |
- } else if reqStatusCode == 400 {
|
|
| 72 |
- if string(reqBody) == "\"Username or email already exists\"" {
|
|
| 71 |
+ } else if respStatusCode == 400 {
|
|
| 72 |
+ if string(respBody) == "\"Username or email already exists\"" {
|
|
| 73 | 73 |
req, err := http.NewRequest("GET", serverAddress+"users/", nil)
|
| 74 | 74 |
req.SetBasicAuth(authConfig.Username, authConfig.Password) |
| 75 | 75 |
resp, err := registryEndpoint.client.Do(req) |
| ... | ... |
@@ -97,9 +97,9 @@ func loginV1(authConfig *cliconfig.AuthConfig, registryEndpoint *Endpoint) (stri |
| 97 | 97 |
} |
| 98 | 98 |
return "", fmt.Errorf("Login: %s (Code: %d; Headers: %s)", body, resp.StatusCode, resp.Header)
|
| 99 | 99 |
} |
| 100 |
- return "", fmt.Errorf("Registration: %s", reqBody)
|
|
| 100 |
+ return "", fmt.Errorf("Registration: %s", respBody)
|
|
| 101 | 101 |
|
| 102 |
- } else if reqStatusCode == 401 {
|
|
| 102 |
+ } else if respStatusCode == 401 {
|
|
| 103 | 103 |
// This case would happen with private registries where /v1/users is |
| 104 | 104 |
// protected, so people can use `docker login` as an auth check. |
| 105 | 105 |
req, err := http.NewRequest("GET", serverAddress+"users/", nil)
|
| ... | ... |
@@ -122,7 +122,7 @@ func loginV1(authConfig *cliconfig.AuthConfig, registryEndpoint *Endpoint) (stri |
| 122 | 122 |
resp.StatusCode, resp.Header) |
| 123 | 123 |
} |
| 124 | 124 |
} else {
|
| 125 |
- return "", fmt.Errorf("Unexpected status code [%d] : %s", reqStatusCode, reqBody)
|
|
| 125 |
+ return "", fmt.Errorf("Unexpected status code [%d] : %s", respStatusCode, respBody)
|
|
| 126 | 126 |
} |
| 127 | 127 |
return status, nil |
| 128 | 128 |
} |