mirror of https://github.com/docker/docs.git
Merge pull request #14811 from devx/refactor-clientRequestAttemptLogin
Cleanup: Factor cmdAttempt out of cli.clientRequestAttemptLogin
This commit is contained in:
commit
70cae97ee2
|
@ -125,8 +125,9 @@ func (cli *DockerCli) clientRequest(method, path string, in io.Reader, headers m
|
||||||
return serverResp, nil
|
return serverResp, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (cli *DockerCli) clientRequestAttemptLogin(method, path string, in io.Reader, out io.Writer, index *registry.IndexInfo, cmdName string) (io.ReadCloser, int, error) {
|
// cmdAttempt builds the corresponding registry Auth Header from the given
|
||||||
cmdAttempt := func(authConfig cliconfig.AuthConfig) (io.ReadCloser, int, error) {
|
// authConfig. It returns the servers body, status, error response
|
||||||
|
func (cli *DockerCli) cmdAttempt(authConfig cliconfig.AuthConfig, method, path string, in io.Reader, out io.Writer) (io.ReadCloser, int, error) {
|
||||||
buf, err := json.Marshal(authConfig)
|
buf, err := json.Marshal(authConfig)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, -1, err
|
return nil, -1, err
|
||||||
|
@ -155,18 +156,20 @@ func (cli *DockerCli) clientRequestAttemptLogin(method, path string, in io.Reade
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return serverResp.body, serverResp.statusCode, err
|
return serverResp.body, serverResp.statusCode, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (cli *DockerCli) clientRequestAttemptLogin(method, path string, in io.Reader, out io.Writer, index *registry.IndexInfo, cmdName string) (io.ReadCloser, int, error) {
|
||||||
|
|
||||||
// Resolve the Auth config relevant for this server
|
// Resolve the Auth config relevant for this server
|
||||||
authConfig := registry.ResolveAuthConfig(cli.configFile, index)
|
authConfig := registry.ResolveAuthConfig(cli.configFile, index)
|
||||||
body, statusCode, err := cmdAttempt(authConfig)
|
body, statusCode, err := cli.cmdAttempt(authConfig, method, path, in, out)
|
||||||
if statusCode == http.StatusUnauthorized {
|
if statusCode == http.StatusUnauthorized {
|
||||||
fmt.Fprintf(cli.out, "\nPlease login prior to %s:\n", cmdName)
|
fmt.Fprintf(cli.out, "\nPlease login prior to %s:\n", cmdName)
|
||||||
if err = cli.CmdLogin(index.GetAuthConfigKey()); err != nil {
|
if err = cli.CmdLogin(index.GetAuthConfigKey()); err != nil {
|
||||||
return nil, -1, err
|
return nil, -1, err
|
||||||
}
|
}
|
||||||
authConfig = registry.ResolveAuthConfig(cli.configFile, index)
|
authConfig = registry.ResolveAuthConfig(cli.configFile, index)
|
||||||
return cmdAttempt(authConfig)
|
return cli.cmdAttempt(authConfig, method, path, in, out)
|
||||||
}
|
}
|
||||||
return body, statusCode, err
|
return body, statusCode, err
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue