Skip to content

Commit

Permalink
cirrus serve: send X-Cirrus-Evaluator-Version header for all responses (
Browse files Browse the repository at this point in the history
#332)

* cirrus serve: send X-Cirrus-Evaluator-Ident header for all responses

* X-Cirrus-Evaluator-Ident → X-Cirrus-Evaluator-Version
  • Loading branch information
edigaryev authored Mar 9, 2021
1 parent f63ce46 commit d3baf27
Showing 1 changed file with 20 additions and 1 deletion.
21 changes: 20 additions & 1 deletion internal/evaluator/evaluator.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"encoding/json"
"fmt"
"github.com/cirruslabs/cirrus-ci-agent/api"
"github.com/cirruslabs/cirrus-cli/internal/version"
"github.com/cirruslabs/cirrus-cli/pkg/larker"
"github.com/cirruslabs/cirrus-cli/pkg/larker/fs"
"github.com/cirruslabs/cirrus-cli/pkg/larker/fs/dummy"
Expand All @@ -13,6 +14,7 @@ import (
"github.com/cirruslabs/cirrus-cli/pkg/parser/parsererror"
"google.golang.org/grpc"
"google.golang.org/grpc/codes"
"google.golang.org/grpc/metadata"
"google.golang.org/grpc/status"
"google.golang.org/protobuf/reflect/protodesc"
"google.golang.org/protobuf/reflect/protoreflect"
Expand All @@ -26,8 +28,25 @@ type ConfigurationEvaluatorServiceServer struct {
api.UnimplementedCirrusConfigurationEvaluatorServiceServer
}

func addVersion(
ctx context.Context,
req interface{},
info *grpc.UnaryServerInfo,
handler grpc.UnaryHandler,
) (resp interface{}, err error) {
headers := map[string]string{
"X-Cirrus-Evaluator-Version": version.FullVersion,
}

if err := grpc.SetHeader(ctx, metadata.New(headers)); err != nil {
return nil, err
}

return handler(ctx, req)
}

func Serve(ctx context.Context, lis net.Listener) error {
server := grpc.NewServer()
server := grpc.NewServer(grpc.UnaryInterceptor(addVersion))

api.RegisterCirrusConfigurationEvaluatorServiceServer(server, &ConfigurationEvaluatorServiceServer{})

Expand Down

0 comments on commit d3baf27

Please sign in to comment.