Skip to content

Commit

Permalink
[chore] nits in configauth package, use non deprecated, update commen…
Browse files Browse the repository at this point in the history
…ts (#6639)

Signed-off-by: Bogdan Drutu <[email protected]>
  • Loading branch information
bogdandrutu authored Dec 1, 2022
1 parent b5a9d6c commit 8cd99b3
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 29 deletions.
17 changes: 9 additions & 8 deletions config/configauth/configauth.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import (
"fmt"

"go.opentelemetry.io/collector/component"
"go.opentelemetry.io/collector/extension/auth"
)

var (
Expand All @@ -33,26 +34,26 @@ type Authentication struct {
AuthenticatorID component.ID `mapstructure:"authenticator"`
}

// GetServerAuthenticator attempts to select the appropriate ServerAuthenticator from the list of extensions,
// GetServerAuthenticator attempts to select the appropriate auth.Server from the list of extensions,
// based on the requested extension name. If an authenticator is not found, an error is returned.
func (a Authentication) GetServerAuthenticator(extensions map[component.ID]component.Component) (ServerAuthenticator, error) {
func (a Authentication) GetServerAuthenticator(extensions map[component.ID]component.Component) (auth.Server, error) {
if ext, found := extensions[a.AuthenticatorID]; found {
if auth, ok := ext.(ServerAuthenticator); ok {
return auth, nil
if server, ok := ext.(auth.Server); ok {
return server, nil
}
return nil, errNotServer
}

return nil, fmt.Errorf("failed to resolve authenticator %q: %w", a.AuthenticatorID, errAuthenticatorNotFound)
}

// GetClientAuthenticator attempts to select the appropriate ClientAuthenticator from the list of extensions,
// GetClientAuthenticator attempts to select the appropriate auth.Client from the list of extensions,
// based on the component id of the extension. If an authenticator is not found, an error is returned.
// This should be only used by HTTP clients.
func (a Authentication) GetClientAuthenticator(extensions map[component.ID]component.Component) (ClientAuthenticator, error) {
func (a Authentication) GetClientAuthenticator(extensions map[component.ID]component.Component) (auth.Client, error) {
if ext, found := extensions[a.AuthenticatorID]; found {
if auth, ok := ext.(ClientAuthenticator); ok {
return auth, nil
if client, ok := ext.(auth.Client); ok {
return client, nil
}
return nil, errNotClient
}
Expand Down
9 changes: 5 additions & 4 deletions config/configauth/configauth_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import (
"github.com/stretchr/testify/assert"

"go.opentelemetry.io/collector/component"
"go.opentelemetry.io/collector/extension/auth"
)

func TestGetServer(t *testing.T) {
Expand All @@ -30,12 +31,12 @@ func TestGetServer(t *testing.T) {
}{
{
desc: "obtain server authenticator",
authenticator: NewServerAuthenticator(),
authenticator: auth.NewServer(),
expected: nil,
},
{
desc: "not a server authenticator",
authenticator: NewClientAuthenticator(),
authenticator: auth.NewClient(),
expected: errNotServer,
},
}
Expand Down Expand Up @@ -81,12 +82,12 @@ func TestGetClient(t *testing.T) {
}{
{
desc: "obtain client authenticator",
authenticator: NewClientAuthenticator(),
authenticator: auth.NewClient(),
expected: nil,
},
{
desc: "not a client authenticator",
authenticator: NewServerAuthenticator(),
authenticator: auth.NewServer(),
expected: errNotClient,
},
}
Expand Down
17 changes: 0 additions & 17 deletions config/configauth/deprecated.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,31 +22,21 @@ import (
// Deprecated: [v0.67.0] Use auth.Client
type ClientAuthenticator = auth.Client

// Option represents the possible options for NewServerAuthenticator.
// Deprecated: [v0.67.0] Use auth.ClientOption
type ClientOption = auth.ClientOption

// WithClientStart overrides the default `Start` function for a component.Component.
// The default always returns nil.
// Deprecated: [v0.67.0] Use auth.WithClientStart
var WithClientStart = auth.WithClientStart

// WithClientShutdown overrides the default `Shutdown` function for a component.Component.
// The default always returns nil.
// Deprecated: [v0.67.0] Use auth.WithClientShutdown
var WithClientShutdown = auth.WithClientShutdown

// WithClientRoundTripper provides a `RoundTripper` function for this client authenticator.
// The default round tripper is no-op.
// Deprecated: [v0.67.0] Use auth.WithClientRoundTripper
var WithClientRoundTripper = auth.WithClientRoundTripper

// WithPerRPCCredentials provides a `PerRPCCredentials` function for this client authenticator.
// There's no default.
// Deprecated: [v0.67.0] Use auth.WithPerRPCCredentials
var WithPerRPCCredentials = auth.WithPerRPCCredentials

// NewClientAuthenticator returns a ClientAuthenticator configured with the provided options.
// Deprecated: [v0.67.0] Use auth.NewClient
var NewClientAuthenticator = auth.NewClient

Expand All @@ -56,25 +46,18 @@ type ServerAuthenticator = auth.Server
// Deprecated: [v0.67.0] Use auth.AuthenticateFunc
type AuthenticateFunc = auth.AuthenticateFunc

// Option represents the possible options for NewServerAuthenticator.
// Deprecated: [v0.67.0] Use auth.Option
type Option = auth.Option

// WithAuthenticate specifies which function to use to perform the authentication.
// Deprecated: [v0.67.0] Use auth.WithAuthenticate
var WithAuthenticate = auth.WithAuthenticate

// WithStart overrides the default `Start` function for a component.Component.
// The default always returns nil.
// Deprecated: [v0.67.0] Use auth.WithStart
var WithStart = auth.WithStart

// WithShutdown overrides the default `Shutdown` function for a component.Component.
// The default always returns nil.
// Deprecated: [v0.67.0] Use auth.WithShutdown
var WithShutdown = auth.WithShutdown

// NewServerAuthenticator returns a ServerAuthenticator configured with the provided options.
// Deprecated: [v0.67.0] Use auth.NewServer
var NewServerAuthenticator = auth.NewServer

Expand Down

0 comments on commit 8cd99b3

Please sign in to comment.