Exemple #1
0
func RegistryDelete(rw http.ResponseWriter, r *http.Request) *httperr.Error {
	// server := mux.Vars(r)["server"]
	server := r.FormValue("server")

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

	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)
}
Exemple #2
0
func RegistryList(rw http.ResponseWriter, r *http.Request) *httperr.Error {
	_, acs, err := models.GetRegistriesAuth()

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

	return RenderJson(rw, acs)
}
Exemple #3
0
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.GetRegistriesAuth()

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