1
// Copyright 2014 Canonical Ltd.
2
// Licensed under the AGPLv3, see LICENCE file for details.
12
// ProxySettings holds the values for the http, https and ftp proxies found by
14
type ProxySettings struct {
20
func getProxySetting(key string) string {
21
value := os.Getenv(key)
23
value = os.Getenv(strings.ToUpper(key))
28
// DetectProxies returns the proxy settings found the environment.
29
func DetectProxies() ProxySettings {
31
Http: getProxySetting("http_proxy"),
32
Https: getProxySetting("https_proxy"),
33
Ftp: getProxySetting("ftp_proxy"),
37
// AsEnvironmentValues returns a potentially multi-line
38
// string in a format that specifies key=value lines.
39
// There are two lines for each non-empty proxy value,
40
// one lower-case and one upper-case.
41
func (s *ProxySettings) AsEnvironmentValues() string {
43
addLine := func(proxy, value string) {
47
fmt.Sprintf("export %s=%s", proxy, value),
48
fmt.Sprintf("export %s=%s", strings.ToUpper(proxy), value))
51
addLine("http_proxy", s.Http)
52
addLine("https_proxy", s.Https)
53
addLine("ftp_proxy", s.Ftp)
54
return strings.Join(lines, "\n")