示例#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, setting.APIVERSION_ACI)
		log.Error("[ACI API] Failed to push aci: %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, setting.APIVERSION_ACI)
	acifilepath := module.GetLayerPath(imageId, acifile, setting.APIVERSION_ACI)
	signfilepath := module.GetSignaturePath(imageId, signfile, setting.APIVERSION_ACI)
	manipath := module.GetManifestPath(imageId, setting.APIVERSION_ACI)
	if err := module.VerifyAciSignature(acifilepath, signfilepath, pubkeyspath); err != nil {
		module.CleanCache(imageId, setting.APIVERSION_ACI)
		log.Error("[ACI API] Failed to verify Aci: %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 exists, err := t.Get(namespace, repository, tag); err == nil && exists {
		oldimageId = t.ImageId
	}

	a := new(models.Aci)
	if err := a.Update(namespace, repository, tag, imageId, manipath, signfilepath, acifilepath); err != nil {
		module.CleanCache(imageId, setting.APIVERSION_ACI)
		log.Error("[ACI API] Failed to update %v/%v: %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, setting.APIVERSION_ACI)
	}

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

	manipath := module.GetManifestPath(imageId, setting.APIVERSION_ACI)

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

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