diff --git a/.chloggen/mx-psi_deprecate-func-methods.yaml b/.chloggen/mx-psi_deprecate-func-methods.yaml new file mode 100644 index 00000000000..90908efe992 --- /dev/null +++ b/.chloggen/mx-psi_deprecate-func-methods.yaml @@ -0,0 +1,25 @@ +# Use this changelog template to create an entry for release notes. + +# One of 'breaking', 'deprecation', 'new_component', 'enhancement', 'bug_fix' +change_type: deprecation + +# The name of the component, or a single word describing the area of concern, (e.g. otlpreceiver) +component: extension/extensionauth + +# A brief description of the change. Surround your text with quotes ("") if it needs to start with a backtick (`). +note: Deprecate methods on `*Func` types. + +# One or more tracking issues or pull requests related to the change +issues: [12480] + +# (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: + +# 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] diff --git a/extension/extensionauth/client.go b/extension/extensionauth/client.go index 2ea8653cc23..a303082cb3d 100644 --- a/extension/extensionauth/client.go +++ b/extension/extensionauth/client.go @@ -39,6 +39,7 @@ func (of clientOptionFunc) apply(e *defaultClient) { // ClientRoundTripperFunc specifies the function that returns a RoundTripper that can be used to authenticate HTTP requests. type ClientRoundTripperFunc func(base http.RoundTripper) (http.RoundTripper, error) +// Deprecated: [v0.121.0] No longer used, will be removed. func (f ClientRoundTripperFunc) RoundTripper(base http.RoundTripper) (http.RoundTripper, error) { if f == nil { return base, nil @@ -49,6 +50,7 @@ func (f ClientRoundTripperFunc) RoundTripper(base http.RoundTripper) (http.Round // ClientPerRPCCredentialsFunc specifies the function that returns a PerRPCCredentials that can be used to authenticate gRPC requests. type ClientPerRPCCredentialsFunc func() (credentials.PerRPCCredentials, error) +// Deprecated: [v0.121.0] No longer used, will be removed. func (f ClientPerRPCCredentialsFunc) PerRPCCredentials() (credentials.PerRPCCredentials, error) { if f == nil { return nil, nil @@ -56,11 +58,29 @@ func (f ClientPerRPCCredentialsFunc) PerRPCCredentials() (credentials.PerRPCCred return f() } +var _ Client = (*defaultClient)(nil) + type defaultClient struct { component.StartFunc component.ShutdownFunc - ClientRoundTripperFunc - ClientPerRPCCredentialsFunc + 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. @@ -83,7 +103,7 @@ func WithClientShutdown(shutdownFunc component.ShutdownFunc) ClientOption { // The default round tripper is no-op. func WithClientRoundTripper(roundTripperFunc ClientRoundTripperFunc) ClientOption { return clientOptionFunc(func(o *defaultClient) { - o.ClientRoundTripperFunc = roundTripperFunc + o.clientRoundTripperFunc = roundTripperFunc }) } @@ -91,7 +111,7 @@ func WithClientRoundTripper(roundTripperFunc ClientRoundTripperFunc) ClientOptio // There's no default. func WithClientPerRPCCredentials(perRPCCredentialsFunc ClientPerRPCCredentialsFunc) ClientOption { return clientOptionFunc(func(o *defaultClient) { - o.ClientPerRPCCredentialsFunc = perRPCCredentialsFunc + o.clientPerRPCCredentialsFunc = perRPCCredentialsFunc }) } diff --git a/extension/extensionauth/server.go b/extension/extensionauth/server.go index b9055ee94b1..d5fc2dcd50b 100644 --- a/extension/extensionauth/server.go +++ b/extension/extensionauth/server.go @@ -29,12 +29,22 @@ type Server interface { Authenticate(ctx context.Context, sources map[string][]string) (context.Context, error) } +var _ Server = (*defaultServer)(nil) + type defaultServer struct { - ServerAuthenticateFunc + serverAuthenticateFunc ServerAuthenticateFunc component.StartFunc component.ShutdownFunc } +// Authenticate implements Server. +func (d *defaultServer) Authenticate(ctx context.Context, sources map[string][]string) (context.Context, error) { + if d.serverAuthenticateFunc == nil { + return ctx, nil + } + return d.serverAuthenticateFunc(ctx, sources) +} + // ServerOption represents the possible options for NewServer. type ServerOption interface { apply(*defaultServer) @@ -50,6 +60,7 @@ func (of serverOptionFunc) apply(e *defaultServer) { // on the given sources map. See Server.Authenticate. type ServerAuthenticateFunc func(ctx context.Context, sources map[string][]string) (context.Context, error) +// Deprecated: [v0.121.0] No longer used, will be removed. func (f ServerAuthenticateFunc) Authenticate(ctx context.Context, sources map[string][]string) (context.Context, error) { if f == nil { return ctx, nil @@ -60,7 +71,7 @@ func (f ServerAuthenticateFunc) Authenticate(ctx context.Context, sources map[st // WithServerAuthenticate specifies which function to use to perform the authentication. func WithServerAuthenticate(authFunc ServerAuthenticateFunc) ServerOption { return serverOptionFunc(func(o *defaultServer) { - o.ServerAuthenticateFunc = authFunc + o.serverAuthenticateFunc = authFunc }) }