Skip to content
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
25 changes: 25 additions & 0 deletions .chloggen/mx-psi_deprecate-func-methods.yaml
Original file line number Diff line number Diff line change
@@ -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]
28 changes: 24 additions & 4 deletions extension/extensionauth/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -49,18 +50,37 @@ 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
}
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.
Expand All @@ -83,15 +103,15 @@ 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
})
}

// WithClientPerRPCCredentials provides a `PerRPCCredentials` function for this client authenticator.
// There's no default.
func WithClientPerRPCCredentials(perRPCCredentialsFunc ClientPerRPCCredentialsFunc) ClientOption {
return clientOptionFunc(func(o *defaultClient) {
o.ClientPerRPCCredentialsFunc = perRPCCredentialsFunc
o.clientPerRPCCredentialsFunc = perRPCCredentialsFunc
})
}

Expand Down
15 changes: 13 additions & 2 deletions extension/extensionauth/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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
Expand All @@ -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
})
}

Expand Down