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

Fix: Force usage of case-sensitive keys in configurations #6876

Merged
merged 4 commits into from
Jan 20, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions .chloggen/case-sensitive-configuration.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# One of 'breaking', 'deprecation', 'new_component', 'enhancement', 'bug_fix'
change_type: 'bug_fix'
rapphil marked this conversation as resolved.
Show resolved Hide resolved

# 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: Fix bug in confmap validation that allowed the usage of case-insensitive keys in the configurations, despite them failing silently.

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

# (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:
8 changes: 8 additions & 0 deletions confmap/confmap.go
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,7 @@ func decodeConfig(m *Conf, result interface{}, errorUnused bool) error {
Result: result,
TagName: "mapstructure",
WeaklyTypedInput: true,
MatchName: caseSensitiveMatchName,
DecodeHook: mapstructure.ComposeDecodeHookFunc(
expandNilStructPointersHookFunc(),
mapstructure.StringToSliceHookFunc(","),
Expand Down Expand Up @@ -189,6 +190,13 @@ func encoderConfig(rawVal interface{}) *encoder.EncoderConfig {
}
}

// case-sensitive version of the callback to be used in the MatchName property
rapphil marked this conversation as resolved.
Show resolved Hide resolved
// of the DecoderConfig. The default for MatchEqual is to use strings.EqualFold,
// which is case-insensitive.
func caseSensitiveMatchName(a, b string) bool {
return a == b
}

// In cases where a config has a mapping of something to a struct pointers
// we want nil values to resolve to a pointer to the zero value of the
// underlying struct just as we want nil values of a mapping of something
Expand Down
4 changes: 4 additions & 0 deletions exporter/loggingexporter/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,10 @@ func TestUnmarshalConfig(t *testing.T) {
filename: "invalid_verbosity_loglevel.yaml",
expectedErr: "'loglevel' and 'verbosity' are incompatible. Use only 'verbosity' instead",
},
{
filename: "config_loglevel_typo.yaml",
expectedErr: "1 error(s) decoding:\n\n* '' has invalid keys: logLevel",
},
}

for _, tt := range tests {
Expand Down
2 changes: 2 additions & 0 deletions exporter/loggingexporter/testdata/config_loglevel_typo.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# Typo in the configuration that assumes that this property is camelcase
logLevel: debug