Skip to content
Merged
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
6 changes: 3 additions & 3 deletions internal/controller/nginx/agent/command.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down Expand Up @@ -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
}
Expand Down Expand Up @@ -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
}
Expand Down
6 changes: 3 additions & 3 deletions internal/controller/nginx/agent/file.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down Expand Up @@ -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
}
Expand Down Expand Up @@ -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
}
Expand Down
6 changes: 3 additions & 3 deletions internal/controller/nginx/agent/grpc/context/context.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package context
package grpcinfo

import (
"context"
Expand All @@ -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
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package context_test
package grpcinfo_test

import (
"context"
Expand All @@ -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))
}
Expand All @@ -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{}))
}
4 changes: 2 additions & 2 deletions internal/controller/nginx/agent/grpc/context/doc.go
Original file line number Diff line number Diff line change
@@ -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
Loading