diff options
author | Matthew Heon <matthew.heon@gmail.com> | 2017-11-01 14:38:21 -0400 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-11-01 14:38:21 -0400 |
commit | f5019df3f5da9030ce21e5c8ad3d3921a6585e7f (patch) | |
tree | 05412dcc190ca026dbe51a4ef72bb91ff646e7c6 /cmd/kpod/logout.go | |
parent | 2b74391cd5281f6fdf391ff8ad50fd1490f6bf89 (diff) | |
parent | eab0737f1189a7b88f0a37a6b894ca4345b6853f (diff) | |
download | podman-f5019df3f5da9030ce21e5c8ad3d3921a6585e7f.tar.gz podman-f5019df3f5da9030ce21e5c8ad3d3921a6585e7f.tar.bz2 podman-f5019df3f5da9030ce21e5c8ad3d3921a6585e7f.zip |
Merge pull request #1 from mheon/master
Initial checkin
Diffstat (limited to 'cmd/kpod/logout.go')
-rw-r--r-- | cmd/kpod/logout.go | 69 |
1 files changed, 69 insertions, 0 deletions
diff --git a/cmd/kpod/logout.go b/cmd/kpod/logout.go new file mode 100644 index 000000000..0b07f1a63 --- /dev/null +++ b/cmd/kpod/logout.go @@ -0,0 +1,69 @@ +package main + +import ( + "fmt" + + "github.com/containers/image/pkg/docker/config" + "github.com/projectatomic/libpod/libpod/common" + "github.com/pkg/errors" + "github.com/urfave/cli" +) + +var ( + logoutFlags = []cli.Flag{ + cli.StringFlag{ + Name: "authfile", + Usage: "Path of the authentication file. Default is ${XDG_RUNTIME_DIR}/containers/auth.json", + }, + cli.BoolFlag{ + Name: "all, a", + Usage: "Remove the cached credentials for all registries in the auth file", + }, + } + logoutDescription = "Remove the cached username and password for the registry." + logoutCommand = cli.Command{ + Name: "logout", + Usage: "logout of a container registry", + Description: logoutDescription, + Flags: logoutFlags, + Action: logoutCmd, + ArgsUsage: "REGISTRY", + } +) + +// logoutCmd uses the authentication package to remove the authenticated of a registry +// stored in the auth.json file +func logoutCmd(c *cli.Context) error { + args := c.Args() + if len(args) > 1 { + return errors.Errorf("too many arguments, logout takes only 1 argument") + } + if len(args) == 0 { + return errors.Errorf("registry must be given") + } + var server string + if len(args) == 1 { + server = args[0] + } + + sc := common.GetSystemContext("", c.String("authfile")) + + if c.Bool("all") { + if err := config.RemoveAllAuthentication(sc); err != nil { + return err + } + fmt.Println("Remove login credentials for all registries") + return nil + } + + err := config.RemoveAuthentication(sc, server) + switch err { + case nil: + fmt.Printf("Remove login credentials for %s\n", server) + return nil + case config.ErrNotLoggedIn: + return errors.Errorf("Not logged into %s\n", server) + default: + return errors.Wrapf(err, "error logging out of %q", server) + } +} |