Skip to content

Commit 491a856

Browse files
Schm1tz1AkshayS198
authored andcommitted
[extension/oauth2clientauthextension] Allow exporting of OAuth extension to re-use it in other components, required for open-telemetry#39248 (open-telemetry#39514)
<!--Ex. Fixing a bug - Describe the bug and how this fixes the issue. Ex. Adding a feature - Explain what this achieves.--> #### Description As discussed in issue open-telemetry#39248 - generic OAuth support for kafka exporter (to be extended/applied for receiver also). This is only for exporting the OAuth class so we can re-use it. Only internal references changed as it was not imported up to now. Created as a separate PR (suggestion by @atoulme in PR open-telemetry#39482). <!-- Issue number (e.g. open-telemetry#1234) or full URL to issue, if applicable. --> #### Link to tracking issue Required for open-telemetry#39482 and open-telemetry#39248 <!--Describe what testing was performed and which tests were added.--> #### Testing Nothing to be changed, only existing test. <!--Describe the documentation added.--> #### Documentation Nothing to be changed. <!--Please delete paragraphs that you did not use before submitting.-->
1 parent dae90e6 commit 491a856

File tree

1 file changed

+9
-9
lines changed

1 file changed

+9
-9
lines changed

extension/oauth2clientauthextension/extension.go

+9-9
Original file line numberDiff line numberDiff line change
@@ -21,14 +21,14 @@ import (
2121
)
2222

2323
var (
24-
_ extension.Extension = (*clientAuthenticator)(nil)
25-
_ extensionauth.HTTPClient = (*clientAuthenticator)(nil)
26-
_ extensionauth.GRPCClient = (*clientAuthenticator)(nil)
24+
_ extension.Extension = (*OauthClientAuthenticator)(nil)
25+
_ extensionauth.HTTPClient = (*OauthClientAuthenticator)(nil)
26+
_ extensionauth.GRPCClient = (*OauthClientAuthenticator)(nil)
2727
)
2828

29-
// clientAuthenticator provides implementation for providing client authentication using OAuth2 client credentials
29+
// OauthClientAuthenticator provides implementation for providing client authentication using OAuth2 client credentials
3030
// workflow for both gRPC and HTTP clients.
31-
type clientAuthenticator struct {
31+
type OauthClientAuthenticator struct {
3232
component.StartFunc
3333
component.ShutdownFunc
3434

@@ -48,7 +48,7 @@ var _ oauth2.TokenSource = (*errorWrappingTokenSource)(nil)
4848
// errFailedToGetSecurityToken indicates a problem communicating with OAuth2 server.
4949
var errFailedToGetSecurityToken = errors.New("failed to get security token from token endpoint")
5050

51-
func newClientAuthenticator(cfg *Config, logger *zap.Logger) (*clientAuthenticator, error) {
51+
func newClientAuthenticator(cfg *Config, logger *zap.Logger) (*OauthClientAuthenticator, error) {
5252
transport := http.DefaultTransport.(*http.Transport).Clone()
5353

5454
tlsCfg, err := cfg.TLSSetting.LoadTLSConfig(context.Background())
@@ -57,7 +57,7 @@ func newClientAuthenticator(cfg *Config, logger *zap.Logger) (*clientAuthenticat
5757
}
5858
transport.TLSClientConfig = tlsCfg
5959

60-
return &clientAuthenticator{
60+
return &OauthClientAuthenticator{
6161
clientCredentials: &clientCredentialsConfig{
6262
Config: clientcredentials.Config{
6363
ClientID: cfg.ClientID,
@@ -90,7 +90,7 @@ func (ewts errorWrappingTokenSource) Token() (*oauth2.Token, error) {
9090

9191
// RoundTripper returns oauth2.Transport, an http.RoundTripper that performs "client-credential" OAuth flow and
9292
// also auto refreshes OAuth tokens as needed.
93-
func (o *clientAuthenticator) RoundTripper(base http.RoundTripper) (http.RoundTripper, error) {
93+
func (o *OauthClientAuthenticator) RoundTripper(base http.RoundTripper) (http.RoundTripper, error) {
9494
ctx := context.WithValue(context.Background(), oauth2.HTTPClient, o.client)
9595
return &oauth2.Transport{
9696
Source: errorWrappingTokenSource{
@@ -103,7 +103,7 @@ func (o *clientAuthenticator) RoundTripper(base http.RoundTripper) (http.RoundTr
103103

104104
// PerRPCCredentials returns gRPC PerRPCCredentials that supports "client-credential" OAuth flow. The underneath
105105
// oauth2.clientcredentials.Config instance will manage tokens performing auto refresh as necessary.
106-
func (o *clientAuthenticator) PerRPCCredentials() (credentials.PerRPCCredentials, error) {
106+
func (o *OauthClientAuthenticator) PerRPCCredentials() (credentials.PerRPCCredentials, error) {
107107
ctx := context.WithValue(context.Background(), oauth2.HTTPClient, o.client)
108108
return grpcOAuth.TokenSource{
109109
TokenSource: errorWrappingTokenSource{

0 commit comments

Comments
 (0)