Last active
March 1, 2019 16:17
-
-
Save vtolstov/992947fd88ba0fa465bfbe03ceadbbac to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package policy | |
import ( | |
"context" | |
"github.com/micro/go-micro/client" | |
"github.com/micro/go-micro/server" | |
"unistack.org/centralv2/service/policy/policypb" | |
) | |
func NewHandlerWrapper(copts ...client.Option) server.HandlerWrapper { | |
return func(fn server.HandlerFunc) server.HandlerFunc { | |
return func(ctx context.Context, req server.Request, rsp interface{}) error { | |
pc := policypb.NewPolicyService(policypb.SvcName, client.NewClient(copts...)) | |
preq := &policypb.PolicyCheckReq{ | |
Action: req.Service() + "." + req.Endpoint(), | |
User: uid, | |
Resource: rid, | |
} | |
_, err := pc.Check(ctx, preq) | |
if err == nil { | |
err = fn(ctx, req, rsp) | |
} | |
return err | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment