Example #1
0
// AppGetListAppV1Handler lists all the files in the namespace/repository
func AppGetListAppV1Handler(ctx *macaron.Context) (int, []byte) {
	namespace := ctx.Params(":namespace")
	repository := ctx.Params(":repository")

	appV1, _ := us.NewUpdateService("appV1", setting.Storage, setting.KeyManager)
	apps, err := appV1.List(namespace + "/" + repository)

	return httpRet("AppV1 List files", apps, err)
}
Example #2
0
// AppGetPublicKeyV1Handler gets the public key of the namespace/repository
func AppGetPublicKeyV1Handler(ctx *macaron.Context) (int, []byte) {
	namespace := ctx.Params(":namespace")

	appV1, _ := us.NewUpdateService("appV1", setting.Storage, setting.KeyManager)
	data, err := appV1.GetPublicKey(namespace)
	if err == nil {
		return http.StatusOK, data
	} else {
		return httpRet("AppV1 Get Public Key", nil, err)
	}
}
Example #3
0
// AppGetMetaSignV1Handler gets the meta signature data
func AppGetMetaSignV1Handler(ctx *macaron.Context) (int, []byte) {
	namespace := ctx.Params(":namespace")
	repository := ctx.Params(":repository")

	appV1, _ := us.NewUpdateService("appV1", setting.Storage, setting.KeyManager)
	data, err := appV1.GetMetaSign(namespace + "/" + repository)
	if err == nil {
		return http.StatusOK, data
	} else {
		return httpRet("AppV1 Get Meta Sign", data, err)
	}
}
Example #4
0
// AppDeleteFileV1Handler remove a file from a repo
func AppDeleteFileV1Handler(ctx *macaron.Context) (int, []byte) {
	// setup the repository.
	namespace := ctx.Params(":namespace")
	repository := ctx.Params(":repository")
	r, err := models.NewAppV1(namespace, repository)
	if err != nil {
		log.Errorf("[%s] setup repository error: %s", ctx.Req.RequestURI, err.Error())

		result, _ := json.Marshal(map[string]string{"Error": "Setup Repository Error"})
		return http.StatusBadRequest, result
	}

	a := models.ArtifactV1{
		OS:   ctx.Params(":os"),
		Arch: ctx.Params(":arch"),
		App:  ctx.Params(":app"),
		Tag:  ctx.Params(":tag"),
	}

	// Remove from update service
	appV1, err := us.NewUpdateService("appV1", setting.Storage, setting.KeyManager)
	if err != nil {
		log.Errorf("[%s] create update service: %s", ctx.Req.RequestURI, err.Error())

		result, _ := json.Marshal(map[string]string{"Error": "Create Update Service Error"})
		return http.StatusBadRequest, result
	}

	err = appV1.Delete(namespace+"/"+repository, a.GetName())
	if err != nil {
		log.Errorf("[%s] delete from update service error: %s", ctx.Req.RequestURI, err.Error())

		result, _ := json.Marshal(map[string]string{"Error": "Delete Update Service Error"})
		return http.StatusBadRequest, result
	}

	err = r.Delete(a)
	if err != nil {
		log.Errorf("[%s] delete artifact error: %s", ctx.Req.RequestURI, err.Error())

		result, _ := json.Marshal(map[string]string{"Error": "Delete Artifact Error"})
		return http.StatusBadRequest, result
	}

	return httpRet("AppV1 Delete data", nil, err)
}
Example #5
0
// AppGetFileV1Handler gets the data of a certain app
func AppGetFileV1Handler(ctx *macaron.Context) (int, []byte) {
	namespace := ctx.Params(":namespace")
	repository := ctx.Params(":repository")
	a := models.ArtifactV1{
		OS:   ctx.Params(":os"),
		Arch: ctx.Params(":arch"),
		App:  ctx.Params(":app"),
		Tag:  ctx.Params(":tag"),
	}

	appV1, _ := us.NewUpdateService("appV1", setting.Storage, setting.KeyManager)
	data, err := appV1.Get(namespace+"/"+repository, a.GetName())
	if err == nil {
		return http.StatusOK, data
	} else {
		return httpRet("AppV1 Get File", nil, err)
	}
}
Example #6
0
// AppPutFileV1Handler creates or updates a certain app
func AppPutFileV1Handler(ctx *macaron.Context) (int, []byte) {
	data, err := ctx.Req.Body().Bytes()
	if err != nil {
		log.Errorf("[%s] Req.Body.Bytes error: %s", ctx.Req.RequestURI, err.Error())

		result, _ := json.Marshal(map[string]string{"Error": "Req.Body.Bytes Error"})
		return http.StatusBadRequest, result
	}

	// Query or Create the repository.
	namespace := ctx.Params(":namespace")
	repository := ctx.Params(":repository")
	r, err := models.NewAppV1(namespace, repository)
	if err != nil {
		log.Errorf("[%s] query/create repository error: %s", ctx.Req.RequestURI, err.Error())

		result, _ := json.Marshal(map[string]string{"Error": "Query/Create Repository Error"})
		return http.StatusBadRequest, result
	}

	reqMethod := ctx.Req.Header.Get("Dockyard-Encrypt-Method")
	encryptMethod := utils.NewEncryptMethod(reqMethod)
	if encryptMethod == utils.EncryptNotSupported {
		log.Errorf("[%s] encrypt method %s is invalid", ctx.Req.RequestURI, reqMethod)

		result, _ := json.Marshal(map[string]string{"Error": "Invalid Encrypt Method"})
		return http.StatusBadRequest, result
	}

	a := models.ArtifactV1{
		OS:            ctx.Params(":os"),
		Arch:          ctx.Params(":arch"),
		App:           ctx.Params(":app"),
		Tag:           ctx.Params(":tag"),
		EncryptMethod: string(encryptMethod),
		Size:          int64(len(data)),
	}

	// Add to update service
	appV1, err := us.NewUpdateService("appV1", setting.Storage, setting.KeyManager)
	if err != nil {
		log.Errorf("[%s] create update service: %s", ctx.Req.RequestURI, err.Error())

		result, _ := json.Marshal(map[string]string{"Error": "Create Update Service Error"})
		return http.StatusBadRequest, result
	}

	tmpPath, err := appV1.Put(namespace+"/"+repository, a.GetName(), data, encryptMethod)
	if err != nil {
		log.Errorf("[%s] put to update service error: %s", ctx.Req.RequestURI, err.Error())

		result, _ := json.Marshal(map[string]string{"Error": "Put Update Service Error"})
		return http.StatusBadRequest, result
	}

	// Although we record the local storage path (or object storage key), we do load it by UpdateService.
	a.Path = tmpPath
	err = r.Put(a)
	if err != nil {
		log.Errorf("[%s] put artifact error: %s", ctx.Req.RequestURI, err.Error())

		result, _ := json.Marshal(map[string]string{"Error": "PUT Artifact Error"})
		return http.StatusBadRequest, result
	}

	return httpRet("AppV1 Put data", nil, err)
}