Пример #1
0
		if len(args) == 1 {
			reg = args[0]
		}

		var login config.Login
		if err := askForLogin(&login); err != nil {
			fmt.Println(xerrors.InternalError)
			logrus.Fatalf("encrypting password: %v", err)
		}

		config.AddLogin(reg, login)

		logged, err := docker.Login(reg)

		if err != nil && err != xerrors.Unauthorized {
			config.RemoveLogin(reg)
			fmt.Println(xerrors.InternalError)
			logrus.Fatalf("log in: %v", err)
		}

		if !logged {
			config.RemoveLogin(reg)
			fmt.Println("Unauthorized: Wrong login/password, please try again")
			os.Exit(1)
		}

		fmt.Println("Login Successful")
	},
}

func askForLogin(login *config.Login) error {
Пример #2
0
var logoutCmd = &cobra.Command{
	Use:   "logout",
	Short: "Log out from a Docker registry",
	Long:  `Log out from a Docker registry`,
	Run: func(cmd *cobra.Command, args []string) {

		if len(args) > 1 {
			fmt.Println("Only one argument is allowed")
			os.Exit(1)
		}
		var reg string = docker.DockerHub

		if len(args) == 1 {
			reg = args[0]
		}
		ok, err := config.RemoveLogin(reg)
		if err != nil {
			fmt.Println(xerrors.InternalError)
			logrus.Fatalf("log out: %v", err)
		}

		if ok {
			fmt.Println("Log out successful")
			return
		}
		fmt.Println("You are not logged in")
	},
}

func init() {
	RootCmd.AddCommand(logoutCmd)