Skip to content

Commit bf43edd

Browse files
committed
Replace localhost in proxy settings with gateway address
Previously this replacement was only applied to values from the current process environment. Now it also applies to system proxy settings, and values from the `env` section of lima.yaml. Signed-off-by: Jan Dubois <[email protected]>
1 parent 5aabbf6 commit bf43edd

File tree

1 file changed

+21
-21
lines changed

1 file changed

+21
-21
lines changed

pkg/cidata/cidata.go

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -39,31 +39,31 @@ func setupEnv(y *limayaml.LimaYAML) (map[string]string, error) {
3939
upperVars[i] = strings.ToUpper(name)
4040
}
4141
if *y.PropagateProxyEnv {
42-
localhostRegexes := []*regexp.Regexp{
43-
regexp.MustCompile(`\blocalhost\b`),
44-
regexp.MustCompile(`\b127.0.0.1\b`),
45-
}
4642
for _, name := range append(lowerVars, upperVars...) {
47-
value, ok := os.LookupEnv(name)
48-
if !ok {
49-
continue
50-
}
51-
// Replace "localhost" in proxy settings with the gateway address
52-
if name != "no_proxy" && name != "NO_PROXY" {
53-
newValue := value
54-
for _, re := range localhostRegexes {
55-
newValue = re.ReplaceAllString(newValue, qemu.SlirpGateway)
56-
}
57-
if value != newValue {
58-
logrus.Infof("Replacing %q value %q with %q", name, value, newValue)
59-
value = newValue
43+
if value, ok := os.LookupEnv(name); ok {
44+
if _, ok := env[name]; ok && value != env[name] {
45+
logrus.Infof("Overriding %q value %q with %q from limactl process environment",
46+
name, env[name], value)
6047
}
48+
env[name] = value
49+
}
50+
}
51+
}
52+
// Replace "localhost" in proxy settings with the gateway address
53+
localhostRegexes := []*regexp.Regexp{
54+
regexp.MustCompile(`\blocalhost\b`),
55+
regexp.MustCompile(`\b127.0.0.1\b`),
56+
}
57+
for _, name := range append(lowerVars, upperVars...) {
58+
value, ok := env[name]
59+
if ok && !strings.EqualFold(name, "no_proxy") {
60+
for _, re := range localhostRegexes {
61+
value = re.ReplaceAllString(value, qemu.SlirpGateway)
6162
}
62-
if _, ok := env[name]; ok && value != env[name] {
63-
logrus.Infof("Overriding %q value %q with %q from limactl process environment",
64-
name, env[name], value)
63+
if value != env[name] {
64+
logrus.Infof("Replacing %q value %q with %q", name, env[name], value)
65+
env[name] = value
6566
}
66-
env[name] = value
6767
}
6868
}
6969
// Make sure uppercase variants have the same value as lowercase ones.

0 commit comments

Comments
 (0)