Skip to content

Commit eefda50

Browse files
committed
GitHub push (with secret)
1 parent 5b9e16f commit eefda50

File tree

3 files changed

+28
-8
lines changed

3 files changed

+28
-8
lines changed

src/app/controllers/project/get.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package project
22

33
import (
4+
"github.com/postgres-ci/app-server/src/app/models/auth"
45
"github.com/postgres-ci/app-server/src/app/models/project"
56
"github.com/postgres-ci/app-server/src/common/errors"
67
"github.com/postgres-ci/app-server/src/tools/params"
@@ -12,6 +13,15 @@ import (
1213

1314
func getHandler(c *http200ok.Context) {
1415

16+
currentUser := c.Get("CurrentUser").(*auth.User)
17+
18+
if !currentUser.IsSuperuser {
19+
20+
render.JSONError(c, http.StatusForbidden, "Access denied")
21+
22+
return
23+
}
24+
1525
project, err := project.Get(params.ToInt32(c, "ProjectID"))
1626

1727
if err != nil {

src/app/controllers/users/get.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package users
22

33
import (
4+
"github.com/postgres-ci/app-server/src/app/models/auth"
45
"github.com/postgres-ci/app-server/src/app/models/users"
56
"github.com/postgres-ci/app-server/src/common/errors"
67
"github.com/postgres-ci/app-server/src/tools/params"
@@ -12,6 +13,15 @@ import (
1213

1314
func getHandler(c *http200ok.Context) {
1415

16+
currentUser := c.Get("CurrentUser").(*auth.User)
17+
18+
if !currentUser.IsSuperuser {
19+
20+
render.JSONError(c, http.StatusForbidden, "Access denied")
21+
22+
return
23+
}
24+
1525
user, err := users.Get(params.ToInt32(c, "UserID"))
1626

1727
if err != nil {

src/app/controllers/webhooks/github.go

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -33,14 +33,14 @@ func githubHandler(c *http200ok.Context) {
3333

3434
if err != nil {
3535

36-
http.Error(c.Response, http.StatusText(http.StatusInternalServerError), http.StatusInternalServerError)
36+
render.JSONError(c, http.StatusInternalServerError, err.Error())
3737

3838
return
3939
}
4040

4141
if err := json.Unmarshal(source, &push); err != nil {
4242

43-
http.Error(c.Response, http.StatusText(http.StatusBadRequest), http.StatusBadRequest)
43+
render.JSONError(c, http.StatusBadRequest, err.Error())
4444

4545
return
4646
}
@@ -50,9 +50,9 @@ func githubHandler(c *http200ok.Context) {
5050
if err != nil {
5151

5252
if errors.IsNotFound(err) {
53-
http.Error(c.Response, "Project not nound", http.StatusNotFound)
53+
render.JSONError(c, http.StatusNotFound, "Project not nound")
5454
} else {
55-
http.Error(c.Response, http.StatusText(http.StatusInternalServerError), http.StatusInternalServerError)
55+
render.JSONError(c, http.StatusInternalServerError, err.Error())
5656
}
5757

5858
return
@@ -64,7 +64,7 @@ func githubHandler(c *http200ok.Context) {
6464

6565
if signature == "" {
6666

67-
http.Error(c.Response, "Missing X-Hub-Signature header", http.StatusForbidden)
67+
render.JSONError(c, http.StatusForbidden, "Missing X-Hub-Signature header")
6868

6969
return
7070
}
@@ -76,22 +76,22 @@ func githubHandler(c *http200ok.Context) {
7676

7777
if !hmac.Equal([]byte(signature[5:]), []byte(expectedMAC)) {
7878

79-
http.Error(c.Response, "HMAC verification failed", http.StatusForbidden)
79+
render.JSONError(c, http.StatusForbidden, "HMAC verification failed")
8080

8181
return
8282
}
8383
}
8484

8585
if err := github.Push(push); err != nil {
8686

87-
http.Error(c.Response, http.StatusText(http.StatusInternalServerError), http.StatusInternalServerError)
87+
render.JSONError(c, http.StatusInternalServerError, err.Error())
8888

8989
return
9090
}
9191

9292
case "":
9393

94-
http.Error(c.Response, "Missing X-GitHub-Event header", http.StatusBadRequest)
94+
render.JSONError(c, http.StatusBadRequest, "Missing X-GitHub-Event header")
9595

9696
return
9797

0 commit comments

Comments
 (0)