diff --git a/config/configauth/mock_serverauth.go b/config/configauth/mock_serverauth.go index 1f5ead65906..cd11c34f74d 100644 --- a/config/configauth/mock_serverauth.go +++ b/config/configauth/mock_serverauth.go @@ -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 } diff --git a/config/configauth/mock_serverauth_test.go b/config/configauth/mock_serverauth_test.go index 4854febf9aa..c22852862b0 100644 --- a/config/configauth/mock_serverauth_test.go +++ b/config/configauth/mock_serverauth_test.go @@ -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) } diff --git a/config/configauth/serverauth.go b/config/configauth/serverauth.go index c56abb67cdc..c2c90102444 100644 --- a/config/configauth/serverauth.go +++ b/config/configauth/serverauth.go @@ -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 @@ -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 { diff --git a/config/configauth/serverauth_test.go b/config/configauth/serverauth_test.go index e05b68047b4..d8314973730 100644 --- a/config/configauth/serverauth_test.go +++ b/config/configauth/serverauth_test.go @@ -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) @@ -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) @@ -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) @@ -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) @@ -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) @@ -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) diff --git a/config/configgrpc/configgrpc.go b/config/configgrpc/configgrpc.go index 2d668978ee9..424e69a9bb9 100644 --- a/config/configgrpc/configgrpc.go +++ b/config/configgrpc/configgrpc.go @@ -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, } ) @@ -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), ) } @@ -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 diff --git a/extension/oidcauthextension/extension.go b/extension/oidcauthextension/extension.go index 60e2cc55def..59d314892d9 100644 --- a/extension/oidcauthextension/extension.go +++ b/extension/oidcauthextension/extension.go @@ -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 @@ -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 } @@ -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) } diff --git a/extension/oidcauthextension/extension_test.go b/extension/oidcauthextension/extension_test.go index d01fd0c7a84..da791366663 100644 --- a/extension/oidcauthextension/extension_test.go +++ b/extension/oidcauthextension/extension_test.go @@ -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) @@ -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)