summaryrefslogtreecommitdiff
path: root/pkg/authz/server.go
blob: b890387489cd41e410e9f68d6be467553daa9809 (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
29
30
31
32
33
34
35
36
37
38
39
package authz

import (
	"context"
	"net/http"

	auth "github.com/envoyproxy/go-control-plane/envoy/service/auth/v3"
	"github.com/xlgmokha/x/pkg/env"
	"github.com/xlgmokha/x/pkg/log"
	"github.com/xlgmokha/x/pkg/x"
	"gitlab.com/gitlab-org/software-supply-chain-security/authorization/authzd.git/pkg/rpc"
	"gitlab.com/gitlab-org/software-supply-chain-security/authorization/sparkled/pkg/pls"
	"gitlab.com/gitlab-org/software-supply-chain-security/authorization/sparkled/pkg/web"
	"google.golang.org/grpc"
	"google.golang.org/grpc/reflection"
)

type Server struct {
	*grpc.Server
}

func New(ctx context.Context, options ...grpc.ServerOption) *Server {
	logger := log.From(ctx)

	server := grpc.NewServer(x.Prepend(
		options,
		grpc.UnaryInterceptor(pls.LogGRPC(logger)),
		grpc.StreamInterceptor(pls.LogGRPCStream(logger)),
	)...)
	auth.RegisterAuthorizationServer(server, NewCheckService(rpc.NewAbilityProtobufClient(
		env.Fetch("AUTHZD_HOST", "https://authzd.staging.runway.gitlab.net"),
		&http.Client{Transport: &web.Transport{Logger: logger}},
	)))
	reflection.Register(server)

	return &Server{
		Server: server,
	}
}