コード例 #1
0
ファイル: tags.go プロジェクト: hqm/go-docker-registry
func (a *RegistryAPI) GetRepoTagJsonHandler(w http.ResponseWriter, r *http.Request) {
	namespace, repo, tag := parseRepo(r, "tag")
	data := map[string]string{
		"last_update":       "",
		"docker_version":    "",
		"docker_go_version": "",
		"arch":              "amd64",
		"os":                "linux",
		"kernel":            "",
	}
	content, err := a.Storage.Get(storage.RepoTagJsonPath(namespace, repo, tag))
	if err != nil {
		a.response(w, data, http.StatusNotFound, EMPTY_HEADERS)
		return
	}
	a.response(w, content, http.StatusOK, EMPTY_HEADERS)
	return
}
コード例 #2
0
ファイル: tags.go プロジェクト: hqm/go-docker-registry
func (a *RegistryAPI) PutRepoTagHandler(w http.ResponseWriter, r *http.Request) {
	namespace, repo, tag := parseRepo(r, "tag")
	logger.Debug("[PutRepoTag] namespace=%s; repository=%s; tag=%s", namespace, repo, tag)
	data, err := ioutil.ReadAll(r.Body)
	if err != nil {
		a.response(w, "Error reading request body: "+err.Error(), http.StatusBadRequest, EMPTY_HEADERS)
		return
	} else if len(data) == 0 {
		a.response(w, "Empty data", http.StatusBadRequest, EMPTY_HEADERS)
		return
	}
	logger.Debug("[PutRepoTag] body:\n%s", data)
	imageID := strings.Trim(string(data), "\"") // trim quotes
	if exists, err := a.Storage.Exists(storage.ImageJsonPath(imageID)); err != nil || !exists {
		a.response(w, "Image not found: "+err.Error(), http.StatusNotFound, EMPTY_HEADERS)
		return
	}
	err = a.Storage.Put(storage.RepoTagPath(namespace, repo, tag), []byte(imageID))
	if err != nil {
		a.internalError(w, err.Error())
		return
	}
	uaStrings := r.Header["User-Agent"]
	uaString := ""
	if len(uaStrings) > 0 {
		// just use the first one. there *should* only be one to begin with.
		uaString = uaStrings[0]
	}
	dataMap := CreateRepoJson(uaString)
	jsonData, err := json.Marshal(&dataMap)
	if err != nil {
		a.internalError(w, err.Error())
		return
	}
	a.Storage.Put(storage.RepoTagJsonPath(namespace, repo, tag), jsonData)
	if tag == "latest" {
		a.Storage.Put(storage.RepoJsonPath(namespace, repo), jsonData)
	}
	a.response(w, true, http.StatusOK, EMPTY_HEADERS)
}