-
Notifications
You must be signed in to change notification settings - Fork 112
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
Resolve environments case-insensitively on Windows #257
Resolve environments case-insensitively on Windows #257
Conversation
Thanks for looking into this! |
types/config.go
Outdated
@@ -32,7 +33,7 @@ type ConfigDetails struct { | |||
|
|||
// LookupEnv provides a lookup function for environment variables | |||
func (cd ConfigDetails) LookupEnv(key string) (string, bool) { | |||
v, ok := cd.Environment[key] | |||
v, ok := utils.EnvResolver(cd.Environment)(key) |
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.
as EnvResolver
is not used in any other place, I'd prefer we keep things simple with EnvResolverWithCase
logic being directly included here
utils/envresolver.go
Outdated
if ok { | ||
return v, ok | ||
} | ||
if loweredEnvironment == 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.
No need to allocate a full lowercase map on each lookup, could just do
key := strings.ToLower(s)
for k, v := range environment {
if key == strings.ToLower(k) {
return v
}
}
utils/envresolver_test.go
Outdated
"gotest.tools/v3/assert" | ||
) | ||
|
||
func Test_EnvResolverWithCase(t *testing.T) { |
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've added signed-off line as described in https://github.com/compose-spec/compose-go/blob/master/CONTRIBUTING.md :
But something might be wrong as this is the first time I wrote signed-off line. Should I use the real name also in author line? Or should I add GPG signature? (git commit -S) |
2f6d078
to
85892a2
Compare
Oh, I got it. I have to pass DCO action. I'll try that. |
85892a2
to
4fcc599
Compare
Thanks for the review. I fixed problems you pointed. |
Signed-off-by: IKEDA Yasuyuki <[email protected]>
Signed-off-by: IKEDA Yasuyuki <[email protected]>
4fcc599
to
eeab8f0
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.
LGTM
Please have a look on docker/compose#9431 for details.
compose-go extracts environment variables to
Environment map[string]string
and reference that later with simplyEnvironment[varname]
.It works case-sensitively but environment variables should be treated case-insensitively on Windows.
This change handles environment variables case-insensitively on Windows, without changing data structures on compose-go.
This change also adds exposed
utils.EnvResolver
function. I plan to use that for additional changes in https://github.com/docker/compose/ , handling option args like--build-arg
withbuild
sub command and-e
withrun
sub command.(like this: https://github.com/ikedam/compose/pull/1/files)