blob: 563278efdbf3017ca1fd473fb4696f587d0ff1e7 (
plain)
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
|
package middleware
import (
"net/http"
"gitlab.com/gitlab-org/software-supply-chain-security/authorization/authzd.git/pkg/rpc"
"gitlab.com/gitlab-org/software-supply-chain-security/authorization/sparkled/app/cfg"
"gitlab.com/gitlab-org/software-supply-chain-security/authorization/sparkled/app/domain"
"gitlab.com/gitlab-org/software-supply-chain-security/authorization/sparkled/pkg/pls"
)
func RequirePermission(permission Permission, ability rpc.Ability) func(http.Handler) http.Handler {
return func(next http.Handler) http.Handler {
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
user := cfg.CurrentUser.From(r.Context())
reply, err := ability.Allowed(r.Context(),
permission.RequestFor(user, &domain.Sparkle{ID: "*"}),
)
if err != nil {
pls.LogError(r.Context(), err)
w.WriteHeader(http.StatusForbidden)
return
}
if reply.Result {
next.ServeHTTP(w, r)
} else {
w.WriteHeader(http.StatusForbidden)
}
})
}
}
|