Skip to content

[extensionauth,configauth] Remove deprecated symbols #12672

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

Merged
merged 2 commits into from
Mar 19, 2025
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
31 changes: 31 additions & 0 deletions .chloggen/mx-psi_remove-deprecated-stuff.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
# Use this changelog template to create an entry for release notes.

# One of 'breaking', 'deprecation', 'new_component', 'enhancement', 'bug_fix'
change_type: breaking

# The name of the component, or a single word describing the area of concern, (e.g. otlpreceiver)
component: extensionauth, configauth

# A brief description of the change. Surround your text with quotes ("") if it needs to start with a backtick (`).
note: Remove deprecated types and functions from `extensionauth` and `configauth` packages.

# One or more tracking issues or pull requests related to the change
issues: [12672]

# (Optional) One or more lines of additional information to render under the primary note.
# These lines will be padded with 2 spaces and then inserted directly into the document.
# Use pipe (|) for multiline entries.
subtext: |
This includes:
- `extensionauth.NewClient`,
- `extensionauth.ClientOption` and all its implementations,
- `extensionauth.NewServer`,
- `extensionauth.ServerOption` and all its implementations and
- `configauth.Authenticator.GetClientAuthenticator`.

# Optional: The change log or logs in which this entry should be included.
# e.g. '[user]' or '[user, api]'
# Include 'user' if the change is relevant to end users.
# Include 'api' if there is a change to a library API.
# Default: '[user]'
change_logs: [api]
14 changes: 0 additions & 14 deletions config/configauth/configauth.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ import (

var (
errAuthenticatorNotFound = errors.New("authenticator not found")
errNotClient = errors.New("requested authenticator is not a client authenticator")
errNotHTTPClient = errors.New("requested authenticator is not a HTTP client authenticator")
errNotGRPCClient = errors.New("requested authenticator is not a gRPC client authenticator")
errNotServer = errors.New("requested authenticator is not a server authenticator")
Expand All @@ -42,19 +41,6 @@ func (a Authentication) GetServerAuthenticator(_ context.Context, extensions map
return nil, fmt.Errorf("failed to resolve authenticator %q: %w", a.AuthenticatorID, errAuthenticatorNotFound)
}

// GetClientAuthenticator attempts to select the appropriate extensionauth.Client from the list of extensions,
// based on the component id of the extension. If an authenticator is not found, an error is returned.
// Deprecated: [v0.122.0] Use GetHTTPClientAuthenticator or GetGRPCClientAuthenticator instead.
func (a Authentication) GetClientAuthenticator(_ context.Context, extensions map[component.ID]component.Component) (extensionauth.Client, error) {
if ext, found := extensions[a.AuthenticatorID]; found {
if client, ok := ext.(extensionauth.Client); ok {
return client, nil
}
return nil, errNotClient
}
return nil, fmt.Errorf("failed to resolve authenticator %q: %w", a.AuthenticatorID, errAuthenticatorNotFound)
}

// GetHTTPClientAuthenticator attempts to select the appropriate extensionauth.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.
Expand Down
4 changes: 2 additions & 2 deletions config/configauth/configauth_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ func TestGetServerFails(t *testing.T) {
assert.Nil(t, authenticator)
}

func TestGetClient(t *testing.T) {
func TestGetHTTPClient(t *testing.T) {
testCases := []struct {
name string
authenticator extension.Extension
Expand Down Expand Up @@ -109,7 +109,7 @@ func TestGetClient(t *testing.T) {
}
}

func TestGetClientFails(t *testing.T) {
func TestGetGRPCClientFails(t *testing.T) {
cfg := &Authentication{
AuthenticatorID: component.MustNewID("does_not_exist"),
}
Expand Down
2 changes: 0 additions & 2 deletions config/configauth/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,6 @@ replace go.opentelemetry.io/collector/pdata => ../../pdata

replace go.opentelemetry.io/collector/component => ../../component

replace go.opentelemetry.io/collector/component/componenttest => ../../component/componenttest

replace go.opentelemetry.io/collector/extension => ../../extension

replace go.opentelemetry.io/collector/extension/extensionauth => ../../extension/extensionauth
Expand Down
12 changes: 6 additions & 6 deletions config/configauth/go.sum

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion config/confighttp/confighttp_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ type mockAuthServer struct {
extensionauth.ServerAuthenticateFunc
}

func newMockAuthServer(auth func(ctx context.Context, sources map[string][]string) (context.Context, error)) extensionauth.Server {
func newMockAuthServer(auth func(ctx context.Context, sources map[string][]string) (context.Context, error)) extension.Extension {
return &mockAuthServer{ServerAuthenticateFunc: auth}
}

Expand Down
1 change: 0 additions & 1 deletion config/confighttp/xconfighttp/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ require (
go.opentelemetry.io/collector/config/configcompression v1.28.1 // indirect
go.opentelemetry.io/collector/config/configopaque v1.28.1 // indirect
go.opentelemetry.io/collector/config/configtls v1.28.1 // indirect
go.opentelemetry.io/collector/extension v1.28.1 // indirect
go.opentelemetry.io/collector/extension/extensionauth v0.122.1 // indirect
go.opentelemetry.io/collector/pdata v1.28.1 // indirect
go.opentelemetry.io/otel v1.35.0 // indirect
Expand Down
99 changes: 0 additions & 99 deletions extension/extensionauth/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,21 +7,8 @@ import (
"net/http"

"google.golang.org/grpc/credentials"

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

// Client is an optional Extension interface that can be used as an HTTP and gRPC 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.
// Deprecated: [v0.122.0] Assert the use of HTTPClient and GRPCClient interfaces instead.
type Client interface {
extension.Extension
HTTPClient
GRPCClient
}

// HTTPClient is an optional Extension interface that can be used as an HTTP 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.
Expand All @@ -38,18 +25,6 @@ type GRPCClient interface {
PerRPCCredentials() (credentials.PerRPCCredentials, error)
}

// ClientOption represents the possible options for NewClient.
// Deprecated: [v0.122.0] This type is deprecated and will be removed in the next release.
type ClientOption interface {
apply(*defaultClient)
}

type clientOptionFunc func(*defaultClient)

func (of clientOptionFunc) apply(e *defaultClient) {
of(e)
}

var _ HTTPClient = (*ClientRoundTripperFunc)(nil)

// ClientRoundTripperFunc specifies the function that returns a RoundTripper that can be used to authenticate HTTP requests.
Expand All @@ -73,77 +48,3 @@ func (f ClientPerRPCCredentialsFunc) PerRPCCredentials() (credentials.PerRPCCred
}
return f()
}

var _ Client = (*defaultClient)(nil)

type defaultClient struct {
component.StartFunc
component.ShutdownFunc
clientRoundTripperFunc ClientRoundTripperFunc
clientPerRPCCredentialsFunc ClientPerRPCCredentialsFunc
}

// PerRPCCredentials implements Client.
func (d *defaultClient) PerRPCCredentials() (credentials.PerRPCCredentials, error) {
if d.clientPerRPCCredentialsFunc == nil {
return nil, nil
}
return d.clientPerRPCCredentialsFunc()
}

// RoundTripper implements Client.
func (d *defaultClient) RoundTripper(base http.RoundTripper) (http.RoundTripper, error) {
if d.clientRoundTripperFunc == nil {
return base, nil
}
return d.clientRoundTripperFunc(base)
}

// WithClientStart overrides the default `Start` function for a component.Component.
// The default always returns nil.
// Deprecated: [v0.122.0] This type is deprecated and will be removed in the next release.
func WithClientStart(startFunc component.StartFunc) ClientOption {
return clientOptionFunc(func(o *defaultClient) {
o.StartFunc = startFunc
})
}

// WithClientShutdown overrides the default `Shutdown` function for a component.Component.
// The default always returns nil.
// Deprecated: [v0.122.0] This type is deprecated and will be removed in the next release.
func WithClientShutdown(shutdownFunc component.ShutdownFunc) ClientOption {
return clientOptionFunc(func(o *defaultClient) {
o.ShutdownFunc = shutdownFunc
})
}

// WithClientRoundTripper provides a `RoundTripper` function for this client authenticator.
// The default round tripper is no-op.
// Deprecated: [v0.122.0] This type is deprecated and will be removed in the next release.
func WithClientRoundTripper(roundTripperFunc ClientRoundTripperFunc) ClientOption {
return clientOptionFunc(func(o *defaultClient) {
o.clientRoundTripperFunc = roundTripperFunc
})
}

// WithClientPerRPCCredentials provides a `PerRPCCredentials` function for this client authenticator.
// There's no default.
// Deprecated: [v0.122.0] This type is deprecated and will be removed in the next release.
func WithClientPerRPCCredentials(perRPCCredentialsFunc ClientPerRPCCredentialsFunc) ClientOption {
return clientOptionFunc(func(o *defaultClient) {
o.clientPerRPCCredentialsFunc = perRPCCredentialsFunc
})
}

// NewClient returns a Client configured with the provided options.
// Deprecated: [v0.122.0] This type is deprecated and will be removed in the next release.
// Manually implement the [HTTPClient] and/or [GRPCClient] interfaces instead.
func NewClient(options ...ClientOption) (Client, error) {
bc := &defaultClient{}

for _, op := range options {
op.apply(bc)
}

return bc, nil
}
100 changes: 14 additions & 86 deletions extension/extensionauth/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,87 +11,19 @@ import (
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"google.golang.org/grpc/credentials"

"go.opentelemetry.io/collector/component"
"go.opentelemetry.io/collector/component/componenttest"
)

func TestClientDefaultValues(t *testing.T) {
// prepare
e, err := NewClient()
require.NoError(t, err)

// test
t.Run("start", func(t *testing.T) {
err := e.Start(context.Background(), componenttest.NewNopHost())
assert.NoError(t, err)
})

t.Run("roundtripper", func(t *testing.T) {
ctx, err := e.RoundTripper(http.DefaultTransport)
assert.NotNil(t, ctx)
assert.NoError(t, err)
})

t.Run("per-rpc-credentials", func(t *testing.T) {
p, err := e.PerRPCCredentials()
assert.Nil(t, p)
assert.NoError(t, err)
})

t.Run("shutdown", func(t *testing.T) {
err := e.Shutdown(context.Background())
assert.NoError(t, err)
})
}

func TestWithClientStart(t *testing.T) {
called := false
e, err := NewClient(WithClientStart(func(context.Context, component.Host) error {
called = true
return nil
}))
require.NoError(t, err)

// test
err = e.Start(context.Background(), componenttest.NewNopHost())

// verify
assert.True(t, called)
assert.NoError(t, err)
}

func TestWithClientShutdown(t *testing.T) {
called := false
e, err := NewClient(WithClientShutdown(func(context.Context) error {
called = true
return nil
}))
require.NoError(t, err)

// test
err = e.Shutdown(context.Background())

// verify
assert.True(t, called)
assert.NoError(t, err)
}

func TestWithClientRoundTripper(t *testing.T) {
called := false
e, err := NewClient(WithClientRoundTripper(func(base http.RoundTripper) (http.RoundTripper, error) {
func TestRoundTripperFunc(t *testing.T) {
var called bool
var httpClient HTTPClient = ClientRoundTripperFunc(func(base http.RoundTripper) (http.RoundTripper, error) {
called = true
return base, nil
}))
require.NoError(t, err)

// test
rt, err := e.RoundTripper(http.DefaultTransport)
})

// verify
rt, err := httpClient.RoundTripper(http.DefaultTransport)
require.NoError(t, err)
assert.True(t, called)
assert.NotNil(t, rt)
assert.NoError(t, err)
assert.Equal(t, http.DefaultTransport, rt)
}

type customPerRPCCredentials struct{}
Expand All @@ -106,19 +38,15 @@ func (c *customPerRPCCredentials) RequireTransportSecurity() bool {
return true
}

func TestWithPerRPCCredentials(t *testing.T) {
called := false
e, err := NewClient(WithClientPerRPCCredentials(func() (credentials.PerRPCCredentials, error) {
func TestWithPerRPCCredentialsFunc(t *testing.T) {
var called bool
var grpcClient GRPCClient = ClientPerRPCCredentialsFunc(func() (credentials.PerRPCCredentials, error) {
called = true
return &customPerRPCCredentials{}, nil
}))
require.NoError(t, err)

// test
p, err := e.PerRPCCredentials()
})

// verify
creds, err := grpcClient.PerRPCCredentials()
require.NoError(t, err)
assert.True(t, called)
assert.NotNil(t, p)
assert.NoError(t, err)
assert.NotNil(t, creds)
}
2 changes: 0 additions & 2 deletions extension/extensionauth/extensionauthtest/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -36,5 +36,3 @@ replace go.opentelemetry.io/collector/component => ../../../component
replace go.opentelemetry.io/collector/pdata => ../../../pdata

replace go.opentelemetry.io/collector/extension => ../..

replace go.opentelemetry.io/collector/component/componenttest => ../../../component/componenttest
Loading
Loading