Skip to content

Commit

Permalink
[extension/oauth2clientauth] Remove duplicate validation logic, use c…
Browse files Browse the repository at this point in the history
…onfig.Validate
  • Loading branch information
atoulme committed Jan 12, 2024
1 parent 5965ee6 commit 0375219
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 67 deletions.
27 changes: 27 additions & 0 deletions .chloggen/oauth2clientauthextension_validation.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# Use this changelog template to create an entry for release notes.

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

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

# A brief description of the change. Surround your text with quotes ("") if it needs to start with a backtick (`).
note: remove the duplicate validation logic, use config.Validate instead.

# Mandatory: One or more tracking issues related to the change. You can use the PR number here if no issue exists.
issues: [30469]

# (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:

# If your change doesn't affect end users or the exported elements of any package,
# you should instead start your pull request title with [chore] or use the "Skip Changelog" label.
# 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: []
10 changes: 0 additions & 10 deletions extension/oauth2clientauthextension/extension.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,16 +36,6 @@ var _ oauth2.TokenSource = (*errorWrappingTokenSource)(nil)
var errFailedToGetSecurityToken = fmt.Errorf("failed to get security token from token endpoint")

func newClientAuthenticator(cfg *Config, logger *zap.Logger) (*clientAuthenticator, error) {
if cfg.ClientID == "" && cfg.ClientIDFile == "" {
return nil, errNoClientIDProvided
}
if cfg.ClientSecret == "" && cfg.ClientSecretFile == "" {
return nil, errNoClientSecretProvided
}
if cfg.TokenURL == "" {
return nil, errNoTokenURLProvided
}

transport := http.DefaultTransport.(*http.Transport).Clone()

tlsCfg, err := cfg.TLSSetting.LoadTLSConfig()
Expand Down
48 changes: 0 additions & 48 deletions extension/oauth2clientauthextension/extension_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,36 +77,6 @@ func TestOAuthClientSettings(t *testing.T) {
shouldError: true,
expectedError: "failed to load TLS config: failed to load TLS cert and key",
},
{
name: "missing_client_id",
settings: &Config{
ClientSecret: "testsecret",
TokenURL: "https://example.com/v1/token",
Scopes: []string{"resource.read"},
},
shouldError: true,
expectedError: errNoClientIDProvided.Error(),
},
{
name: "missing_client_secret",
settings: &Config{
ClientID: "testclientid",
TokenURL: "https://example.com/v1/token",
Scopes: []string{"resource.read"},
},
shouldError: true,
expectedError: errNoClientSecretProvided.Error(),
},
{
name: "missing_token_url",
settings: &Config{
ClientID: "testclientid",
ClientSecret: "testsecret",
Scopes: []string{"resource.read"},
},
shouldError: true,
expectedError: errNoTokenURLProvided.Error(),
},
}

for _, test := range tests {
Expand Down Expand Up @@ -251,15 +221,6 @@ func TestRoundTripper(t *testing.T) {
},
shouldError: false,
},
{
name: "invalid_client_settings_should_error",
settings: &Config{
ClientID: "testclientid",
TokenURL: "https://example.com/v1/token",
Scopes: []string{"resource.read"},
},
shouldError: true,
},
}

testString := "TestString"
Expand Down Expand Up @@ -308,15 +269,6 @@ func TestOAuth2PerRPCCredentials(t *testing.T) {
},
shouldError: false,
},
{
name: "invalid_client_settings_should_error",
settings: &Config{
ClientID: "testclientid",
TokenURL: "https://example.com/v1/token",
Scopes: []string{"resource.read"},
},
shouldError: true,
},
}

for _, testcase := range tests {
Expand Down
9 changes: 0 additions & 9 deletions extension/oauth2clientauthextension/factory_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,15 +43,6 @@ func TestCreateExtension(t *testing.T) {
},
shouldError: false,
},
{
name: "invalid_client_settings_should_error",
settings: &Config{
ClientID: "testclientid",
TokenURL: "https://example.com/v1/token",
Scopes: []string{"resource.read"},
},
shouldError: true,
},
}

for _, testcase := range tests {
Expand Down

0 comments on commit 0375219

Please sign in to comment.