Skip to content

Commit

Permalink
[confmap] Validate providers scheme when building a Resolver
Browse files Browse the repository at this point in the history
  • Loading branch information
mx-psi committed Aug 1, 2024
1 parent 2bb2613 commit 5e427e3
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 1 deletion.
25 changes: 25 additions & 0 deletions .chloggen/mx-psi_restrict-providers-scheme.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: enhancement

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

# A brief description of the change. Surround your text with quotes ("") if it needs to start with a backtick (`).
note: Check that providers have a correct scheme when building a confmap.Resolver.

# One or more tracking issues or pull requests related to the change
issues: []

# (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]
12 changes: 11 additions & 1 deletion confmap/resolver.go
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,17 @@ func NewResolver(set ResolverSettings) (*Resolver, error) {
providers := make(map[string]Provider, len(set.ProviderFactories))
for _, factory := range set.ProviderFactories {
provider := factory.Create(set.ProviderSettings)
providers[provider.Scheme()] = provider
scheme := provider.Scheme()
// Check that the scheme follows the pattern.
if !regexp.MustCompile(schemePattern).MatchString(scheme) {
return nil, fmt.Errorf("invalid 'confmap.Provider' scheme %q", scheme)
}
// Check that the scheme is unique.
if _, ok := providers[scheme]; ok {
return nil, fmt.Errorf("duplicate 'confmap.Provider' scheme %q", scheme)
}

providers[scheme] = provider
}

if set.DefaultScheme != "" {
Expand Down

0 comments on commit 5e427e3

Please sign in to comment.