MCPcopy Create free account
hub / github.com/convox/rack / Authorize

Method Authorize

pkg/api/authorization.go:11–25  ·  view source on GitHub ↗
(next stdapi.HandlerFunc)

Source from the content-addressed store, hash-verified

9)
10
11func (s *Server) Authorize(next stdapi.HandlerFunc) stdapi.HandlerFunc {
12 return func(c *stdapi.Context) error {
13 switch c.Request().Method {
14 case http.MethodGet:
15 if !CanRead(c) {
16 return stdapi.Errorf(401, "you are unauthorized to access this")
17 }
18 default:
19 if !CanWrite(c) {
20 return stdapi.Errorf(401, "you are unauthorized to access this")
21 }
22 }
23 return next(c)
24 }
25}
26
27func CanRead(c *stdapi.Context) bool {
28 if d := c.Get(structs.ConvoxRoleParam); d != nil {

Callers 1

TestAuthorizeFunction · 0.95

Calls 3

CanReadFunction · 0.85
CanWriteFunction · 0.85
RequestMethod · 0.80

Tested by 1

TestAuthorizeFunction · 0.76