Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions docs/docs/ref/proto.mdx

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 9 additions & 0 deletions internal/controlplane/handlers.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (
"google.golang.org/grpc/codes"
"google.golang.org/grpc/status"

"github.com/mindersec/minder/internal/constants"
pb "github.com/mindersec/minder/pkg/api/protobuf/go/minder/v1"
)

Expand All @@ -25,3 +26,11 @@ func (s *Server) CheckHealth(ctx context.Context, _ *pb.CheckHealthRequest) (*pb
}
return &pb.CheckHealthResponse{Status: "OK"}, nil
}

// GetVersion returns the build and version info of the Minder server
func (*Server) GetVersion(_ context.Context, _ *pb.GetVersionRequest) (*pb.GetVersionResponse, error) {
return &pb.GetVersionResponse{
Version: constants.CLIVersion,
Commit: constants.Revision,
}, nil
}
15 changes: 13 additions & 2 deletions internal/controlplane/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ import (
"google.golang.org/grpc"
"google.golang.org/grpc/codes"
"google.golang.org/grpc/credentials/insecure"
"google.golang.org/grpc/metadata"
"google.golang.org/grpc/reflection"
"google.golang.org/grpc/status"

Expand All @@ -43,6 +44,7 @@ import (
"github.com/mindersec/minder/internal/auth"
"github.com/mindersec/minder/internal/auth/jwt"
"github.com/mindersec/minder/internal/authz"
"github.com/mindersec/minder/internal/constants"
"github.com/mindersec/minder/internal/controlplane/metrics"
"github.com/mindersec/minder/internal/crypto"
datasourcessvc "github.com/mindersec/minder/internal/datasources/service"
Expand Down Expand Up @@ -215,8 +217,7 @@ func initMetrics(r sdkmetric.Reader) *sdkmetric.MeterProvider {
res := resource.NewWithAttributes(
semconv.SchemaURL,
semconv.ServiceName("minder"),
// TODO: Make this auto-generated
semconv.ServiceVersion("v0.1.0"),
semconv.ServiceVersion(constants.CLIVersion),
)
// By default/spec (?!), otel includes net.sock.peer.{addr,port}.
// See https://github.com/open-telemetry/opentelemetry-go-contrib/issues/3071
Expand Down Expand Up @@ -265,6 +266,7 @@ func (s *Server) StartGRPCServer(ctx context.Context) error {
s.TokenValidationInterceptor,
EntityContextProjectInterceptor,
ProjectAuthorizationInterceptor,
VersionHeaderInterceptor(),
recovery.UnaryServerInterceptor(recovery.WithRecoveryHandlerContext(recoveryHandler)),
}

Expand Down Expand Up @@ -542,3 +544,12 @@ func withMaxSizeMiddleware(h http.Handler) http.Handler {
h.ServeHTTP(w, r)
})
}

// VersionHeaderInterceptor injects the Minder version into the HTTP response headers
func VersionHeaderInterceptor() grpc.UnaryServerInterceptor {
return func(ctx context.Context, req interface{}, _ *grpc.UnaryServerInfo, handler grpc.UnaryHandler) (interface{}, error) {
// SetHeader tells gRPC-Gateway to add this to the HTTP response
_ = grpc.SetHeader(ctx, metadata.Pairs("x-minder-version", constants.CLIVersion))
return handler(ctx, req)
}
}
28 changes: 28 additions & 0 deletions internal/controlplane/server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import (
"github.com/mindersec/minder/internal/auth"
mockjwt "github.com/mindersec/minder/internal/auth/jwt/mock"
mockauthz "github.com/mindersec/minder/internal/authz/mock"
"github.com/mindersec/minder/internal/constants"
"github.com/mindersec/minder/internal/controlplane/metrics"
"github.com/mindersec/minder/internal/crypto"
mock_service "github.com/mindersec/minder/internal/entities/properties/service/mock"
Expand Down Expand Up @@ -220,3 +221,30 @@ func httpDoWithRetry(client *http.Client, createRequest func() (*http.Request, e

return resp, err
}

func TestGetVersion(t *testing.T) {
t.Parallel()

server := &Server{}

resp, err := server.GetVersion(context.Background(), &pb.GetVersionRequest{})

require.NoError(t, err)
require.NotNil(t, resp)
require.Equal(t, constants.CLIVersion, resp.Version)
require.Equal(t, constants.Revision, resp.Commit)
}

func TestVersionHeaderInterceptor(t *testing.T) {
t.Parallel()

interceptor := VersionHeaderInterceptor()

handler := func(_ context.Context, _ interface{}) (interface{}, error) {
return "success", nil
}

_, err := interceptor(context.Background(), nil, &grpc.UnaryServerInfo{}, handler)

require.NoError(t, err)
}
28 changes: 28 additions & 0 deletions pkg/api/openapi/minder/v1/minder.swagger.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading
Loading