本文整理汇总了Golang中github.com/juju/utils/proxy.Settings类的典型用法代码示例。如果您正苦于以下问题:Golang Settings类的具体用法?Golang Settings怎么用?Golang Settings使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Settings类的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: GetProxySettings
// GetProxySettings is defined on the PackageManager interface.
func (apt *apt) GetProxySettings() (proxy.Settings, error) {
var res proxy.Settings
args := strings.Fields(apt.cmder.GetProxyCmd())
if len(args) <= 1 {
return proxy.Settings{}, fmt.Errorf("expected at least 2 arguments, got %d %v", len(args), args)
}
cmd := exec.Command(args[0], args[1:]...)
out, err := CommandOutput(cmd)
if err != nil {
logger.Errorf("command failed: %v\nargs: %#v\n%s",
err, args, string(out))
return res, fmt.Errorf("command failed: %v", err)
}
output := string(bytes.Join(proxyRE.FindAll(out, -1), []byte("\n")))
for _, match := range proxyRE.FindAllStringSubmatch(output, -1) {
switch match[1] {
case "http":
res.Http = match[2]
case "https":
res.Https = match[2]
case "ftp":
res.Ftp = match[2]
}
}
return res, nil
}
示例2: TestSetEnvironmentValues
func (s *proxySuite) TestSetEnvironmentValues(c *gc.C) {
s.PatchEnvironment("http_proxy", "initial")
s.PatchEnvironment("HTTP_PROXY", "initial")
s.PatchEnvironment("https_proxy", "initial")
s.PatchEnvironment("HTTPS_PROXY", "initial")
s.PatchEnvironment("ftp_proxy", "initial")
s.PatchEnvironment("FTP_PROXY", "initial")
s.PatchEnvironment("no_proxy", "initial")
s.PatchEnvironment("NO_PROXY", "initial")
proxySettings := proxy.Settings{
Http: "http proxy",
Https: "https proxy",
// Ftp left blank to show clearing env.
NoProxy: "10.0.3.1,localhost",
}
proxySettings.SetEnvironmentValues()
obtained := proxy.DetectProxies()
c.Assert(obtained, gc.DeepEquals, proxySettings)
c.Assert(os.Getenv("http_proxy"), gc.Equals, "http proxy")
c.Assert(os.Getenv("HTTP_PROXY"), gc.Equals, "http proxy")
c.Assert(os.Getenv("https_proxy"), gc.Equals, "https proxy")
c.Assert(os.Getenv("HTTPS_PROXY"), gc.Equals, "https proxy")
c.Assert(os.Getenv("ftp_proxy"), gc.Equals, "")
c.Assert(os.Getenv("FTP_PROXY"), gc.Equals, "")
c.Assert(os.Getenv("no_proxy"), gc.Equals, "10.0.3.1,localhost")
c.Assert(os.Getenv("NO_PROXY"), gc.Equals, "10.0.3.1,localhost")
}
示例3: GetProxySettings
// GetProxySettings is defined on the PackageManager interface.
func (yum *yum) GetProxySettings() (proxy.Settings, error) {
var res proxy.Settings
args := strings.Fields(yum.cmder.GetProxyCmd())
if len(args) <= 1 {
return proxy.Settings{}, fmt.Errorf("expected at least 2 arguments, got %d %v", len(args), args)
}
cmd := exec.Command(args[0], args[1:]...)
out, err := CommandOutput(cmd)
if err != nil {
logger.Errorf("command failed: %v\nargs: %#v\n%s",
err, args, string(out))
return res, fmt.Errorf("command failed: %v", err)
}
for _, match := range strings.Split(string(out), "\n") {
fields := strings.Split(match, "=")
if len(fields) != 2 {
continue
}
if strings.HasPrefix(fields[0], "https") {
res.Https = strings.TrimSpace(fields[1])
} else if strings.HasPrefix(fields[0], "http") {
res.Http = strings.TrimSpace(fields[1])
} else if strings.HasPrefix(fields[0], "ftp") {
res.Ftp = strings.TrimSpace(fields[1])
}
}
return res, nil
}
示例4: TestAsScriptEnvironmentOneValue
func (s *proxySuite) TestAsScriptEnvironmentOneValue(c *gc.C) {
proxies := proxy.Settings{
Http: "some-value",
}
expected := `
export http_proxy=some-value
export HTTP_PROXY=some-value`[1:]
c.Assert(proxies.AsScriptEnvironment(), gc.Equals, expected)
}
示例5: TestAsEnvironmentValuesOneValue
func (s *proxySuite) TestAsEnvironmentValuesOneValue(c *gc.C) {
proxies := proxy.Settings{
Http: "some-value",
}
expected := []string{
"http_proxy=some-value",
"HTTP_PROXY=some-value",
}
c.Assert(proxies.AsEnvironmentValues(), gc.DeepEquals, expected)
}
示例6: handleProxyValues
func (w *proxyWorker) handleProxyValues(proxySettings proxyutils.Settings) {
proxySettings.SetEnvironmentValues()
if proxySettings != w.proxy || w.first {
logger.Debugf("new proxy settings %#v", proxySettings)
w.proxy = proxySettings
if err := w.writeEnvironment(); err != nil {
// It isn't really fatal, but we should record it.
logger.Errorf("error writing proxy environment file: %v", err)
}
}
}
示例7: TestProxyConfigMap
func (s *ConfigSuite) TestProxyConfigMap(c *gc.C) {
s.addJujuFiles(c)
cfg := newTestConfig(c, testing.Attrs{})
proxySettings := proxy.Settings{
Http: "http proxy",
Https: "https proxy",
Ftp: "ftp proxy",
NoProxy: "no proxy",
}
cfg, err := cfg.Apply(config.ProxyConfigMap(proxySettings))
c.Assert(err, gc.IsNil)
c.Assert(cfg.ProxySettings(), gc.DeepEquals, proxySettings)
// Apt proxy and proxy differ by the content of the no-proxy values.
proxySettings.NoProxy = ""
c.Assert(cfg.AptProxySettings(), gc.DeepEquals, proxySettings)
}
示例8: TestAsScriptEnvironmentAllValue
func (s *proxySuite) TestAsScriptEnvironmentAllValue(c *gc.C) {
proxies := proxy.Settings{
Http: "some-value",
Https: "special",
Ftp: "who uses this?",
NoProxy: "10.0.3.1,localhost",
}
expected := `
export http_proxy=some-value
export HTTP_PROXY=some-value
export https_proxy=special
export HTTPS_PROXY=special
export ftp_proxy=who uses this?
export FTP_PROXY=who uses this?
export no_proxy=10.0.3.1,localhost
export NO_PROXY=10.0.3.1,localhost`[1:]
c.Assert(proxies.AsScriptEnvironment(), gc.Equals, expected)
}
示例9: TestAsEnvironmentValuesAllValue
func (s *proxySuite) TestAsEnvironmentValuesAllValue(c *gc.C) {
proxies := proxy.Settings{
Http: "some-value",
Https: "special",
Ftp: "who uses this?",
NoProxy: "10.0.3.1,localhost",
}
expected := []string{
"http_proxy=some-value",
"HTTP_PROXY=some-value",
"https_proxy=special",
"HTTPS_PROXY=special",
"ftp_proxy=who uses this?",
"FTP_PROXY=who uses this?",
"no_proxy=10.0.3.1,localhost",
"NO_PROXY=10.0.3.1,localhost",
}
c.Assert(proxies.AsEnvironmentValues(), gc.DeepEquals, expected)
}
示例10: TestAsEnvironmentValuesEmpty
func (s *proxySuite) TestAsEnvironmentValuesEmpty(c *gc.C) {
proxies := proxy.Settings{}
c.Assert(proxies.AsEnvironmentValues(), gc.HasLen, 0)
}
示例11: TestAsScriptEnvironmentEmpty
func (s *proxySuite) TestAsScriptEnvironmentEmpty(c *gc.C) {
proxies := proxy.Settings{}
c.Assert(proxies.AsScriptEnvironment(), gc.Equals, "")
}