Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix inconsistency between gRPC function/type names #3285

Merged
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
8 changes: 4 additions & 4 deletions config/configauth/mock_serverauth.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,13 +42,13 @@ func (m *MockAuthenticator) Authenticate(ctx context.Context, headers map[string
return m.AuthenticateFunc(ctx, headers)
}

// GrpcUnaryServerInterceptor isn't currently implemented and always returns nil.
func (m *MockAuthenticator) GrpcUnaryServerInterceptor(context.Context, interface{}, *grpc.UnaryServerInfo, grpc.UnaryHandler) (interface{}, error) {
// GRPCUnaryServerInterceptor isn't currently implemented and always returns nil.
func (m *MockAuthenticator) GRPCUnaryServerInterceptor(context.Context, interface{}, *grpc.UnaryServerInfo, grpc.UnaryHandler) (interface{}, error) {
return nil, nil
}

// GrpcStreamServerInterceptor isn't currently implemented and always returns nil.
func (m *MockAuthenticator) GrpcStreamServerInterceptor(interface{}, grpc.ServerStream, *grpc.StreamServerInfo, grpc.StreamHandler) error {
// GRPCStreamServerInterceptor isn't currently implemented and always returns nil.
func (m *MockAuthenticator) GRPCStreamServerInterceptor(interface{}, grpc.ServerStream, *grpc.StreamServerInfo, grpc.StreamHandler) error {
return nil
}

Expand Down
4 changes: 2 additions & 2 deletions config/configauth/mock_serverauth_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,13 +51,13 @@ func TestNilOperations(t *testing.T) {
}

{
ret, err := m.GrpcUnaryServerInterceptor(origCtx, nil, nil, nil)
ret, err := m.GRPCUnaryServerInterceptor(origCtx, nil, nil, nil)
assert.Nil(t, ret)
assert.NoError(t, err)
}

{
err := m.GrpcStreamServerInterceptor(nil, nil, nil, nil)
err := m.GRPCStreamServerInterceptor(nil, nil, nil, nil)
assert.NoError(t, err)
}

Expand Down
28 changes: 14 additions & 14 deletions config/configauth/serverauth.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,38 +42,38 @@ type ServerAuthenticator interface {
// The deadline and cancellation given to this function must be respected, but note that authentication data has to be part of the map, not context.
Authenticate(ctx context.Context, headers map[string][]string) error

// GrpcUnaryServerInterceptor is a helper method to provide a gRPC-compatible UnaryServerInterceptor, typically calling the authenticator's Authenticate method.
// GRPCUnaryServerInterceptor is a helper method to provide a gRPC-compatible UnaryServerInterceptor, typically calling the authenticator's Authenticate method.
// While the context is the typical source of authentication data, the interceptor is free to determine where the auth data should come from. For instance, some
// receivers might implement an interceptor that looks into the payload instead.
// Once the authentication succeeds, the interceptor is expected to call the handler.
// See https://pkg.go.dev/google.golang.org/grpc#UnaryServerInterceptor.
GrpcUnaryServerInterceptor(ctx context.Context, req interface{}, srvInfo *grpc.UnaryServerInfo, handler grpc.UnaryHandler) (interface{}, error)
GRPCUnaryServerInterceptor(ctx context.Context, req interface{}, srvInfo *grpc.UnaryServerInfo, handler grpc.UnaryHandler) (interface{}, error)

// GrpcStreamServerInterceptor is a helper method to provide a gRPC-compatible StreamServerInterceptor, typically calling the authenticator's Authenticate method.
// GRPCStreamServerInterceptor is a helper method to provide a gRPC-compatible StreamServerInterceptor, typically calling the authenticator's Authenticate method.
// While the context is the typical source of authentication data, the interceptor is free to determine where the auth data should come from. For instance, some
// receivers might implement an interceptor that looks into the payload instead.
// Once the authentication succeeds, the interceptor is expected to call the handler.
// See https://pkg.go.dev/google.golang.org/grpc#StreamServerInterceptor.
GrpcStreamServerInterceptor(srv interface{}, stream grpc.ServerStream, srvInfo *grpc.StreamServerInfo, handler grpc.StreamHandler) error
GRPCStreamServerInterceptor(srv interface{}, stream grpc.ServerStream, srvInfo *grpc.StreamServerInfo, handler grpc.StreamHandler) error
}

// AuthenticateFunc defines the signature for the function responsible for performing the authentication based on the given headers map.
// See ServerAuthenticator.Authenticate.
type AuthenticateFunc func(ctx context.Context, headers map[string][]string) error

// GrpcUnaryInterceptorFunc defines the signature for the function intercepting unary gRPC calls, useful for authenticators to use as
// GRPCUnaryInterceptorFunc defines the signature for the function intercepting unary gRPC calls, useful for authenticators to use as
// types for internal structs, making it easier to mock them in tests.
// See ServerAuthenticator.GrpcUnaryServerInterceptor.
type GrpcUnaryInterceptorFunc func(ctx context.Context, req interface{}, info *grpc.UnaryServerInfo, handler grpc.UnaryHandler, authenticate AuthenticateFunc) (interface{}, error)
// See ServerAuthenticator.GRPCUnaryServerInterceptor.
type GRPCUnaryInterceptorFunc func(ctx context.Context, req interface{}, info *grpc.UnaryServerInfo, handler grpc.UnaryHandler, authenticate AuthenticateFunc) (interface{}, error)

// GrpcStreamInterceptorFunc defines the signature for the function intercepting streaming gRPC calls, useful for authenticators to use as
// GRPCStreamInterceptorFunc defines the signature for the function intercepting streaming gRPC calls, useful for authenticators to use as
// types for internal structs, making it easier to mock them in tests.
// See ServerAuthenticator.GrpcStreamServerInterceptor.
type GrpcStreamInterceptorFunc func(srv interface{}, stream grpc.ServerStream, info *grpc.StreamServerInfo, handler grpc.StreamHandler, authenticate AuthenticateFunc) error
// See ServerAuthenticator.GRPCStreamServerInterceptor.
type GRPCStreamInterceptorFunc func(srv interface{}, stream grpc.ServerStream, info *grpc.StreamServerInfo, handler grpc.StreamHandler, authenticate AuthenticateFunc) error

// DefaultGrpcUnaryServerInterceptor provides a default implementation of GrpcUnaryInterceptorFunc, useful for most authenticators.
// DefaultGRPCUnaryServerInterceptor provides a default implementation of GRPCUnaryInterceptorFunc, useful for most authenticators.
// It extracts the headers from the incoming request, under the assumption that the credentials will be part of the resulting map.
func DefaultGrpcUnaryServerInterceptor(ctx context.Context, req interface{}, _ *grpc.UnaryServerInfo, handler grpc.UnaryHandler, authenticate AuthenticateFunc) (interface{}, error) {
func DefaultGRPCUnaryServerInterceptor(ctx context.Context, req interface{}, _ *grpc.UnaryServerInfo, handler grpc.UnaryHandler, authenticate AuthenticateFunc) (interface{}, error) {
headers, ok := metadata.FromIncomingContext(ctx)
if !ok {
return nil, errMetadataNotFound
Expand All @@ -86,9 +86,9 @@ func DefaultGrpcUnaryServerInterceptor(ctx context.Context, req interface{}, _ *
return handler(ctx, req)
}

// DefaultGrpcStreamServerInterceptor provides a default implementation of GrpcStreamInterceptorFunc, useful for most authenticators.
// DefaultGRPCStreamServerInterceptor provides a default implementation of GRPCStreamInterceptorFunc, useful for most authenticators.
// It extracts the headers from the incoming request, under the assumption that the credentials will be part of the resulting map.
func DefaultGrpcStreamServerInterceptor(srv interface{}, stream grpc.ServerStream, _ *grpc.StreamServerInfo, handler grpc.StreamHandler, authenticate AuthenticateFunc) error {
func DefaultGRPCStreamServerInterceptor(srv interface{}, stream grpc.ServerStream, _ *grpc.StreamServerInfo, handler grpc.StreamHandler, authenticate AuthenticateFunc) error {
ctx := stream.Context()
headers, ok := metadata.FromIncomingContext(ctx)
if !ok {
Expand Down
12 changes: 6 additions & 6 deletions config/configauth/serverauth_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ func TestDefaultUnaryInterceptorAuthSucceeded(t *testing.T) {
ctx := metadata.NewIncomingContext(context.Background(), metadata.Pairs("authorization", "some-auth-data"))

// test
res, err := DefaultGrpcUnaryServerInterceptor(ctx, nil, &grpc.UnaryServerInfo{}, handler, authFunc)
res, err := DefaultGRPCUnaryServerInterceptor(ctx, nil, &grpc.UnaryServerInfo{}, handler, authFunc)

// verify
assert.Nil(t, res)
Expand All @@ -63,7 +63,7 @@ func TestDefaultUnaryInterceptorAuthFailure(t *testing.T) {
ctx := metadata.NewIncomingContext(context.Background(), metadata.Pairs("authorization", "some-auth-data"))

// test
res, err := DefaultGrpcUnaryServerInterceptor(ctx, nil, &grpc.UnaryServerInfo{}, handler, authFunc)
res, err := DefaultGRPCUnaryServerInterceptor(ctx, nil, &grpc.UnaryServerInfo{}, handler, authFunc)

// verify
assert.Nil(t, res)
Expand All @@ -83,7 +83,7 @@ func TestDefaultUnaryInterceptorMissingMetadata(t *testing.T) {
}

// test
res, err := DefaultGrpcUnaryServerInterceptor(context.Background(), nil, &grpc.UnaryServerInfo{}, handler, authFunc)
res, err := DefaultGRPCUnaryServerInterceptor(context.Background(), nil, &grpc.UnaryServerInfo{}, handler, authFunc)

// verify
assert.Nil(t, res)
Expand All @@ -108,7 +108,7 @@ func TestDefaultStreamInterceptorAuthSucceeded(t *testing.T) {
}

// test
err := DefaultGrpcStreamServerInterceptor(nil, streamServer, &grpc.StreamServerInfo{}, handler, authFunc)
err := DefaultGRPCStreamServerInterceptor(nil, streamServer, &grpc.StreamServerInfo{}, handler, authFunc)

// verify
assert.NoError(t, err)
Expand All @@ -134,7 +134,7 @@ func TestDefaultStreamInterceptorAuthFailure(t *testing.T) {
}

// test
err := DefaultGrpcStreamServerInterceptor(nil, streamServer, &grpc.StreamServerInfo{}, handler, authFunc)
err := DefaultGRPCStreamServerInterceptor(nil, streamServer, &grpc.StreamServerInfo{}, handler, authFunc)

// verify
assert.Equal(t, expectedErr, err)
Expand All @@ -156,7 +156,7 @@ func TestDefaultStreamInterceptorMissingMetadata(t *testing.T) {
}

// test
err := DefaultGrpcStreamServerInterceptor(nil, streamServer, &grpc.StreamServerInfo{}, handler, authFunc)
err := DefaultGRPCStreamServerInterceptor(nil, streamServer, &grpc.StreamServerInfo{}, handler, authFunc)

// verify
assert.Equal(t, errMetadataNotFound, err)
Expand Down
8 changes: 4 additions & 4 deletions config/configgrpc/configgrpc.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ const (

var (
// Map of opentelemetry compression types to grpc registered compression types.
grpcCompressionKeyMap = map[string]string{
gRPCCompressionKeyMap = map[string]string{
CompressionGzip: gzip.Name,
}
)
Expand Down Expand Up @@ -311,8 +311,8 @@ func (gss *GRPCServerSettings) ToServerOption(ext map[config.ComponentID]compone
}

opts = append(opts,
grpc.UnaryInterceptor(authenticator.GrpcUnaryServerInterceptor),
grpc.StreamInterceptor(authenticator.GrpcStreamServerInterceptor),
grpc.UnaryInterceptor(authenticator.GRPCUnaryServerInterceptor),
grpc.StreamInterceptor(authenticator.GRPCStreamServerInterceptor),
)
}

Expand All @@ -327,7 +327,7 @@ func (gss *GRPCServerSettings) ToServerOption(ext map[config.ComponentID]compone
// passed in compression key is supported, and CompressionUnsupported otherwise.
func GetGRPCCompressionKey(compressionType string) string {
compressionKey := strings.ToLower(compressionType)
if encodingKey, ok := grpcCompressionKeyMap[compressionKey]; ok {
if encodingKey, ok := gRPCCompressionKeyMap[compressionKey]; ok {
return encodingKey
}
return CompressionUnsupported
Expand Down
16 changes: 8 additions & 8 deletions extension/oidcauthextension/extension.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,8 @@ import (

type oidcExtension struct {
cfg *Config
unaryInterceptor configauth.GrpcUnaryInterceptorFunc
streamInterceptor configauth.GrpcStreamInterceptorFunc
unaryInterceptor configauth.GRPCUnaryInterceptorFunc
streamInterceptor configauth.GRPCStreamInterceptorFunc

provider *oidc.Provider
verifier *oidc.IDTokenVerifier
Expand Down Expand Up @@ -75,8 +75,8 @@ func newExtension(cfg *Config, logger *zap.Logger) (*oidcExtension, error) {
return &oidcExtension{
cfg: cfg,
logger: logger,
unaryInterceptor: configauth.DefaultGrpcUnaryServerInterceptor,
streamInterceptor: configauth.DefaultGrpcStreamServerInterceptor,
unaryInterceptor: configauth.DefaultGRPCUnaryServerInterceptor,
streamInterceptor: configauth.DefaultGRPCStreamServerInterceptor,
}, nil
}

Expand Down Expand Up @@ -141,13 +141,13 @@ func (e *oidcExtension) Authenticate(ctx context.Context, headers map[string][]s
return nil
}

// GrpcUnaryServerInterceptor is a helper method to provide a gRPC-compatible UnaryInterceptor, typically calling the authenticator's Authenticate method.
func (e *oidcExtension) GrpcUnaryServerInterceptor(ctx context.Context, req interface{}, info *grpc.UnaryServerInfo, handler grpc.UnaryHandler) (interface{}, error) {
// GRPCUnaryServerInterceptor is a helper method to provide a gRPC-compatible UnaryInterceptor, typically calling the authenticator's Authenticate method.
func (e *oidcExtension) GRPCUnaryServerInterceptor(ctx context.Context, req interface{}, info *grpc.UnaryServerInfo, handler grpc.UnaryHandler) (interface{}, error) {
return e.unaryInterceptor(ctx, req, info, handler, e.Authenticate)
}

// GrpcStreamServerInterceptor is a helper method to provide a gRPC-compatible StreamInterceptor, typically calling the authenticator's Authenticate method.
func (e *oidcExtension) GrpcStreamServerInterceptor(srv interface{}, str grpc.ServerStream, info *grpc.StreamServerInfo, handler grpc.StreamHandler) error {
// GRPCStreamServerInterceptor is a helper method to provide a gRPC-compatible StreamInterceptor, typically calling the authenticator's Authenticate method.
func (e *oidcExtension) GRPCStreamServerInterceptor(srv interface{}, str grpc.ServerStream, info *grpc.StreamServerInfo, handler grpc.StreamHandler) error {
return e.streamInterceptor(srv, str, info, handler, e.Authenticate)
}

Expand Down
4 changes: 2 additions & 2 deletions extension/oidcauthextension/extension_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -475,7 +475,7 @@ func TestUnaryInterceptor(t *testing.T) {
}

// test
res, err := p.GrpcUnaryServerInterceptor(context.Background(), nil, &grpc.UnaryServerInfo{}, handler)
res, err := p.GRPCUnaryServerInterceptor(context.Background(), nil, &grpc.UnaryServerInfo{}, handler)

// verify
assert.NoError(t, err)
Expand Down Expand Up @@ -506,7 +506,7 @@ func TestStreamInterceptor(t *testing.T) {
}

// test
err = p.GrpcStreamServerInterceptor(nil, streamServer, &grpc.StreamServerInfo{}, handler)
err = p.GRPCStreamServerInterceptor(nil, streamServer, &grpc.StreamServerInfo{}, handler)

// verify
assert.NoError(t, err)
Expand Down