-
Notifications
You must be signed in to change notification settings - Fork 604
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Setup proxy environment variables from system settings
env.* settings from lima.yaml will override system settings. Process environment during instance creation override all. Signed-off-by: Jan Dubois <[email protected]>
- Loading branch information
Showing
7 changed files
with
141 additions
and
25 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,11 @@ | ||
package osutil | ||
|
||
import "github.com/lima-vm/lima/pkg/sysprof" | ||
import ( | ||
"fmt" | ||
"strings" | ||
|
||
"github.com/lima-vm/lima/pkg/sysprof" | ||
) | ||
|
||
func DNSAddresses() ([]string, error) { | ||
nwData, err := sysprof.NetworkData() | ||
|
@@ -23,3 +28,47 @@ func DNSAddresses() ([]string, error) { | |
} | ||
return addresses, nil | ||
} | ||
|
||
func proxyURL(proxy string, port int) string { | ||
if !strings.Contains(proxy, "://") { | ||
proxy = "http://" + proxy | ||
} | ||
if port != 0 { | ||
proxy = fmt.Sprintf("%s:%d", proxy, port) | ||
} | ||
return proxy | ||
} | ||
|
||
func ProxySettings() (map[string]string, error) { | ||
nwData, err := sysprof.NetworkData() | ||
if err != nil { | ||
return nil, err | ||
} | ||
env := make(map[string]string) | ||
if len(nwData) > 0 { | ||
// In case "en0" is not found, use the proxies of the first interface | ||
proxies := nwData[0].Proxies | ||
for _, nw := range nwData { | ||
if nw.Interface == "en0" { | ||
proxies = nw.Proxies | ||
break | ||
} | ||
} | ||
// Proxies with a username are not going to work because the password is stored in a keychain. | ||
// If users are fine with exposing the username/password, they can set the proxy to | ||
// "http://username:[email protected]" in the system settings (or in lima.yaml). | ||
if proxies.FTPEnable == "yes" && proxies.FTPUser == "" { | ||
env["ftp_proxy"] = proxyURL(proxies.FTPProxy, proxies.FTPPort) | ||
} | ||
if proxies.HTTPEnable == "yes" && proxies.HTTPUser == "" { | ||
env["http_proxy"] = proxyURL(proxies.HTTPProxy, proxies.HTTPPort) | ||
} | ||
if proxies.HTTPSEnable == "yes" && proxies.HTTPSUser == "" { | ||
env["https_proxy"] = proxyURL(proxies.HTTPSProxy, proxies.HTTPSPort) | ||
} | ||
// Not setting up "no_proxy" variable; the values from the proxies.ExceptionList are | ||
// not understood by most applications checking "no_proxy". The default value would | ||
// be "*.local,169.254/16". Users can always specify env.no_proxy in lima.yaml. | ||
} | ||
return env, nil | ||
} |
This file contains 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
This file contains 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