mirror of
https://github.com/containers/podman.git
synced 2025-06-21 01:19:15 +08:00
Handle http/https in registry given to login/out
Signed-off-by: TomSweeneyRedHat <tsweeney@redhat.com>
This commit is contained in:
@ -465,3 +465,11 @@ func getAuthFile(authfile string) string {
|
|||||||
}
|
}
|
||||||
return os.Getenv("REGISTRY_AUTH_FILE")
|
return os.Getenv("REGISTRY_AUTH_FILE")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// scrubServer removes 'http://' or 'https://' from the front of the
|
||||||
|
// server/registry string if either is there. This will be mostly used
|
||||||
|
// for user input from 'podman login' and 'podman logout'.
|
||||||
|
func scrubServer(server string) string {
|
||||||
|
server = strings.TrimPrefix(server, "https://")
|
||||||
|
return strings.TrimPrefix(server, "http://")
|
||||||
|
}
|
||||||
|
@ -60,10 +60,7 @@ func loginCmd(c *cli.Context) error {
|
|||||||
if len(args) == 0 {
|
if len(args) == 0 {
|
||||||
return errors.Errorf("registry must be given")
|
return errors.Errorf("registry must be given")
|
||||||
}
|
}
|
||||||
var server string
|
server := scrubServer(args[0])
|
||||||
if len(args) == 1 {
|
|
||||||
server = args[0]
|
|
||||||
}
|
|
||||||
authfile := getAuthFile(c.String("authfile"))
|
authfile := getAuthFile(c.String("authfile"))
|
||||||
|
|
||||||
sc := common.GetSystemContext("", authfile, false)
|
sc := common.GetSystemContext("", authfile, false)
|
||||||
@ -113,6 +110,10 @@ func getUserAndPass(username, password, userFromAuthFile string) (string, string
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return "", "", errors.Wrapf(err, "error reading username")
|
return "", "", errors.Wrapf(err, "error reading username")
|
||||||
}
|
}
|
||||||
|
// If no username provided, use userFromAuthFile instead.
|
||||||
|
if strings.TrimSpace(username) == "" {
|
||||||
|
username = userFromAuthFile
|
||||||
|
}
|
||||||
}
|
}
|
||||||
if password == "" {
|
if password == "" {
|
||||||
fmt.Print("Password: ")
|
fmt.Print("Password: ")
|
||||||
|
@ -44,7 +44,7 @@ func logoutCmd(c *cli.Context) error {
|
|||||||
}
|
}
|
||||||
var server string
|
var server string
|
||||||
if len(args) == 1 {
|
if len(args) == 1 {
|
||||||
server = args[0]
|
server = scrubServer(args[0])
|
||||||
}
|
}
|
||||||
authfile := getAuthFile(c.String("authfile"))
|
authfile := getAuthFile(c.String("authfile"))
|
||||||
|
|
||||||
@ -54,14 +54,14 @@ func logoutCmd(c *cli.Context) error {
|
|||||||
if err := config.RemoveAllAuthentication(sc); err != nil {
|
if err := config.RemoveAllAuthentication(sc); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
fmt.Println("Remove login credentials for all registries")
|
fmt.Println("Removed login credentials for all registries")
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
err := config.RemoveAuthentication(sc, server)
|
err := config.RemoveAuthentication(sc, server)
|
||||||
switch err {
|
switch err {
|
||||||
case nil:
|
case nil:
|
||||||
fmt.Printf("Remove login credentials for %s\n", server)
|
fmt.Printf("Removed login credentials for %s\n", server)
|
||||||
return nil
|
return nil
|
||||||
case config.ErrNotLoggedIn:
|
case config.ErrNotLoggedIn:
|
||||||
return errors.Errorf("Not logged into %s\n", server)
|
return errors.Errorf("Not logged into %s\n", server)
|
||||||
|
Reference in New Issue
Block a user