Exemple #1
0
func PostCompleteHandler(ctx *macaron.Context, log *logs.BeeLogger) (int, []byte) {
	imageId := ctx.Params(":imageId")
	repository := ctx.Params(":repository")

	body, _ := ctx.Req.Body().Bytes()
	if err := module.CheckClientStatus(body); err != nil {
		module.CleanCache(imageId)
		log.Error("[ACI API] Push aci failed: %v", err.Error())

		failmsg := module.FillRespMsg(false, err.Error(), "")
		result, _ := json.Marshal(failmsg)
		return http.StatusInternalServerError, result
	}

	namespace := ctx.Params(":namespace")
	acifile := ctx.Params(":acifile")
	signfile := ctx.Params(":signfile")

	//TODO: only for testing,pubkey will be read and saved via user management module
	pubkeyspath := module.GetPubkeysPath(namespace, repository)
	acipath := module.GetAciPath(imageId, acifile)
	signpath := module.GetSignaturePath(imageId, signfile)
	manipath := module.GetManifestPath(imageId)
	if err := module.VerifyAciSignature(acipath, signpath, pubkeyspath); err != nil {
		module.CleanCache(imageId)
		log.Error("[ACI API] Aci verified failed: %v", err.Error())

		failmsg := module.FillRespMsg(false, "", err.Error())
		result, _ := json.Marshal(failmsg)
		return http.StatusInternalServerError, result
	}

	//If aci image is existent,it should update the db and delete the old image after executed successfully
	var oldimageId = ""
	tag := strings.Trim(acifile, ".aci")
	t := new(models.Tag)
	if err := t.Get(namespace, repository, tag); err == nil {
		oldimageId = t.ImageId
	}

	a := new(models.Aci)
	if err := a.Update(namespace, repository, tag, imageId, manipath, signpath, acipath); err != nil {
		module.CleanCache(imageId)
		log.Error("[ACI API] Update %v/%v failed: %v", namespace, repository, err.Error())

		failmsg := module.FillRespMsg(false, "", err.Error())
		result, _ := json.Marshal(failmsg)
		return http.StatusInternalServerError, result
	}

	//Delete old aci directory after redis is updated
	if oldimageId != "" {
		module.CleanCache(oldimageId)
	}

	successmsg := module.FillRespMsg(true, "", "")
	result, _ := json.Marshal(successmsg)
	return http.StatusOK, result
}
Exemple #2
0
func PutAciHandler(ctx *macaron.Context, log *logs.BeeLogger) (int, []byte) {
	imageId := ctx.Params(":imageId")
	acifile := ctx.Params(":acifile")

	acipath := module.GetAciPath(imageId, acifile)

	data, _ := ctx.Req.Body().Bytes()
	if err := ioutil.WriteFile(acipath, data, 0777); err != nil {
		//Temporary directory would be deleted in PostCompleteHandler
		log.Error("[ACI API] Save aci file failed: %v", err.Error())
		result, _ := json.Marshal(map[string]string{"message": "Save aci file failed"})
		return http.StatusInternalServerError, result
	}

	result, _ := json.Marshal(map[string]string{})
	return http.StatusOK, result
}