-
Notifications
You must be signed in to change notification settings - Fork 115
/
authz.go
54 lines (42 loc) · 1.26 KB
/
authz.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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
package authz
// <!-- START clutchdoc -->
// description: Exposes an endpoint for RBAC policy checks on arbitrary resources and users.
// <!-- END clutchdoc -->
import (
"context"
"errors"
"github.com/golang/protobuf/ptypes/any"
"github.com/uber-go/tally/v4"
"go.uber.org/zap"
authzv1 "github.com/lyft/clutch/backend/api/authz/v1"
"github.com/lyft/clutch/backend/module"
"github.com/lyft/clutch/backend/service"
"github.com/lyft/clutch/backend/service/authz"
)
const Name = "clutch.module.authz"
func New(*any.Any, *zap.Logger, tally.Scope) (module.Module, error) {
svc, ok := service.Registry["clutch.service.authz"]
if !ok {
return nil, errors.New("unable to get authz service")
}
p, ok := svc.(authz.Client)
if !ok {
return nil, errors.New("authz service was not the correct type")
}
return &mod{
authzv1: &api{zclient: p},
}, nil
}
type mod struct {
authzv1 authzv1.AuthzAPIServer
}
func (m *mod) Register(r module.Registrar) error {
authzv1.RegisterAuthzAPIServer(r.GRPCServer(), m.authzv1)
return r.RegisterJSONGateway(authzv1.RegisterAuthzAPIHandler)
}
type api struct {
zclient authz.Client
}
func (a *api) Check(ctx context.Context, request *authzv1.CheckRequest) (*authzv1.CheckResponse, error) {
return a.zclient.Check(ctx, request)
}