diff --git a/internal/controller/nginx/agent/command.go b/internal/controller/nginx/agent/command.go index 18e62c28d6..af4a254a47 100644 --- a/internal/controller/nginx/agent/command.go +++ b/internal/controller/nginx/agent/command.go @@ -77,7 +77,7 @@ func (cs *commandService) CreateConnection( return nil, errors.New("empty connection request") } - gi, ok := grpcContext.GrpcInfoFromContext(ctx) + gi, ok := grpcContext.FromContext(ctx) if !ok { return nil, agentgrpc.ErrStatusInvalidConnection } @@ -126,7 +126,7 @@ func (cs *commandService) CreateConnection( func (cs *commandService) Subscribe(in pb.CommandService_SubscribeServer) error { ctx := in.Context() - gi, ok := grpcContext.GrpcInfoFromContext(ctx) + gi, ok := grpcContext.FromContext(ctx) if !ok { return agentgrpc.ErrStatusInvalidConnection } @@ -562,7 +562,7 @@ func (cs *commandService) UpdateDataPlaneStatus( return nil, errors.New("empty UpdateDataPlaneStatus request") } - gi, ok := grpcContext.GrpcInfoFromContext(ctx) + gi, ok := grpcContext.FromContext(ctx) if !ok { return nil, agentgrpc.ErrStatusInvalidConnection } diff --git a/internal/controller/nginx/agent/file.go b/internal/controller/nginx/agent/file.go index 39355a55d4..035c96b77b 100644 --- a/internal/controller/nginx/agent/file.go +++ b/internal/controller/nginx/agent/file.go @@ -56,7 +56,7 @@ func (fs *fileService) GetFile( ctx context.Context, req *pb.GetFileRequest, ) (*pb.GetFileResponse, error) { - gi, ok := grpcContext.GrpcInfoFromContext(ctx) + gi, ok := grpcContext.FromContext(ctx) if !ok { return nil, agentgrpc.ErrStatusInvalidConnection } @@ -84,7 +84,7 @@ func (fs *fileService) GetFileStream( req *pb.GetFileRequest, server grpc.ServerStreamingServer[pb.FileDataChunk], ) error { - gi, ok := grpcContext.GrpcInfoFromContext(server.Context()) + gi, ok := grpcContext.FromContext(server.Context()) if !ok { return agentgrpc.ErrStatusInvalidConnection } @@ -187,7 +187,7 @@ func (fs *fileService) UpdateOverview( ctx context.Context, req *pb.UpdateOverviewRequest, ) (*pb.UpdateOverviewResponse, error) { - gi, ok := grpcContext.GrpcInfoFromContext(ctx) + gi, ok := grpcContext.FromContext(ctx) if !ok { return &pb.UpdateOverviewResponse{}, agentgrpc.ErrStatusInvalidConnection } diff --git a/internal/controller/nginx/agent/grpc/context/context.go b/internal/controller/nginx/agent/grpc/context/context.go index d676badc72..62a15627a5 100644 --- a/internal/controller/nginx/agent/grpc/context/context.go +++ b/internal/controller/nginx/agent/grpc/context/context.go @@ -1,4 +1,4 @@ -package context +package grpcinfo import ( "context" @@ -17,9 +17,9 @@ func NewGrpcContext(ctx context.Context, r GrpcInfo) context.Context { return context.WithValue(ctx, contextGRPCKey{}, r) } -// GrpcInfoFromContext returns the GrpcInfo saved in ctx if it exists. +// FromContext returns the GrpcInfo saved in ctx if it exists. // Returns false if there's no GrpcInfo in the context. -func GrpcInfoFromContext(ctx context.Context) (GrpcInfo, bool) { +func FromContext(ctx context.Context) (GrpcInfo, bool) { v, ok := ctx.Value(contextGRPCKey{}).(GrpcInfo) return v, ok } diff --git a/internal/controller/nginx/agent/grpc/context/context_test.go b/internal/controller/nginx/agent/grpc/context/context_test.go index 82334618a5..92c30fe78c 100644 --- a/internal/controller/nginx/agent/grpc/context/context_test.go +++ b/internal/controller/nginx/agent/grpc/context/context_test.go @@ -1,4 +1,4 @@ -package context_test +package grpcinfo_test import ( "context" @@ -16,7 +16,7 @@ func TestGrpcInfoInContext(t *testing.T) { grpcInfo := grpcContext.GrpcInfo{Token: "test"} newCtx := grpcContext.NewGrpcContext(context.Background(), grpcInfo) - info, ok := grpcContext.GrpcInfoFromContext(newCtx) + info, ok := grpcContext.FromContext(newCtx) g.Expect(ok).To(BeTrue()) g.Expect(info).To(Equal(grpcInfo)) } @@ -25,7 +25,7 @@ func TestGrpcInfoNotInContext(t *testing.T) { t.Parallel() g := NewWithT(t) - info, ok := grpcContext.GrpcInfoFromContext(context.Background()) + info, ok := grpcContext.FromContext(context.Background()) g.Expect(ok).To(BeFalse()) g.Expect(info).To(Equal(grpcContext.GrpcInfo{})) } diff --git a/internal/controller/nginx/agent/grpc/context/doc.go b/internal/controller/nginx/agent/grpc/context/doc.go index 4091b10d69..8a039ac16a 100644 --- a/internal/controller/nginx/agent/grpc/context/doc.go +++ b/internal/controller/nginx/agent/grpc/context/doc.go @@ -1,4 +1,4 @@ /* -Package context contains the functions for storing extra information in the gRPC context. +Package grpcinfo contains helpers for storing and retrieving gRPC identity information in a context.Context. */ -package context //nolint:revive // ignoring conflicting package name +package grpcinfo