Пример #1
0
func (a *RegistryAPI) GetRepoTagsHandler(w http.ResponseWriter, r *http.Request) {
	namespace, repo, _ := parseRepo(r, "")
	logger.Debug("[GetRepoTags] namespace=%s; repository=%s", namespace, repo)
	names, err := a.Storage.List(storage.RepoTagPath(namespace, repo, ""))
	if err != nil {
		a.response(w, "Repository not found: "+err.Error(), http.StatusNotFound, EMPTY_HEADERS)
		return
	}
	data := map[string]string{}
	for _, name := range names {
		base := path.Base(name)
		if !strings.HasPrefix(base, storage.TAG_PREFIX) {
			continue
		}
		// this is a tag
		tagName := strings.TrimPrefix(base, storage.TAG_PREFIX)
		content, err := a.Storage.Get(name)
		if err != nil {
			a.internalError(w, err.Error())
			return
		}
		data[tagName] = string(content)
	}
	a.response(w, data, http.StatusOK, EMPTY_HEADERS)
}
Пример #2
0
func (a *RegistryAPI) DeleteRepoTagsHandler(w http.ResponseWriter, r *http.Request) {
	namespace, repo, _ := parseRepo(r, "")
	logger.Debug("[DeleteRepoTags] namespace=%s; repository=%s", namespace, repo)
	if err := a.Storage.RemoveAll(storage.RepoTagPath(namespace, repo, "")); err != nil {
		a.response(w, "Repository not found: "+err.Error(), http.StatusNotFound, EMPTY_HEADERS)
		return
	}
	a.response(w, true, http.StatusOK, EMPTY_HEADERS)
}
Пример #3
0
func (a *RegistryAPI) GetRepoTagHandler(w http.ResponseWriter, r *http.Request) {
	namespace, repo, tag := parseRepo(r, "tag")
	logger.Debug("[GetRepoTag] namespace=%s; repository=%s; tag=%s", namespace, repo, tag)
	content, err := a.Storage.Get(storage.RepoTagPath(namespace, repo, tag))
	if err != nil {
		a.response(w, "Tag not found: "+err.Error(), http.StatusNotFound, EMPTY_HEADERS)
		return
	}
	a.response(w, content, http.StatusOK, EMPTY_HEADERS)
}
Пример #4
0
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)
}