From 55cc3e90f4cbe2ed69bb0e830ff53167a1afdd4d Mon Sep 17 00:00:00 2001 From: Bogdan Drutu Date: Mon, 5 Dec 2022 12:08:46 -0800 Subject: [PATCH] [chore] combine auth files, rename old names related to authentificator (#6666) Signed-off-by: Bogdan Drutu Signed-off-by: Bogdan Drutu --- ...fault_clientauthenticator.go => client.go} | 14 ++++++- ...ntauthenticator_test.go => client_test.go} | 0 extension/auth/clientauth.go | 36 ----------------- ...fault_serverauthenticator.go => server.go} | 20 +++++++++- ...erauthenticator_test.go => server_test.go} | 0 extension/auth/serverauth.go | 40 ------------------- 6 files changed, 32 insertions(+), 78 deletions(-) rename extension/auth/{default_clientauthenticator.go => client.go} (82%) rename extension/auth/{default_clientauthenticator_test.go => client_test.go} (100%) delete mode 100644 extension/auth/clientauth.go rename extension/auth/{default_serverauthenticator.go => server.go} (57%) rename extension/auth/{default_serverauthenticator_test.go => server_test.go} (100%) delete mode 100644 extension/auth/serverauth.go diff --git a/extension/auth/default_clientauthenticator.go b/extension/auth/client.go similarity index 82% rename from extension/auth/default_clientauthenticator.go rename to extension/auth/client.go index fa46fac1020e..54fc8083fbf0 100644 --- a/extension/auth/default_clientauthenticator.go +++ b/extension/auth/client.go @@ -20,9 +20,21 @@ import ( "google.golang.org/grpc/credentials" "go.opentelemetry.io/collector/component" + "go.opentelemetry.io/collector/extension" ) -var _ Client = (*defaultClient)(nil) +// Client is an Extension that can be used as an authenticator for the configauth.Authentication option. +// Authenticators are then included as part of OpenTelemetry Collector builds and can be referenced by their +// names from the Authentication configuration. +type Client interface { + extension.Extension + + // RoundTripper returns a RoundTripper that can be used to authenticate HTTP requests. + RoundTripper(base http.RoundTripper) (http.RoundTripper, error) + + // PerRPCCredentials returns a PerRPCCredentials that can be used to authenticate gRPC requests. + PerRPCCredentials() (credentials.PerRPCCredentials, error) +} // ClientOption represents the possible options for NewServerAuthenticator. type ClientOption func(*defaultClient) diff --git a/extension/auth/default_clientauthenticator_test.go b/extension/auth/client_test.go similarity index 100% rename from extension/auth/default_clientauthenticator_test.go rename to extension/auth/client_test.go diff --git a/extension/auth/clientauth.go b/extension/auth/clientauth.go deleted file mode 100644 index 65b337b321f4..000000000000 --- a/extension/auth/clientauth.go +++ /dev/null @@ -1,36 +0,0 @@ -// Copyright The OpenTelemetry Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package auth // import "go.opentelemetry.io/collector/extension/auth" - -import ( - "net/http" - - "google.golang.org/grpc/credentials" - - "go.opentelemetry.io/collector/extension" -) - -// Client is an Extension that can be used as an authenticator for the configauth.Authentication option. -// Authenticators are then included as part of OpenTelemetry Collector builds and can be referenced by their -// names from the Authentication configuration. -type Client interface { - extension.Extension - - // RoundTripper returns a RoundTripper that can be used to authenticate HTTP requests. - RoundTripper(base http.RoundTripper) (http.RoundTripper, error) - - // PerRPCCredentials returns a PerRPCCredentials that can be used to authenticate gRPC requests. - PerRPCCredentials() (credentials.PerRPCCredentials, error) -} diff --git a/extension/auth/default_serverauthenticator.go b/extension/auth/server.go similarity index 57% rename from extension/auth/default_serverauthenticator.go rename to extension/auth/server.go index 13305939f8b8..394f3fb5e0f7 100644 --- a/extension/auth/default_serverauthenticator.go +++ b/extension/auth/server.go @@ -18,9 +18,27 @@ import ( "context" "go.opentelemetry.io/collector/component" + "go.opentelemetry.io/collector/extension" ) -var _ Server = (*defaultServer)(nil) +// Server is an Extension that can be used as an authenticator for the configauth.Authentication option. +// Authenticators are then included as part of OpenTelemetry Collector builds and can be referenced by their +// names from the Authentication configuration. Each Server is free to define its own behavior and configuration options, +// but note that the expectations that come as part of Extensions exist here as well. For instance, multiple instances of the same +// authenticator should be possible to exist under different names. +type Server interface { + extension.Extension + + // Authenticate checks whether the given headers map contains valid auth data. Successfully authenticated calls will always return a nil error. + // When the authentication fails, an error must be returned and the caller must not retry. This function is typically called from interceptors, + // on behalf of receivers, but receivers can still call this directly if the usage of interceptors isn't suitable. + // 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. + // The resulting context should contain the authentication data, such as the principal/username, group membership (if available), and the raw + // authentication data (if possible). This will allow other components in the pipeline to make decisions based on that data, such as routing based + // on tenancy as determined by the group membership, or passing through the authentication data to the next collector/backend. + // The context keys to be used are not defined yet. + Authenticate(ctx context.Context, headers map[string][]string) (context.Context, error) +} type defaultServer struct { ServerAuthenticateFunc diff --git a/extension/auth/default_serverauthenticator_test.go b/extension/auth/server_test.go similarity index 100% rename from extension/auth/default_serverauthenticator_test.go rename to extension/auth/server_test.go diff --git a/extension/auth/serverauth.go b/extension/auth/serverauth.go deleted file mode 100644 index bc5fa2bb9c6d..000000000000 --- a/extension/auth/serverauth.go +++ /dev/null @@ -1,40 +0,0 @@ -// Copyright The OpenTelemetry Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package auth // import "go.opentelemetry.io/collector/extension/auth" - -import ( - "context" - - "go.opentelemetry.io/collector/extension" -) - -// Server is an Extension that can be used as an authenticator for the configauth.Authentication option. -// Authenticators are then included as part of OpenTelemetry Collector builds and can be referenced by their -// names from the Authentication configuration. Each Server is free to define its own behavior and configuration options, -// but note that the expectations that come as part of Extensions exist here as well. For instance, multiple instances of the same -// authenticator should be possible to exist under different names. -type Server interface { - extension.Extension - - // Authenticate checks whether the given headers map contains valid auth data. Successfully authenticated calls will always return a nil error. - // When the authentication fails, an error must be returned and the caller must not retry. This function is typically called from interceptors, - // on behalf of receivers, but receivers can still call this directly if the usage of interceptors isn't suitable. - // 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. - // The resulting context should contain the authentication data, such as the principal/username, group membership (if available), and the raw - // authentication data (if possible). This will allow other components in the pipeline to make decisions based on that data, such as routing based - // on tenancy as determined by the group membership, or passing through the authentication data to the next collector/backend. - // The context keys to be used are not defined yet. - Authenticate(ctx context.Context, headers map[string][]string) (context.Context, error) -}