mirror of
https://github.com/docker/compose.git
synced 2026-08-28 04:18:05 +00:00
commit
52c2d09eae
10 changed files with 130 additions and 23 deletions
|
|
@ -35,7 +35,7 @@ import (
|
|||
func Command() *cobra.Command {
|
||||
cmd := &cobra.Command{
|
||||
Use: "login [OPTIONS] [SERVER]",
|
||||
Short: "Log in to a Docker registry",
|
||||
Short: "Log in to a Docker registry or cloud backend",
|
||||
Long: "Log in to a Docker registry or cloud backend.\nIf no registry server is specified, the default is defined by the daemon.",
|
||||
Args: cobra.MaximumNArgs(1),
|
||||
RunE: runLogin,
|
||||
|
|
|
|||
42
cli/cmd/logout/azurelogout.go
Normal file
42
cli/cmd/logout/azurelogout.go
Normal file
|
|
@ -0,0 +1,42 @@
|
|||
package logout
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
|
||||
"github.com/pkg/errors"
|
||||
"github.com/spf13/cobra"
|
||||
|
||||
"github.com/docker/api/client"
|
||||
"github.com/docker/api/errdefs"
|
||||
)
|
||||
|
||||
// AzureLogoutCommand returns the azure logout command
|
||||
func AzureLogoutCommand() *cobra.Command {
|
||||
cmd := &cobra.Command{
|
||||
Use: "azure",
|
||||
Short: "Logout from Azure",
|
||||
Args: cobra.MaximumNArgs(0),
|
||||
RunE: func(cmd *cobra.Command, args []string) error {
|
||||
return cloudLogout(cmd, "aci")
|
||||
},
|
||||
}
|
||||
return cmd
|
||||
}
|
||||
|
||||
func cloudLogout(cmd *cobra.Command, backendType string) error {
|
||||
ctx := cmd.Context()
|
||||
cs, err := client.GetCloudService(ctx, backendType)
|
||||
if err != nil {
|
||||
return errors.Wrap(errdefs.ErrLoginFailed, "cannot connect to backend")
|
||||
}
|
||||
err = cs.Logout(ctx)
|
||||
if errors.Is(err, context.Canceled) {
|
||||
return errors.New("logout canceled")
|
||||
}
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
fmt.Println("Removing login credentials for Azure")
|
||||
return nil
|
||||
}
|
||||
25
cli/cmd/logout/logout.go
Normal file
25
cli/cmd/logout/logout.go
Normal file
|
|
@ -0,0 +1,25 @@
|
|||
package logout
|
||||
|
||||
import (
|
||||
"github.com/spf13/cobra"
|
||||
|
||||
"github.com/docker/api/cli/mobycli"
|
||||
)
|
||||
|
||||
// Command returns the login command
|
||||
func Command() *cobra.Command {
|
||||
cmd := &cobra.Command{
|
||||
Use: "logout [SERVER]",
|
||||
Short: "Log out from a Docker registry or cloud backend",
|
||||
Long: "Log out from a Docker registry or cloud backend.\nIf no server is specified, the default is defined by the daemon.",
|
||||
Args: cobra.MaximumNArgs(0),
|
||||
RunE: runLogout,
|
||||
}
|
||||
|
||||
cmd.AddCommand(AzureLogoutCommand())
|
||||
return cmd
|
||||
}
|
||||
|
||||
func runLogout(cmd *cobra.Command, args []string) error {
|
||||
return mobycli.ExecCmd(cmd)
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue