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

Replace localhost in proxy settings with gateway address #508

Merged
merged 1 commit into from
Jan 1, 2022
Merged
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
42 changes: 21 additions & 21 deletions pkg/cidata/cidata.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,31 +39,31 @@ func setupEnv(y *limayaml.LimaYAML) (map[string]string, error) {
upperVars[i] = strings.ToUpper(name)
}
if *y.PropagateProxyEnv {
localhostRegexes := []*regexp.Regexp{
regexp.MustCompile(`\blocalhost\b`),
regexp.MustCompile(`\b127.0.0.1\b`),
}
for _, name := range append(lowerVars, upperVars...) {
value, ok := os.LookupEnv(name)
if !ok {
continue
}
// Replace "localhost" in proxy settings with the gateway address
if name != "no_proxy" && name != "NO_PROXY" {
newValue := value
for _, re := range localhostRegexes {
newValue = re.ReplaceAllString(newValue, qemu.SlirpGateway)
}
if value != newValue {
logrus.Infof("Replacing %q value %q with %q", name, value, newValue)
value = newValue
if value, ok := os.LookupEnv(name); ok {
if _, ok := env[name]; ok && value != env[name] {
logrus.Infof("Overriding %q value %q with %q from limactl process environment",
name, env[name], value)
}
env[name] = value
}
}
}
// Replace "localhost" in proxy settings with the gateway address
localhostRegexes := []*regexp.Regexp{
regexp.MustCompile(`\blocalhost\b`),
regexp.MustCompile(`\b127.0.0.1\b`),
}
for _, name := range append(lowerVars, upperVars...) {
value, ok := env[name]
if ok && !strings.EqualFold(name, "no_proxy") {
for _, re := range localhostRegexes {
value = re.ReplaceAllString(value, qemu.SlirpGateway)
}
if _, ok := env[name]; ok && value != env[name] {
logrus.Infof("Overriding %q value %q with %q from limactl process environment",
name, env[name], value)
if value != env[name] {
logrus.Infof("Replacing %q value %q with %q", name, env[name], value)
env[name] = value
}
env[name] = value
}
}
// Make sure uppercase variants have the same value as lowercase ones.
Expand Down