Beispiel #1
0
func (i *Image) HasTarsum(tarsum string) (bool, error) {
	if err := db.Get(i, db.Key("tarsum", tarsum)); err != nil {
		return false, err
	}

	return true, nil
}
Beispiel #2
0
func (t *Tag) GetByKey(key string) error {
	if err := db.Get(t, key); err != nil {
		return err
	}

	return nil
}
Beispiel #3
0
func GetTagV1Handler(ctx *macaron.Context, log *logs.BeeLogger) (int, []byte) {
	namespace := ctx.Params(":namespace")
	repository := ctx.Params(":repository")

	repo := new(models.Repository)
	if has, _, err := repo.Has(namespace, repository); err != nil {
		log.Error("[REGISTRY API V1] Read repository json error: %v", err.Error())

		result, _ := json.Marshal(map[string]string{"message": "Get V1 tag failed,wrong name or repository"})
		return http.StatusBadRequest, result
	} else if has == false {
		log.Error("[REGISTRY API V1] Read repository no found. %v/%v", namespace, repository)

		result, _ := json.Marshal(map[string]string{"message": "Get V1 tag failed,read repository no found"})
		return http.StatusNotFound, result
	}

	tag := map[string]string{}

	for _, value := range repo.Tags {
		t := new(models.Tag)
		if err := db.Get(t, value); err != nil {
			log.Error(fmt.Sprintf("[REGISTRY API V1]  %s/%s Tags is not exist", namespace, repository))

			result, _ := json.Marshal(map[string]string{"message": fmt.Sprintf("%s/%s Tags is not exist", namespace, repository)})
			return http.StatusNotFound, result
		}

		tag[t.Name] = t.ImageId
	}

	result, _ := json.Marshal(tag)
	return http.StatusOK, result
}
Beispiel #4
0
func (t *Tag) Get(namespace, repository, tag string) error {
	key := db.Key("tag", namespace, repository, tag)

	if err := db.Get(t, key); err != nil {
		return err
	}

	return nil
}
Beispiel #5
0
func (i *Image) Has(image string) (bool, string, error) {
	if key := db.Key("image", image); len(key) <= 0 {
		return false, "", fmt.Errorf("Invalid image key")
	} else {
		if err := db.Get(i, key); err != nil {
			if err == redis.Nil {
				return false, "", nil
			} else {
				return false, "", err
			}
		}

		return true, key, nil
	}
}
Beispiel #6
0
func (r *Repository) Has(namespace, repository string) (bool, string, error) {
	if key := db.Key("repository", namespace, repository); len(key) <= 0 {
		return false, "", fmt.Errorf("Invalid repository key")
	} else {
		if err := db.Get(r, key); err != nil {
			if err == redis.Nil {
				return false, "", nil
			} else {
				return false, "", err
			}
		}

		return true, key, nil
	}
}