OLD | NEW |
1 // Copyright 2012, 2013 Canonical Ltd. | 1 // Copyright 2012, 2013 Canonical Ltd. |
2 // Licensed under the AGPLv3, see LICENCE file for details. | 2 // Licensed under the AGPLv3, see LICENCE file for details. |
3 | 3 |
4 package config | 4 package config |
5 | 5 |
6 import ( | 6 import ( |
7 "fmt" | 7 "fmt" |
8 "io/ioutil" | 8 "io/ioutil" |
9 "os" | 9 "os" |
10 "os/exec" | 10 "os/exec" |
11 "path/filepath" | 11 "path/filepath" |
12 "regexp" | 12 "regexp" |
13 "strings" | 13 "strings" |
14 "time" | 14 "time" |
15 | 15 |
16 "github.com/juju/errors" | 16 "github.com/juju/errors" |
17 "github.com/juju/loggo" | 17 "github.com/juju/loggo" |
18 | 18 |
19 "launchpad.net/juju-core/cert" | 19 "launchpad.net/juju-core/cert" |
20 "launchpad.net/juju-core/charm" | 20 "launchpad.net/juju-core/charm" |
21 "launchpad.net/juju-core/juju/osenv" | 21 "launchpad.net/juju-core/juju/osenv" |
22 "launchpad.net/juju-core/schema" | 22 "launchpad.net/juju-core/schema" |
23 "launchpad.net/juju-core/utils" | 23 "launchpad.net/juju-core/utils" |
| 24 "launchpad.net/juju-core/utils/proxy" |
24 "launchpad.net/juju-core/version" | 25 "launchpad.net/juju-core/version" |
25 ) | 26 ) |
26 | 27 |
27 var logger = loggo.GetLogger("juju.environs.config") | 28 var logger = loggo.GetLogger("juju.environs.config") |
28 | 29 |
29 const ( | 30 const ( |
30 // FwInstance requests the use of an individual firewall per instance. | 31 // FwInstance requests the use of an individual firewall per instance. |
31 FwInstance = "instance" | 32 FwInstance = "instance" |
32 | 33 |
33 // FwGlobal requests the use of a single firewall group for all machines
. | 34 // FwGlobal requests the use of a single firewall group for all machines
. |
(...skipping 470 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
504 | 505 |
505 // ProxySSH returns a flag indicating whether SSH commands | 506 // ProxySSH returns a flag indicating whether SSH commands |
506 // should be proxied through the API server. | 507 // should be proxied through the API server. |
507 func (c *Config) ProxySSH() bool { | 508 func (c *Config) ProxySSH() bool { |
508 value, _ := c.defined["proxy-ssh"].(bool) | 509 value, _ := c.defined["proxy-ssh"].(bool) |
509 return value | 510 return value |
510 } | 511 } |
511 | 512 |
512 // ProxySettings returns all four proxy settings; http, https, ftp, and no | 513 // ProxySettings returns all four proxy settings; http, https, ftp, and no |
513 // proxy. | 514 // proxy. |
514 func (c *Config) ProxySettings() osenv.ProxySettings { | 515 func (c *Config) ProxySettings() proxy.Settings { |
515 » return osenv.ProxySettings{ | 516 » return proxy.Settings{ |
516 Http: c.HttpProxy(), | 517 Http: c.HttpProxy(), |
517 Https: c.HttpsProxy(), | 518 Https: c.HttpsProxy(), |
518 Ftp: c.FtpProxy(), | 519 Ftp: c.FtpProxy(), |
519 NoProxy: c.NoProxy(), | 520 NoProxy: c.NoProxy(), |
520 } | 521 } |
521 } | 522 } |
522 | 523 |
523 // HttpProxy returns the http proxy for the environment. | 524 // HttpProxy returns the http proxy for the environment. |
524 func (c *Config) HttpProxy() string { | 525 func (c *Config) HttpProxy() string { |
525 return c.asString("http-proxy") | 526 return c.asString("http-proxy") |
(...skipping 16 matching lines...) Expand all Loading... |
542 | 543 |
543 func (c *Config) getWithFallback(key, fallback string) string { | 544 func (c *Config) getWithFallback(key, fallback string) string { |
544 value := c.asString(key) | 545 value := c.asString(key) |
545 if value == "" { | 546 if value == "" { |
546 value = c.asString(fallback) | 547 value = c.asString(fallback) |
547 } | 548 } |
548 return value | 549 return value |
549 } | 550 } |
550 | 551 |
551 // AptProxySettings returns all three proxy settings; http, https and ftp. | 552 // AptProxySettings returns all three proxy settings; http, https and ftp. |
552 func (c *Config) AptProxySettings() osenv.ProxySettings { | 553 func (c *Config) AptProxySettings() proxy.Settings { |
553 » return osenv.ProxySettings{ | 554 » return proxy.Settings{ |
554 Http: c.AptHttpProxy(), | 555 Http: c.AptHttpProxy(), |
555 Https: c.AptHttpsProxy(), | 556 Https: c.AptHttpsProxy(), |
556 Ftp: c.AptFtpProxy(), | 557 Ftp: c.AptFtpProxy(), |
557 } | 558 } |
558 } | 559 } |
559 | 560 |
560 // AptHttpProxy returns the apt http proxy for the environment. | 561 // AptHttpProxy returns the apt http proxy for the environment. |
561 // Falls back to the default http-proxy if not specified. | 562 // Falls back to the default http-proxy if not specified. |
562 func (c *Config) AptHttpProxy() string { | 563 func (c *Config) AptHttpProxy() string { |
563 return c.getWithFallback("apt-http-proxy", "http-proxy") | 564 return c.getWithFallback("apt-http-proxy", "http-proxy") |
(...skipping 448 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1012 } | 1013 } |
1013 | 1014 |
1014 func addIfNotEmpty(settings map[string]interface{}, key, value string) { | 1015 func addIfNotEmpty(settings map[string]interface{}, key, value string) { |
1015 if value != "" { | 1016 if value != "" { |
1016 settings[key] = value | 1017 settings[key] = value |
1017 } | 1018 } |
1018 } | 1019 } |
1019 | 1020 |
1020 // ProxyConfigMap returns a map suitable to be applied to a Config to update | 1021 // ProxyConfigMap returns a map suitable to be applied to a Config to update |
1021 // proxy settings. | 1022 // proxy settings. |
1022 func ProxyConfigMap(proxy osenv.ProxySettings) map[string]interface{} { | 1023 func ProxyConfigMap(proxySettings proxy.Settings) map[string]interface{} { |
1023 settings := make(map[string]interface{}) | 1024 settings := make(map[string]interface{}) |
1024 » addIfNotEmpty(settings, "http-proxy", proxy.Http) | 1025 » addIfNotEmpty(settings, "http-proxy", proxySettings.Http) |
1025 » addIfNotEmpty(settings, "https-proxy", proxy.Https) | 1026 » addIfNotEmpty(settings, "https-proxy", proxySettings.Https) |
1026 » addIfNotEmpty(settings, "ftp-proxy", proxy.Ftp) | 1027 » addIfNotEmpty(settings, "ftp-proxy", proxySettings.Ftp) |
1027 » addIfNotEmpty(settings, "no-proxy", proxy.NoProxy) | 1028 » addIfNotEmpty(settings, "no-proxy", proxySettings.NoProxy) |
1028 return settings | 1029 return settings |
1029 } | 1030 } |
1030 | 1031 |
1031 // AptProxyConfigMap returns a map suitable to be applied to a Config to update | 1032 // AptProxyConfigMap returns a map suitable to be applied to a Config to update |
1032 // proxy settings. | 1033 // proxy settings. |
1033 func AptProxyConfigMap(proxy osenv.ProxySettings) map[string]interface{} { | 1034 func AptProxyConfigMap(proxySettings proxy.Settings) map[string]interface{} { |
1034 settings := make(map[string]interface{}) | 1035 settings := make(map[string]interface{}) |
1035 » addIfNotEmpty(settings, "apt-http-proxy", proxy.Http) | 1036 » addIfNotEmpty(settings, "apt-http-proxy", proxySettings.Http) |
1036 » addIfNotEmpty(settings, "apt-https-proxy", proxy.Https) | 1037 » addIfNotEmpty(settings, "apt-https-proxy", proxySettings.Https) |
1037 » addIfNotEmpty(settings, "apt-ftp-proxy", proxy.Ftp) | 1038 » addIfNotEmpty(settings, "apt-ftp-proxy", proxySettings.Ftp) |
1038 return settings | 1039 return settings |
1039 } | 1040 } |
OLD | NEW |