Config: reference environment variables in configuration values - #32029
Open
andig wants to merge 1 commit into
Open
Config: reference environment variables in configuration values#32029andig wants to merge 1 commit into
andig wants to merge 1 commit into
Conversation
Contributor
There was a problem hiding this comment.
Hey - I've found 1 issue, and left some high level feedback:
- In
envHookFunc, callingreflect.ValueOf(data).String()assumesdatais a string and can panic for other source types; consider using a type assertion orfmt.Sprintto safely handle non-string inputs. - The
envRefregex only allows\win environment variable names, which may be too restrictive for some deployments; consider broadening the allowed character set or aligning with the actual constraints used elsewhere for env var names.
Prompt for AI Agents
Please address the comments from this code review:
## Overall Comments
- In `envHookFunc`, calling `reflect.ValueOf(data).String()` assumes `data` is a string and can panic for other source types; consider using a type assertion or `fmt.Sprint` to safely handle non-string inputs.
- The `envRef` regex only allows `\w` in environment variable names, which may be too restrictive for some deployments; consider broadening the allowed character set or aligning with the actual constraints used elsewhere for env var names.
## Individual Comments
### Comment 1
<location path="util/decoder.go" line_range="25" />
<code_context>
+ return data, nil
+ }
+
+ m := envRef.FindStringSubmatch(reflect.ValueOf(data).String())
+ if m == nil {
+ return data, nil
</code_context>
<issue_to_address>
**issue (bug_risk):** Guard against nil `data` before calling `reflect.ValueOf` to avoid a panic.
`data` can still be `nil` or a non-string when the hook is invoked, and `reflect.ValueOf(nil)` will panic. Add a nil check (e.g. `if data == nil { return data, nil }`) before calling `reflect.ValueOf` to prevent this.
</issue_to_address>Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.
| return data, nil | ||
| } | ||
|
|
||
| m := envRef.FindStringSubmatch(reflect.ValueOf(data).String()) |
Contributor
There was a problem hiding this comment.
issue (bug_risk): Guard against nil data before calling reflect.ValueOf to avoid a panic.
data can still be nil or a non-string when the hook is invoked, and reflect.ValueOf(nil) will panic. Add a nil check (e.g. if data == nil { return data, nil }) before calling reflect.ValueOf to prevent this.
This comment has been minimized.
This comment has been minimized.
Contributor
|
✅ Build finished.
|
This file contains hidden or 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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
fixes #31880
Allows any configuration value to reference an environment variable instead of containing the secret inline. Entering
${env:SUPERVISOR_TOKEN}into a form field resolves the value from the process environment when the device is created.util.DecodeOther, so it covers all device, plugin and global settings configuration, from both UI and yaml${env:NAME}is only substituted when it makes up the entire value, keeping it clear of the existing${var}plugin placeholder syntaxNOTE: Global yaml settings parsed by viper are not covered, since yaml configuration is being retired anyway.