func GetTagV1Handler(ctx *macaron.Context, log *logs.BeeLogger) (int, []byte) { namespace := ctx.Params(":namespace") repository := ctx.Params(":repository") r := new(models.Repository) if exists, err := r.Get(namespace, repository); err != nil { log.Error("[REGISTRY API V1] Failed to get repository %v/%v context: %v", namespace, repository, err.Error()) result, _ := json.Marshal(map[string]string{"message": "Failed to get repository context"}) return http.StatusBadRequest, result } else if exists == false { log.Error("[REGISTRY API V1] Not found repository %v/%v", namespace, repository) result, _ := json.Marshal(map[string]string{"message": "Not found repository"}) return http.StatusNotFound, result } tags := map[string]string{} tagslist := r.GetTagslist() for _, tagname := range tagslist { t := new(models.Tag) if exists, err := t.Get(namespace, repository, tagname); err != nil || !exists { log.Error(fmt.Sprintf("[REGISTRY API V1] %s/%s %v is not exist", namespace, repository, tagname)) result, _ := json.Marshal(map[string]string{"message": "Tag is not exist"}) return http.StatusNotFound, result } tags[tagname] = t.ImageId } result, _ := json.Marshal(tags) return http.StatusOK, result }
func GetTagsListV2Handler(ctx *macaron.Context, log *logs.BeeLogger) (int, []byte) { namespace := ctx.Params(":namespace") repository := ctx.Params(":repository") r := new(models.Repository) if _, err := r.Get(namespace, repository); err != nil { log.Error("[REGISTRY API V2] Failed to get repository %v/%v: %v", namespace, repository, err.Error()) result, _ := json.Marshal(map[string]string{"message": "Failed to get repository"}) return http.StatusBadRequest, result } data := map[string]interface{}{} data["name"] = fmt.Sprintf("%s/%s", namespace, repository) tagslist := r.GetTagslist() if len(tagslist) <= 0 { log.Error("[REGISTRY API V2] Repository %v/%v tags list is empty", namespace, repository) result, _ := json.Marshal(map[string]string{"message": "Tags list is empty"}) return http.StatusNotFound, result } data["tags"] = tagslist result, _ := json.Marshal(data) return http.StatusOK, result }