-
Notifications
You must be signed in to change notification settings - Fork 104
/
list_mount.go
38 lines (31 loc) · 977 Bytes
/
list_mount.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
package repo
import (
"net/http"
"strconv"
"github.com/bleenco/abstruse/server/api/middlewares"
"github.com/bleenco/abstruse/server/api/render"
"github.com/bleenco/abstruse/server/core"
"github.com/go-chi/chi"
)
// HandleListMount returns http.HandlerFunc that writes JSON encoded
// list of env variables for repository to the http response body.
func HandleListMount(mounts core.MountsStore, repos core.RepositoryStore) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
claims := middlewares.ClaimsFromCtx(r.Context())
id, err := strconv.Atoi(chi.URLParam(r, "id"))
if err != nil {
render.InternalServerError(w, err.Error())
return
}
if perm := repos.GetPermissions(uint(id), claims.ID); !perm.Read {
render.UnathorizedError(w, "permission denied")
return
}
mts, err := mounts.List(uint(id))
if err != nil {
render.InternalServerError(w, err.Error())
return
}
render.JSON(w, http.StatusOK, mts)
}
}