-
Notifications
You must be signed in to change notification settings - Fork 1.5k
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
Conversation
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 | ||
} |
There was a problem hiding this comment.
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 Report
@@ 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
Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here. |
cf3d692
to
3af6bbb
Compare
620ceec
to
8b5fbb8
Compare
…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>
8b5fbb8
to
a7beedf
Compare
There was a problem hiding this 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?
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