mirror of
https://github.com/pomerium/pomerium.git
synced 2025-05-23 22:17:14 +02:00
mcp: storage scaffolding (#5581)
This commit is contained in:
parent
f1a9401ddc
commit
db221cb826
4 changed files with 68 additions and 8 deletions
|
@ -2,14 +2,19 @@ package mcp
|
|||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"net/http"
|
||||
"path"
|
||||
|
||||
"github.com/gorilla/mux"
|
||||
"github.com/rs/cors"
|
||||
"go.opentelemetry.io/contrib/instrumentation/google.golang.org/grpc/otelgrpc"
|
||||
oteltrace "go.opentelemetry.io/otel/trace"
|
||||
googlegrpc "google.golang.org/grpc"
|
||||
|
||||
"github.com/pomerium/pomerium/config"
|
||||
"github.com/pomerium/pomerium/pkg/grpc"
|
||||
"github.com/pomerium/pomerium/pkg/grpc/databroker"
|
||||
"github.com/pomerium/pomerium/pkg/telemetry/trace"
|
||||
)
|
||||
|
||||
|
@ -24,19 +29,27 @@ const (
|
|||
)
|
||||
|
||||
type Handler struct {
|
||||
prefix string
|
||||
trace oteltrace.TracerProvider
|
||||
prefix string
|
||||
trace oteltrace.TracerProvider
|
||||
storage *Storage
|
||||
}
|
||||
|
||||
func New(
|
||||
ctx context.Context,
|
||||
prefix string,
|
||||
_ *config.Config,
|
||||
cfg *config.Config,
|
||||
) (*Handler, error) {
|
||||
tracerProvider := trace.NewTracerProvider(ctx, "MCP")
|
||||
|
||||
client, err := getDatabrokerServiceClient(ctx, cfg, tracerProvider)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("databroker client: %w", err)
|
||||
}
|
||||
|
||||
return &Handler{
|
||||
prefix: prefix,
|
||||
trace: tracerProvider,
|
||||
prefix: prefix,
|
||||
trace: tracerProvider,
|
||||
storage: NewStorage(client),
|
||||
}, nil
|
||||
}
|
||||
|
||||
|
@ -58,3 +71,27 @@ func (srv *Handler) HandlerFunc() http.HandlerFunc {
|
|||
|
||||
return r.ServeHTTP
|
||||
}
|
||||
|
||||
var outboundGRPCConnection = new(grpc.CachedOutboundGRPClientConn)
|
||||
|
||||
func getDatabrokerServiceClient(
|
||||
ctx context.Context,
|
||||
cfg *config.Config,
|
||||
tracerProvider oteltrace.TracerProvider,
|
||||
) (databroker.DataBrokerServiceClient, error) {
|
||||
sharedKey, err := cfg.Options.GetSharedKey()
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("shared key: %w", err)
|
||||
}
|
||||
|
||||
dataBrokerConn, err := outboundGRPCConnection.Get(ctx, &grpc.OutboundOptions{
|
||||
OutboundPort: cfg.OutboundPort,
|
||||
InstallationID: cfg.Options.InstallationID,
|
||||
ServiceName: cfg.Options.Services,
|
||||
SignedJWTKey: sharedKey,
|
||||
}, googlegrpc.WithStatsHandler(otelgrpc.NewClientHandler(otelgrpc.WithTracerProvider(tracerProvider))))
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("databroker connection: %w", err)
|
||||
}
|
||||
return databroker.NewDataBrokerServiceClient(dataBrokerConn), nil
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue