summaryrefslogtreecommitdiff
path: root/pkg/authz/server.go
diff options
context:
space:
mode:
authormo khan <mo@mokhan.ca>2025-06-26 14:36:34 -0600
committermo khan <mo@mokhan.ca>2025-06-26 14:36:34 -0600
commitfeca0a2a1680a0071e8223adcc861d8c0cc8aea9 (patch)
tree436f5830b803223da24ee9e3ea0d1f011cfb6435 /pkg/authz/server.go
parent0275f5dca7c66640587294b95ce396dd6d6a02c8 (diff)
feat: connect to the remove authorization daemon
Diffstat (limited to 'pkg/authz/server.go')
-rw-r--r--pkg/authz/server.go16
1 files changed, 15 insertions, 1 deletions
diff --git a/pkg/authz/server.go b/pkg/authz/server.go
index e1b0669..4728182 100644
--- a/pkg/authz/server.go
+++ b/pkg/authz/server.go
@@ -4,6 +4,7 @@ import (
"context"
auth "github.com/envoyproxy/go-control-plane/envoy/service/auth/v3"
+ xcontext "github.com/xlgmokha/x/pkg/context"
"github.com/xlgmokha/x/pkg/log"
"github.com/xlgmokha/x/pkg/x"
"gitlab.com/gitlab-org/software-supply-chain-security/authorization/sparkled/pkg/pls"
@@ -11,6 +12,8 @@ import (
"google.golang.org/grpc/reflection"
)
+var Connection xcontext.Key[*grpc.ClientConn] = xcontext.Key[*grpc.ClientConn]("grpc_client")
+
type Server struct {
*grpc.Server
}
@@ -23,7 +26,18 @@ func New(ctx context.Context, options ...grpc.ServerOption) *Server {
grpc.UnaryInterceptor(pls.LogGRPC(logger)),
grpc.StreamInterceptor(pls.LogGRPCStream(logger)),
)...)
- auth.RegisterAuthorizationServer(server, NewCheckService())
+
+ connection := Connection.From(ctx)
+ if x.IsZero(connection) {
+ auth.RegisterAuthorizationServer(server, NewCheckService(nil))
+ } else {
+ auth.RegisterAuthorizationServer(
+ server,
+ NewCheckService(
+ auth.NewAuthorizationClient(connection),
+ ),
+ )
+ }
reflection.Register(server)
return &Server{