Esempio n. 1
0
func LoginHandler(rw http.ResponseWriter, request *http.Request) error {
	reg := request.URL.Query()["realm"]

	if len(reg) == 0 {
		return fmt.Errorf("no registry provided")
	}

	logged, err := docker.Login(reg[0])

	if err != nil {
		return err
	}

	if !logged {
		return xerrors.Unauthorized
	}
	return nil
}
Esempio n. 2
0
		var reg string = docker.DockerHub

		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")
	},