summaryrefslogtreecommitdiff
path: root/pkg/authz/remote_check_service.go
blob: 43178fe02c93645dfcacc73c0c233e3496793da9 (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
package authz

import (
	"context"
	"errors"

	auth "github.com/envoyproxy/go-control-plane/envoy/service/auth/v3"
	"github.com/xlgmokha/x/pkg/x"
)

type RemoteCheckService struct {
	client auth.AuthorizationClient
	auth.UnimplementedAuthorizationServer
}

func NewRemoteCheckService(client auth.AuthorizationClient) auth.AuthorizationServer {
	return &RemoteCheckService{
		client: client,
	}
}

func (svc *RemoteCheckService) Check(ctx context.Context, request *auth.CheckRequest) (*auth.CheckResponse, error) {
	if x.IsZero(svc.client) {
		return nil, errors.New("RPC client is not configured")
	}

	return svc.client.Check(ctx, request)
}