예제 #1
0
파일: registries.go 프로젝트: soulware/rack
func RegistryDelete(rw http.ResponseWriter, r *http.Request) *httperr.Error {
	// server := mux.Vars(r)["server"]
	server := r.FormValue("server")

	env, acs, err := models.GetPrivateRegistriesAuth()

	if err != nil {
		return httperr.Server(err)
	}

	ac, ok := acs[server]

	if !ok {
		return httperr.Errorf(404, "no such registry: %s", server)
	}

	models.DockerLogout(ac)
	delete(acs, server)

	dat, err := json.Marshal(acs)

	if err != nil {
		return httperr.Server(err)
	}

	env["DOCKER_AUTH_DATA"] = string(dat)

	err = models.PutRackSettings(env)

	if err != nil {
		return httperr.Server(err)
	}

	return RenderJson(rw, ac)
}
예제 #2
0
파일: registries.go 프로젝트: soulware/rack
func RegistryCreate(rw http.ResponseWriter, r *http.Request) *httperr.Error {
	ac := docker.AuthConfiguration{
		Username:      GetForm(r, "username"),
		Password:      GetForm(r, "password"),
		Email:         GetForm(r, "email"),
		ServerAddress: GetForm(r, "serveraddress"),
	}

	_, err := models.DockerLogin(ac)

	if err != nil {
		return httperr.Errorf(400, "Could not login to server with provided credentials")
	}

	env, acs, err := models.GetPrivateRegistriesAuth()

	if err != nil {
		return httperr.Server(err)
	}

	acs[ac.ServerAddress] = ac

	dat, err := json.Marshal(acs)

	if err != nil {
		return httperr.Server(err)
	}

	env["DOCKER_AUTH_DATA"] = string(dat)

	err = models.PutRackSettings(env)

	if err != nil {
		return httperr.Server(err)
	}

	return RenderJson(rw, ac)
}