Ejemplo n.º 1
0
func GetImageAncestryV1Handler(ctx *macaron.Context, log *logs.BeeLogger) (int, []byte) {
	imageId := ctx.Params(":imageId")

	i := new(models.Image)
	if has, _, err := i.Has(imageId); err != nil {
		log.Error("[REGISTRY API V1] Read Image Ancestry Error: %v", err.Error())

		result, _ := json.Marshal(map[string]string{"message": "Read Image Ancestry Error"})
		return http.StatusBadRequest, result
	} else if has == false {
		log.Error("[REGISTRY API V1] Read Image None: %v", err.Error())

		result, _ := json.Marshal(map[string]string{"message": "Read Image None"})
		return http.StatusNotFound, result
	}

	ctx.Resp.Header().Set("Content-Length", fmt.Sprint(len(i.Ancestry)))

	return http.StatusOK, []byte(i.Ancestry)
}
Ejemplo n.º 2
0
func GetACIHandler(ctx *macaron.Context, log *logs.BeeLogger) (int, []byte) {
	namespace := ctx.Params(":namespace")
	repository := ctx.Params(":repository")
	acifilename := ctx.Params(":acifilename")

	acifile := strings.Trim(acifilename, ".asc")
	tag := strings.Trim(acifile, ".aci")

	t := new(models.Tag)
	if err := t.Get(namespace, repository, tag); err != nil {
		log.Error("[ACI API] Not found ACI %v/%v/%v", namespace, repository, acifilename)
		result, _ := json.Marshal(map[string]string{"message": "Not found ACI"})
		return http.StatusNotFound, result
	}

	i := new(models.Image)
	if has, _, err := i.Has(t.ImageId); err != nil || has != true {
		log.Error("[ACI API] Not found ACI %v/%v/%v", namespace, repository, acifilename)
		result, _ := json.Marshal(map[string]string{"message": "Not found ACI"})
		return http.StatusNotFound, result
	}

	var filepath string
	if b := strings.Contains(acifilename, ".asc"); b == true {
		filepath = i.SignPath
	} else {
		filepath = i.AciPath
	}

	content, err := ioutil.ReadFile(filepath)
	if err != nil {
		log.Error("[ACI API] Get ACI file failed: %v", err.Error())

		result, _ := json.Marshal(map[string]string{"message": "Get ACI file failed"})
		return http.StatusInternalServerError, result
	}

	return http.StatusOK, content
}
Ejemplo n.º 3
0
func GetImageLayerV1Handler(ctx *macaron.Context, log *logs.BeeLogger) (int, []byte) {
	imageId := ctx.Params(":imageId")

	i := new(models.Image)
	if has, _, err := i.Has(imageId); err != nil {
		log.Error("[REGISTRY API V1] Read Image Layer File Status Error: %v", err.Error())

		result, _ := json.Marshal(map[string]string{"message": "Read Image Layer file Error"})
		return http.StatusBadRequest, result
	} else if has == false {
		log.Error("[REGISTRY API V1] Read Image None Error")

		result, _ := json.Marshal(map[string]string{"message": "Read Image None"})
		return http.StatusNotFound, result
	}

	layerfile := i.Path
	if _, err := os.Stat(layerfile); err != nil {
		log.Error("[REGISTRY API V1] Read Image file state error: %v", err.Error())

		result, _ := json.Marshal(map[string]string{"message": "Read Image file state error"})
		return http.StatusBadRequest, result
	}

	file, err := ioutil.ReadFile(layerfile)
	if err != nil {
		log.Error("[REGISTRY API V1] Read Image file error: %v", err.Error())

		result, _ := json.Marshal(map[string]string{"message": "Read Image file error"})
		return http.StatusBadRequest, result
	}

	ctx.Resp.Header().Set("Content-Type", "application/octet-stream")
	ctx.Resp.Header().Set("Content-Length", fmt.Sprint(len(file)))

	return http.StatusOK, file
}