-
Notifications
You must be signed in to change notification settings - Fork 2.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' into chore/flag-autoscaling-v2beta2
- Loading branch information
Showing
21 changed files
with
653 additions
and
535 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
# 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: oauth2clientauthextension | ||
|
||
# A brief description of the change. Surround your text with quotes ("") if it needs to start with a backtick (`). | ||
note: Enable dynamically reading ClientID and ClientSecret from files | ||
|
||
# Mandatory: One or more tracking issues related to the change. You can use the PR number here if no issue exists. | ||
issues: [26117] | ||
|
||
# (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: | | ||
- Read the client ID and/or secret from a file by specifying the file path to the ClientIDFile (`client_id_file`) and ClientSecretFile (`client_secret_file`) fields respectively. | ||
- The file is read every time the client issues a new token. This means that the corresponding value can change dynamically during the execution by modifying the file contents. | ||
# 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: [user, api] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
# 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. filelogreceiver) | ||
component: pkg/stanza | ||
|
||
# A brief description of the change. Surround your text with quotes ("") if it needs to start with a backtick (`). | ||
note: Remove Flusher from tokenize.SplitterConfig | ||
|
||
# Mandatory: One or more tracking issues related to the change. You can use the PR number here if no issue exists. | ||
issues: [26517] | ||
|
||
# (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: Removes the following in favor of flush.WithPeriod | ||
- tokenize.DefaultFlushPeriod | ||
- tokenize.FlusherConfig | ||
- tokenize.NewFlusherConfig | ||
|
||
# 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: [api] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
102 changes: 102 additions & 0 deletions
102
extension/oauth2clientauthextension/clientcredentialsconfig.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,102 @@ | ||
// Copyright The OpenTelemetry Authors | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
package oauth2clientauthextension // import "github.com/open-telemetry/opentelemetry-collector-contrib/extension/oauth2clientauthextension" | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
"os" | ||
"strings" | ||
|
||
"go.uber.org/multierr" | ||
"golang.org/x/oauth2" | ||
"golang.org/x/oauth2/clientcredentials" | ||
) | ||
|
||
// clientCredentialsConfig is a clientcredentials.Config wrapper to allow | ||
// values read from files in the ClientID and ClientSecret fields. | ||
// | ||
// Values from files can be retrieved by populating the ClientIDFile or | ||
// the ClientSecretFile fields with the path to the file. | ||
// | ||
// Priority: File > Raw value | ||
// | ||
// Example - Retrieve secret from file: | ||
// | ||
// cfg := clientCredentialsConfig{ | ||
// Config: clientcredentials.Config{ | ||
// ClientID: "clientId", | ||
// ... | ||
// }, | ||
// ClientSecretFile: "/path/to/client/secret", | ||
// } | ||
type clientCredentialsConfig struct { | ||
clientcredentials.Config | ||
|
||
ClientIDFile string | ||
ClientSecretFile string | ||
} | ||
|
||
type clientCredentialsTokenSource struct { | ||
ctx context.Context | ||
config *clientCredentialsConfig | ||
} | ||
|
||
// clientCredentialsTokenSource implements TokenSource | ||
var _ oauth2.TokenSource = (*clientCredentialsTokenSource)(nil) | ||
|
||
func readCredentialsFile(path string) (string, error) { | ||
f, err := os.ReadFile(path) | ||
if err != nil { | ||
return "", fmt.Errorf("failed to read credentials file %q: %w", path, err) | ||
} | ||
|
||
credential := strings.TrimSpace(string(f)) | ||
if credential == "" { | ||
return "", fmt.Errorf("empty credentials file %q", path) | ||
} | ||
return credential, nil | ||
} | ||
|
||
func getActualValue(value, filepath string) (string, error) { | ||
if len(filepath) > 0 { | ||
return readCredentialsFile(filepath) | ||
} | ||
|
||
return value, nil | ||
} | ||
|
||
// createConfig creates a proper clientcredentials.Config with values retrieved | ||
// from files, if the user has specified '*_file' values | ||
func (c *clientCredentialsConfig) createConfig() (*clientcredentials.Config, error) { | ||
clientID, err := getActualValue(c.ClientID, c.ClientIDFile) | ||
if err != nil { | ||
return nil, multierr.Combine(errNoClientIDProvided, err) | ||
} | ||
|
||
clientSecret, err := getActualValue(c.ClientSecret, c.ClientSecretFile) | ||
if err != nil { | ||
return nil, multierr.Combine(errNoClientSecretProvided, err) | ||
} | ||
|
||
return &clientcredentials.Config{ | ||
ClientID: clientID, | ||
ClientSecret: clientSecret, | ||
TokenURL: c.TokenURL, | ||
Scopes: c.Scopes, | ||
EndpointParams: c.EndpointParams, | ||
}, nil | ||
} | ||
|
||
func (c *clientCredentialsConfig) TokenSource(ctx context.Context) oauth2.TokenSource { | ||
return oauth2.ReuseTokenSource(nil, clientCredentialsTokenSource{ctx: ctx, config: c}) | ||
} | ||
|
||
func (ts clientCredentialsTokenSource) Token() (*oauth2.Token, error) { | ||
cfg, err := ts.config.createConfig() | ||
if err != nil { | ||
return nil, err | ||
} | ||
return cfg.TokenSource(ts.ctx).Token() | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
testcreds |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.