Enable cross-platforms logout from Registry
Signed-off-by: Arnaud Porterie <arnaud.porterie@docker.com>
This commit is contained in:
parent
b2c162a0b3
commit
8ee7ad2209
|
@ -11,7 +11,6 @@ import (
|
||||||
Cli "github.com/docker/docker/cli"
|
Cli "github.com/docker/docker/cli"
|
||||||
flag "github.com/docker/docker/pkg/mflag"
|
flag "github.com/docker/docker/pkg/mflag"
|
||||||
"github.com/docker/docker/pkg/term"
|
"github.com/docker/docker/pkg/term"
|
||||||
"github.com/docker/docker/registry"
|
|
||||||
"github.com/docker/engine-api/client"
|
"github.com/docker/engine-api/client"
|
||||||
"github.com/docker/engine-api/types"
|
"github.com/docker/engine-api/types"
|
||||||
)
|
)
|
||||||
|
@ -36,16 +35,7 @@ func (cli *DockerCli) CmdLogin(args ...string) error {
|
||||||
cli.in = os.Stdin
|
cli.in = os.Stdin
|
||||||
}
|
}
|
||||||
|
|
||||||
// The daemon `/info` endpoint informs us of the default registry being
|
serverAddress := cli.electAuthServer()
|
||||||
// used. This is essential in cross-platforms environment, where for
|
|
||||||
// example a Linux client might be interacting with a Windows daemon, hence
|
|
||||||
// the default registry URL might be Windows specific.
|
|
||||||
serverAddress := registry.IndexServer
|
|
||||||
if info, err := cli.client.Info(); err != nil {
|
|
||||||
fmt.Fprintf(cli.out, "Warning: failed to get default registry endpoint from daemon (%v). Using system default: %s\n", err, serverAddress)
|
|
||||||
} else {
|
|
||||||
serverAddress = info.IndexServerAddress
|
|
||||||
}
|
|
||||||
if len(cmd.Args()) > 0 {
|
if len(cmd.Args()) > 0 {
|
||||||
serverAddress = cmd.Arg(0)
|
serverAddress = cmd.Arg(0)
|
||||||
}
|
}
|
||||||
|
|
|
@ -5,7 +5,6 @@ import (
|
||||||
|
|
||||||
Cli "github.com/docker/docker/cli"
|
Cli "github.com/docker/docker/cli"
|
||||||
flag "github.com/docker/docker/pkg/mflag"
|
flag "github.com/docker/docker/pkg/mflag"
|
||||||
"github.com/docker/docker/registry"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
// CmdLogout logs a user out from a Docker registry.
|
// CmdLogout logs a user out from a Docker registry.
|
||||||
|
@ -14,12 +13,12 @@ import (
|
||||||
//
|
//
|
||||||
// Usage: docker logout [SERVER]
|
// Usage: docker logout [SERVER]
|
||||||
func (cli *DockerCli) CmdLogout(args ...string) error {
|
func (cli *DockerCli) CmdLogout(args ...string) error {
|
||||||
cmd := Cli.Subcmd("logout", []string{"[SERVER]"}, Cli.DockerCommands["logout"].Description+".\nIf no server is specified \""+registry.IndexServer+"\" is the default.", true)
|
cmd := Cli.Subcmd("logout", []string{"[SERVER]"}, Cli.DockerCommands["logout"].Description+".\nIf no server is specified, the default is defined by the daemon.", true)
|
||||||
cmd.Require(flag.Max, 1)
|
cmd.Require(flag.Max, 1)
|
||||||
|
|
||||||
cmd.ParseFlags(args, true)
|
cmd.ParseFlags(args, true)
|
||||||
|
|
||||||
serverAddress := registry.IndexServer
|
serverAddress := cli.electAuthServer()
|
||||||
if len(cmd.Args()) > 0 {
|
if len(cmd.Args()) > 0 {
|
||||||
serverAddress = cmd.Arg(0)
|
serverAddress = cmd.Arg(0)
|
||||||
}
|
}
|
||||||
|
|
|
@ -21,6 +21,20 @@ import (
|
||||||
registrytypes "github.com/docker/engine-api/types/registry"
|
registrytypes "github.com/docker/engine-api/types/registry"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
func (cli *DockerCli) electAuthServer() string {
|
||||||
|
// The daemon `/info` endpoint informs us of the default registry being
|
||||||
|
// used. This is essential in cross-platforms environment, where for
|
||||||
|
// example a Linux client might be interacting with a Windows daemon, hence
|
||||||
|
// the default registry URL might be Windows specific.
|
||||||
|
serverAddress := registry.IndexServer
|
||||||
|
if info, err := cli.client.Info(); err != nil {
|
||||||
|
fmt.Fprintf(cli.out, "Warning: failed to get default registry endpoint from daemon (%v). Using system default: %s\n", err, serverAddress)
|
||||||
|
} else {
|
||||||
|
serverAddress = info.IndexServerAddress
|
||||||
|
}
|
||||||
|
return serverAddress
|
||||||
|
}
|
||||||
|
|
||||||
// encodeAuthToBase64 serializes the auth configuration as JSON base64 payload
|
// encodeAuthToBase64 serializes the auth configuration as JSON base64 payload
|
||||||
func encodeAuthToBase64(authConfig types.AuthConfig) (string, error) {
|
func encodeAuthToBase64(authConfig types.AuthConfig) (string, error) {
|
||||||
buf, err := json.Marshal(authConfig)
|
buf, err := json.Marshal(authConfig)
|
||||||
|
|
Loading…
Reference in New Issue