Beispiel #1
0
func DeleteRepoPackage(c *gin.Context) {
	repo := session.Repo(c)
	pkgname := c.Param("package")
	arch := c.Param("arch")

	if !util.StrContains(arch, repo.Archs) {
		c.AbortWithStatus(http.StatusNotFound)
		return
	}

	pkg, err := repo.Package(pkgname, arch, true)
	if err != nil {
		log.Errorf("Failed to get repo package '%s': %s", pkgname, err)
		c.AbortWithStatus(http.StatusInternalServerError)
		return
	}

	if pkg == nil {
		c.AbortWithStatus(http.StatusNotFound)
		return
	}

	err = repo.Remove([]string{pkgname}, arch)
	if err != nil {
		log.Errorf("Failed to remove repo package '%s': %s", pkgname, err)
		c.AbortWithStatus(http.StatusInternalServerError)
		return
	}

	c.Status(http.StatusOK)
}
Beispiel #2
0
func PostUploadDone(c *gin.Context) {
	sessionID := c.Param("sessionid")
	repo := session.Repo(c)
	state := checker.FromContext(c)

	if pkgs, ok := sessions[sessionID]; ok {
		delete(sessions, sessionID)
		err := repo.Add(pkgs)
		if err != nil {
			log.Errorf("failed to add packages '%s' to repository '%s': %s", strings.Join(pkgs, ", "), repo.Name, err)
			c.AbortWithStatus(http.StatusInternalServerError)
			return
		}

		// clear packages from checker state
		// TODO: check pkg name (maybe it's the full path here?)
		for _, pkg := range pkgs {
			state.ClearPkg(pkg, repo.Owner, repo.Name)
		}
		c.Writer.WriteHeader(http.StatusOK)
		return
	}

	c.AbortWithStatus(http.StatusNotFound)
}
Beispiel #3
0
func PatchRepo(c *gin.Context) {
	r := session.Repo(c)

	in := struct {
		SourceOwner  *string `json:"source_owner,omitempty"`
		SourceName   *string `json:"source_name,omitempty"`
		SourceBranch *string `json:"source_branch,omitempty"`
		BuildBranch  *string `json:"build_branch,omitempty"`
		Name         *string `json:"name,omitempty"`
	}{}

	err := c.BindJSON(&in)
	if err != nil {
		log.Error(err)
		c.AbortWithStatus(http.StatusBadRequest)
		return
	}

	if in.SourceOwner != nil {
		r.SourceOwner = *in.SourceOwner
	}

	if in.SourceName != nil {
		r.SourceName = *in.SourceName
	}

	if in.SourceBranch != nil {
		r.SourceBranch = *in.SourceBranch
	}

	if in.BuildBranch != nil {
		r.BuildBranch = *in.BuildBranch
	}

	if in.Name != nil {
		r.Name = *in.Name
		if !repo.ValidRepoName(r.Name) {
			c.AbortWithStatus(http.StatusBadRequest)
			return
		}
	}

	err = store.UpdateRepo(c, r.Repo)
	if err != nil {
		log.Errorf("failed to update repo '%s/%s': %s", r.Owner, r.Name, err)
		c.AbortWithStatus(http.StatusInternalServerError)
		return
	}

	c.JSON(http.StatusOK, r)
}
Beispiel #4
0
func GetRepoPackages(c *gin.Context) {
	repo := session.Repo(c)
	arch := c.Param("arch")

	if !util.StrContains(arch, repo.Archs) {
		c.AbortWithStatus(http.StatusNotFound)
		return
	}

	pkgs, err := repo.Packages(arch, false)
	if err != nil {
		log.Errorf("Failed to get repo packages: %s", err)
		c.AbortWithStatus(http.StatusInternalServerError)
		return
	}

	c.JSON(http.StatusOK, pkgs)
}
Beispiel #5
0
func PostUploadFile(c *gin.Context) {
	pkg := c.Param("filename")
	sessionID := c.Param("sessionid")
	repo := session.Repo(c)

	if _, ok := sessions[sessionID]; !ok {
		c.AbortWithStatus(http.StatusNotFound)
	}

	// TODO check valid filename
	// TODO check valid file content
	// TODO: clear session on error

	new, err := repo.IsNewFilename(pkg)
	if err != nil {
		c.AbortWithError(400, err)
		return
	}

	if !new {
		c.AbortWithStatus(208)
		return
	}

	pkg = path.Join(repo.Path(), pkg)

	f, err := os.Create(pkg)
	if err != nil {
		log.Errorf("failed to create file %s: %s", pkg, err)
		c.AbortWithStatus(http.StatusInternalServerError)
		return
	}

	_, err = io.Copy(f, c.Request.Body)
	if err != nil {
		log.Errorf("failed to write data: %s", err)
		c.AbortWithStatus(http.StatusInternalServerError)
		return
	}

	sessions[sessionID] = append(sessions[sessionID], pkg)

	c.Writer.WriteHeader(http.StatusOK)
}
Beispiel #6
0
func DeleteRepo(c *gin.Context) {
	repo := session.Repo(c)

	err := repo.ClearPath()
	if err != nil {
		log.Errorf("failed to delete repo storage '%s/%s': %s", repo.Owner, repo.Name, err)
		c.AbortWithStatus(http.StatusInternalServerError)
		return
	}

	err = store.DeleteRepo(c, repo.Repo)
	if err != nil {
		log.Errorf("failed to remove repo db entry '%s/%s': %s", repo.Owner, repo.Name, err)
		c.AbortWithStatus(http.StatusInternalServerError)
		return
	}

	c.Status(http.StatusOK)
}
Beispiel #7
0
func GetRepoPackageFiles(c *gin.Context) {
	repo := session.Repo(c)
	pkgname := c.Param("package")
	arch := c.Param("arch")

	if !util.StrContains(arch, repo.Archs) {
		c.AbortWithStatus(http.StatusNotFound)
		return
	}

	pkg, err := repo.Package(pkgname, arch, true)
	if err != nil {
		log.Errorf("Failed to get repo package '%s': %s", pkgname, err)
		c.AbortWithStatus(http.StatusInternalServerError)
		return
	}

	if pkg == nil {
		c.AbortWithStatus(http.StatusNotFound)
		return
	}

	c.JSON(http.StatusOK, pkg.Files)
}
Beispiel #8
0
func ServeRepoFile(c *gin.Context) {
	repo := session.Repo(c)
	arch := c.Param("arch")
	file := c.Param("file")
	c.File(path.Join(repo.PathDeep(arch), file))
}
Beispiel #9
0
func GetRepo(c *gin.Context) {
	c.JSON(http.StatusOK, session.Repo(c))
}