Apply fix for apis

This commit is contained in:
Ben Toogood 2020-04-03 09:45:39 +01:00
parent 49a1130281
commit 183c8bfb81

View File

@ -67,17 +67,19 @@ func (h authHandler) ServeHTTP(w http.ResponseWriter, req *http.Request) {
resName = resName + "." + endpoint.Name resName = resName + "." + endpoint.Name
} }
// determine the resource path. there is an inconsistency in how resolvers
// use method, some use it as Users.ReadUser (the rpc method), and others
// use it as the HTTP method, e.g GET. TODO: Refactor this to make it consistent.
resEndpoint := endpoint.Path
if len(endpoint.Path) == 0 {
resEndpoint = endpoint.Method
}
// Perform the verification check to see if the account has access to // Perform the verification check to see if the account has access to
// the resource they're requesting // the resource they're requesting
err = h.auth.Verify(acc, &auth.Resource{ res := &auth.Resource{Type: "service", Name: resName, Endpoint: resEndpoint}
Type: "service", if err := h.auth.Verify(acc, res); err == nil {
Name: resName, // The account has the necessary permissions to access the resource
Endpoint: endpoint.Path,
})
// The account has the necessary permissions to access the
// resource
if err == nil {
h.handler.ServeHTTP(w, req) h.handler.ServeHTTP(w, req)
return return
} }