Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enforce scheme name restrictions to all confmap.Provider implementations. #5861

Merged
merged 1 commit into from
Aug 9, 2022

Conversation

bogdandrutu
Copy link
Member

Currently was documented that the format should be compatible with the URI definition (see https://datatracker.ietf.org/doc/html/rfc3986),
but the scheme name restriction was not copied from the RFC, and no tests to enforce. This PR clearly documents the characters allowed in the scheme name and add confmaptest helper func to test for valid scheme names.

Updates #5706

Signed-off-by: Bogdan bogdandrutu@gmail.com

@bogdandrutu bogdandrutu requested review from a team and codeboten August 8, 2022 18:45
Comment on lines 29 to +42
func LoadConf(fileName string) (*confmap.Conf, error) {
ret, err := fileprovider.New().Retrieve(context.Background(), "file:"+fileName, nil)
// Clean the path before using it.
content, err := ioutil.ReadFile(filepath.Clean(fileName))
if err != nil {
return nil, fmt.Errorf("unable to read the file %v: %w", fileName, err)
}

var rawConf map[string]interface{}
if err = yaml.Unmarshal(content, &rawConf); err != nil {
return nil, err
}
return ret.AsConf()

return confmap.NewFromStringMap(rawConf), nil
}
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I had to avoid using fileprovider.New() to avoid circular dependencies, since fileprovider uses ValidateProviderScheme.

@codecov
Copy link

codecov bot commented Aug 8, 2022

Codecov Report

Merging #5861 (a7beedf) into main (4c86c26) will increase coverage by 0.00%.
The diff coverage is 100.00%.

@@           Coverage Diff           @@
##             main    #5861   +/-   ##
=======================================
  Coverage   91.73%   91.74%           
=======================================
  Files         195      195           
  Lines       11915    11929   +14     
=======================================
+ Hits        10930    10944   +14     
  Misses        777      777           
  Partials      208      208           
Impacted Files Coverage Δ
confmap/provider.go 100.00% <ø> (ø)
confmap/confmaptest/configtest.go 100.00% <100.00%> (ø)
exporter/exporterhelper/common.go 93.97% <0.00%> (ø)

Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here.

@bogdandrutu bogdandrutu changed the title Enforce scheme name restrictions to all confmap.Provider implementaions. Enforce scheme name restrictions to all confmap.Provider implementations. Aug 8, 2022
@bogdandrutu bogdandrutu force-pushed the restrictscheme branch 3 times, most recently from 620ceec to 8b5fbb8 Compare August 8, 2022 19:11
…ons.

Currently was documented that the format should be compatible with the URI definition (see https://datatracker.ietf.org/doc/html/rfc3986),
but the scheme name restriction was not copied from the RFC, and no tests to enforce. This PR clearly documents the characters allowed in the scheme name and add confmaptest helper func to test for valid scheme names.

Signed-off-by: Bogdan <bogdandrutu@gmail.com>
Copy link
Member

@mx-psi mx-psi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changes here LGTM. Should we also make service.NewConfigProvider fail if it we pass a provider that does not have a valid scheme?

@bogdandrutu bogdandrutu merged commit 1212571 into open-telemetry:main Aug 9, 2022
@bogdandrutu bogdandrutu deleted the restrictscheme branch October 14, 2024 20:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants