mirror of
https://github.com/woodpecker-ci/woodpecker.git
synced 2024-11-26 20:01:02 +00:00
Let normal repo admins change timeout to lower values (#543)
fix #534 fix #179 Co-authored-by: Anbraten <anton@ju60.de>
This commit is contained in:
parent
2c75a299e2
commit
7931bc78eb
1 changed files with 19 additions and 9 deletions
|
@ -31,6 +31,10 @@ import (
|
||||||
"github.com/woodpecker-ci/woodpecker/shared/token"
|
"github.com/woodpecker-ci/woodpecker/shared/token"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// TODO: make it set system wide via environment variables
|
||||||
|
const defaultTimeout = 60 // 1 hour default build time
|
||||||
|
const maxTimeout = defaultTimeout * 2
|
||||||
|
|
||||||
func PostRepo(c *gin.Context) {
|
func PostRepo(c *gin.Context) {
|
||||||
remote_ := server.Config.Services.Remote
|
remote_ := server.Config.Services.Remote
|
||||||
store_ := store.FromContext(c)
|
store_ := store.FromContext(c)
|
||||||
|
@ -38,7 +42,7 @@ func PostRepo(c *gin.Context) {
|
||||||
repo := session.Repo(c)
|
repo := session.Repo(c)
|
||||||
|
|
||||||
if repo.IsActive {
|
if repo.IsActive {
|
||||||
c.String(409, "Repository is already active.")
|
c.String(http.StatusConflict, "Repository is already active.")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -54,7 +58,9 @@ func PostRepo(c *gin.Context) {
|
||||||
}
|
}
|
||||||
|
|
||||||
if repo.Timeout == 0 {
|
if repo.Timeout == 0 {
|
||||||
repo.Timeout = 60 // 1 hour default build time
|
repo.Timeout = defaultTimeout
|
||||||
|
} else if repo.Timeout > maxTimeout {
|
||||||
|
repo.Timeout = maxTimeout
|
||||||
}
|
}
|
||||||
|
|
||||||
if repo.Hash == "" {
|
if repo.Hash == "" {
|
||||||
|
@ -67,7 +73,7 @@ func PostRepo(c *gin.Context) {
|
||||||
t := token.New(token.HookToken, repo.FullName)
|
t := token.New(token.HookToken, repo.FullName)
|
||||||
sig, err := t.Sign(repo.Hash)
|
sig, err := t.Sign(repo.Hash)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
c.String(500, err.Error())
|
c.String(http.StatusInternalServerError, err.Error())
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -79,7 +85,7 @@ func PostRepo(c *gin.Context) {
|
||||||
|
|
||||||
err = remote_.Activate(c, user, repo, link)
|
err = remote_.Activate(c, user, repo, link)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
c.String(500, err.Error())
|
c.String(http.StatusInternalServerError, err.Error())
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -90,11 +96,11 @@ func PostRepo(c *gin.Context) {
|
||||||
|
|
||||||
err = store_.UpdateRepo(repo)
|
err = store_.UpdateRepo(repo)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
c.String(500, err.Error())
|
c.String(http.StatusInternalServerError, err.Error())
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
c.JSON(200, repo)
|
c.JSON(http.StatusOK, repo)
|
||||||
}
|
}
|
||||||
|
|
||||||
func PatchRepo(c *gin.Context) {
|
func PatchRepo(c *gin.Context) {
|
||||||
|
@ -108,8 +114,12 @@ func PatchRepo(c *gin.Context) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
if (in.IsTrusted != nil || in.Timeout != nil) && !user.Admin {
|
if in.Timeout != nil && *in.Timeout > maxTimeout && !user.Admin {
|
||||||
c.String(403, "Insufficient privileges")
|
c.String(http.StatusForbidden, fmt.Sprintf("Timeout is not allowed to be higher than max timeout (%dmin)", maxTimeout))
|
||||||
|
}
|
||||||
|
if in.IsTrusted != nil && *in.IsTrusted != repo.IsTrusted && !user.Admin {
|
||||||
|
log.Trace().Msgf("user '%s' wants to make repo trusted without being an instance admin ", user.Login)
|
||||||
|
c.String(http.StatusForbidden, "Insufficient privileges")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -133,7 +143,7 @@ func PatchRepo(c *gin.Context) {
|
||||||
case string(model.VisibilityInternal), string(model.VisibilityPrivate), string(model.VisibilityPublic):
|
case string(model.VisibilityInternal), string(model.VisibilityPrivate), string(model.VisibilityPublic):
|
||||||
repo.Visibility = model.RepoVisibly(*in.Visibility)
|
repo.Visibility = model.RepoVisibly(*in.Visibility)
|
||||||
default:
|
default:
|
||||||
c.String(400, "Invalid visibility type")
|
c.String(http.StatusBadRequest, "Invalid visibility type")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue