Beispiel #1
0
func (r *Repository) PutTagFromManifests(image, namespace, repository, tag, manifests string) error {
	if has, _, err := r.Has(namespace, repository); err != nil {
		return err
	} else if has == false {
		return fmt.Errorf("Repository not found")
	}

	t := new(Tag)
	t.Name, t.ImageId, t.Namespace, t.Repository, t.Manifest = tag, image, namespace, repository, manifests

	if err := t.Save(); err != nil {
		return err
	}

	has := false
	for _, v := range r.Tags {
		if v == db.Key("tag", t.Namespace, t.Repository, t.Name) {
			has = true
		}
	}

	if has == false {
		r.Tags = append(r.Tags, db.Key("tag", t.Namespace, t.Repository, t.Name))
	}

	if err := r.Save(); err != nil {
		return err
	}

	return nil
}
Beispiel #2
0
func (i *Image) PutTarsum(tarsum string) error {
	if err := db.Save(i, db.Key("tarsum", tarsum)); err != nil {
		return err
	}

	return nil
}
Beispiel #3
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 #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) Save() error {
	key := db.Key("image", i.ImageId)

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

	if _, err := db.Client.HSet(db.GLOBAL_IMAGE_INDEX, i.ImageId, key).Result(); err != nil {
		return err
	}

	return nil
}
Beispiel #6
0
func (t *Tag) Save() error {
	key := db.Key("tag", t.Namespace, t.Repository, t.Name)

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

	if _, err := db.Client.HSet(db.GLOBAL_TAG_INDEX, (fmt.Sprintf("%s/%s/%s:%s", t.Namespace, t.Repository, t.Name, t.ImageId)), key).Result(); err != nil {
		return err
	}

	return nil
}
Beispiel #7
0
func (r *Repository) Save() error {
	key := db.Key("repository", r.Namespace, r.Repository)

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

	if _, err := db.Client.HSet(db.GLOBAL_REPOSITORY_INDEX, (fmt.Sprintf("%s/%s", r.Namespace, r.Repository)), key).Result(); err != nil {
		return err
	}

	return nil
}
Beispiel #8
0
func (r *Repository) PutTag(imageId, namespace, repository, tag string) error {
	if has, _, err := r.Has(namespace, repository); err != nil {
		return err
	} else if has == false {
		return fmt.Errorf("Repository not found")
	}

	i := new(Image)
	if has, _, err := i.Has(imageId); err != nil {
		return err
	} else if has == false {
		return fmt.Errorf("Tag's image not found")
	}

	t := new(Tag)
	t.Name, t.ImageId, t.Namespace, t.Repository = tag, imageId, namespace, repository

	if err := t.Save(); err != nil {
		return err
	}

	has := false
	for _, value := range r.Tags {
		if value == db.Key("tag", t.Namespace, t.Repository, t.Name) {
			has = true
		}
	}

	if !has {
		r.Tags = append(r.Tags, db.Key("tag", t.Namespace, t.Repository, t.Name))
	}

	if err := r.Save(); err != nil {
		return err
	}

	return nil
}
Beispiel #9
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 #10
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
	}
}