Beispiel #1
0
func (this *BlobAPIV2Controller) GetBlobs() {
	image := new(models.Image)
	digest := strings.Split(this.Ctx.Input.Param(":digest"), ":")[1]

	if has, _, _ := image.HasTarsum(digest); has == false {
		this.JSONOut(http.StatusBadRequest, "", map[string][]modules.ErrorDescriptor{"errors": []modules.ErrorDescriptor{modules.ErrorDescriptors[modules.APIErrorCodeUnauthorized]}})
		return
	}

	layerfile := image.Path

	if _, err := os.Stat(layerfile); err != nil {
		this.JSONOut(http.StatusBadRequest, "", map[string][]modules.ErrorDescriptor{"errors": []modules.ErrorDescriptor{modules.ErrorDescriptors[modules.APIErrorCodeBlobUnknown]}})
		return
	}

	file, err := ioutil.ReadFile(layerfile)
	if err != nil {
		this.JSONOut(http.StatusBadRequest, "", map[string][]modules.ErrorDescriptor{"errors": []modules.ErrorDescriptor{modules.ErrorDescriptors[modules.APIErrorCodeBlobUnknown]}})
		return
	}

	this.Ctx.Output.Context.ResponseWriter.Header().Set("Content-Type", "application/octet-stream")
	this.Ctx.Output.Context.ResponseWriter.Header().Set("Content-Transfer-Encoding", "binary")
	this.Ctx.Output.Context.ResponseWriter.Header().Set("Content-Length", string(int64(len(file))))
	this.Ctx.Output.Context.Output.SetStatus(http.StatusOK)
	this.Ctx.Output.Context.Output.Body(file)
	return
}
Beispiel #2
0
func (this *BlobAPIV2Controller) HeadDigest() {
	image := new(models.Image)
	digest := strings.Split(this.Ctx.Input.Param(":digest"), ":")[1]

	if has, _, _ := image.HasTarsum(digest); has == false {
		this.JSONOut(http.StatusNotFound, "", map[string][]modules.ErrorDescriptor{"errors": []modules.ErrorDescriptor{modules.ErrorDescriptors[modules.APIErrorCodeUnauthorized]}})
		return
	}

	this.Ctx.Output.Context.Output.SetStatus(http.StatusOK)
	this.ServeJson()
	return
}