本文整理汇总了Golang中github.com/juju/utils/proxy.DetectProxies函数的典型用法代码示例。如果您正苦于以下问题:Golang DetectProxies函数的具体用法?Golang DetectProxies怎么用?Golang DetectProxies使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了DetectProxies函数的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: 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")
}
示例2: waitProxySettings
func (s *MachineEnvironmentWatcherSuite) waitProxySettings(c *gc.C, expected proxy.Settings) {
for {
select {
case <-time.After(testing.LongWait):
c.Fatalf("timeout while waiting for proxy settings to change")
case <-time.After(10 * time.Millisecond):
obtained := proxy.DetectProxies()
if obtained != expected {
c.Logf("proxy settings are %#v, still waiting", obtained)
continue
}
return
}
}
}
示例3: TestDetectNoSettings
func (s *proxySuite) TestDetectNoSettings(c *gc.C) {
// Patch all of the environment variables we check out just in case the
// user has one set.
s.PatchEnvironment("http_proxy", "")
s.PatchEnvironment("HTTP_PROXY", "")
s.PatchEnvironment("https_proxy", "")
s.PatchEnvironment("HTTPS_PROXY", "")
s.PatchEnvironment("ftp_proxy", "")
s.PatchEnvironment("FTP_PROXY", "")
s.PatchEnvironment("no_proxy", "")
s.PatchEnvironment("NO_PROXY", "")
proxies := proxy.DetectProxies()
c.Assert(proxies, gc.DeepEquals, proxy.Settings{})
}
示例4: waitProxySettings
func (s *ProxyUpdaterSuite) waitProxySettings(c *gc.C, expected proxy.Settings) {
for {
select {
case <-time.After(time.Second):
c.Fatalf("timeout while waiting for proxy settings to change")
return
case <-time.After(10 * time.Millisecond):
obtained := proxy.DetectProxies()
if obtained != expected {
if obtained != s.detectedSettings {
c.Logf("proxy settings are \n%#v, should be \n%#v, still waiting", obtained, expected)
}
s.detectedSettings = obtained
continue
}
return
}
}
}
示例5: TestDetectPrimaryPreference
func (s *proxySuite) TestDetectPrimaryPreference(c *gc.C) {
// Patch all of the environment variables we check out just in case the
// user has one set.
s.PatchEnvironment("http_proxy", "http://[email protected]")
s.PatchEnvironment("https_proxy", "https://[email protected]")
s.PatchEnvironment("ftp_proxy", "ftp://[email protected]")
s.PatchEnvironment("no_proxy", "10.0.3.1,localhost")
s.PatchEnvironment("HTTP_PROXY", "http://[email protected]")
s.PatchEnvironment("HTTPS_PROXY", "https://[email protected]")
s.PatchEnvironment("FTP_PROXY", "ftp://[email protected]")
s.PatchEnvironment("NO_PROXY", "localhost")
proxies := proxy.DetectProxies()
c.Assert(proxies, gc.DeepEquals, proxy.Settings{
Http: "http://[email protected]",
Https: "https://[email protected]",
Ftp: "ftp://[email protected]",
NoProxy: "10.0.3.1,localhost",
})
}
示例6: Initialise
// Initialise is specified on the container.Initialiser interface.
func (ci *containerInitialiser) Initialise() error {
err := ensureDependencies(ci.series)
if err != nil {
return err
}
err = configureLXDBridge()
if err != nil {
return err
}
proxies := proxy.DetectProxies()
err = ConfigureLXDProxies(proxies)
if err != nil {
return err
}
// Well... this will need to change soon once we are passed 17.04 as who
// knows what the series name will be.
if ci.series >= "xenial" {
configureZFS()
}
return nil
}
示例7: PrepareForCreateEnvironment
// PrepareForCreateEnvironment is specified in the EnvironProvider interface.
func (p environProvider) PrepareForCreateEnvironment(cfg *config.Config) (*config.Config, error) {
attrs := map[string]interface{}{
// We must not proxy SSH through the API server in a
// local provider environment. Besides not being useful,
// it may not work; there is no requirement for sshd to
// be available on machine-0.
"proxy-ssh": false,
}
if _, ok := cfg.AgentVersion(); !ok {
attrs["agent-version"] = version.Current.Number.String()
}
if namespace, _ := cfg.UnknownAttrs()["namespace"].(string); namespace == "" {
username := os.Getenv("USER")
if username == "" {
u, err := userCurrent()
if err != nil {
return nil, errors.Annotate(err, "failed to determine username for namespace")
}
username = u.Username
}
attrs["namespace"] = fmt.Sprintf("%s-%s", username, cfg.Name())
}
setIfNotBlank := func(key, value string) {
if value != "" {
attrs[key] = value
}
}
// If the user has specified no values for any of the four normal
// proxies, then look in the environment and set them.
logger.Tracef("Look for proxies?")
if cfg.HttpProxy() == "" &&
cfg.HttpsProxy() == "" &&
cfg.FtpProxy() == "" &&
cfg.NoProxy() == "" {
proxySettings := proxy.DetectProxies()
logger.Tracef("Proxies detected %#v", proxySettings)
setIfNotBlank(config.HttpProxyKey, proxySettings.Http)
setIfNotBlank(config.HttpsProxyKey, proxySettings.Https)
setIfNotBlank(config.FtpProxyKey, proxySettings.Ftp)
setIfNotBlank(config.NoProxyKey, proxySettings.NoProxy)
}
if version.Current.OS == version.Ubuntu {
if cfg.AptHttpProxy() == "" &&
cfg.AptHttpsProxy() == "" &&
cfg.AptFtpProxy() == "" {
proxySettings, err := detectPackageProxies()
if err != nil {
return nil, errors.Trace(err)
}
setIfNotBlank(config.AptHttpProxyKey, proxySettings.Http)
setIfNotBlank(config.AptHttpsProxyKey, proxySettings.Https)
setIfNotBlank(config.AptFtpProxyKey, proxySettings.Ftp)
}
}
cfg, err := cfg.Apply(attrs)
if err != nil {
return nil, errors.Trace(err)
}
// Make sure everything is valid.
cfg, err = p.Validate(cfg, nil)
if err != nil {
return nil, errors.Trace(err)
}
return cfg, nil
}
示例8: PrepareForBootstrap
// PrepareForBootstrap implements environs.EnvironProvider.PrepareForBootstrap.
func (p environProvider) PrepareForBootstrap(ctx environs.BootstrapContext, cfg *config.Config) (environs.Environ, error) {
attrs := map[string]interface{}{
// We must not proxy SSH through the API server in a
// local provider environment. Besides not being useful,
// it may not work; there is no requirement for sshd to
// be available on machine-0.
"proxy-ssh": false,
}
if _, ok := cfg.AgentVersion(); !ok {
attrs["agent-version"] = version.Current.String()
}
if namespace, _ := cfg.UnknownAttrs()["namespace"].(string); namespace == "" {
username := os.Getenv("USER")
if username == "" {
u, err := userCurrent()
if err != nil {
return nil, errors.Annotate(err, "failed to determine username for namespace")
}
username = u.Username
}
attrs["namespace"] = fmt.Sprintf("%s-%s", username, cfg.Name())
}
setIfNotBlank := func(key, value string) {
if value != "" {
attrs[key] = value
}
}
// If the user has specified no values for any of the four normal
// proxies, then look in the environment and set them.
logger.Tracef("Look for proxies?")
if cfg.HttpProxy() == "" &&
cfg.HttpsProxy() == "" &&
cfg.FtpProxy() == "" &&
cfg.NoProxy() == "" {
proxySettings := proxy.DetectProxies()
logger.Tracef("Proxies detected %#v", proxySettings)
setIfNotBlank(config.HttpProxyKey, proxySettings.Http)
setIfNotBlank(config.HttpsProxyKey, proxySettings.Https)
setIfNotBlank(config.FtpProxyKey, proxySettings.Ftp)
setIfNotBlank(config.NoProxyKey, proxySettings.NoProxy)
}
if jujuos.HostOS() == jujuos.Ubuntu {
if cfg.AptHttpProxy() == "" &&
cfg.AptHttpsProxy() == "" &&
cfg.AptFtpProxy() == "" {
proxySettings, err := detectPackageProxies()
if err != nil {
return nil, errors.Trace(err)
}
setIfNotBlank(config.AptHttpProxyKey, proxySettings.Http)
setIfNotBlank(config.AptHttpsProxyKey, proxySettings.Https)
setIfNotBlank(config.AptFtpProxyKey, proxySettings.Ftp)
}
}
cfg, err := cfg.Apply(attrs)
if err != nil {
return nil, errors.Trace(err)
}
// Make sure everything is valid.
cfg, err = p.Validate(cfg, nil)
if err != nil {
return nil, errors.Trace(err)
}
// The user must not set bootstrap-ip; this is determined by the provider,
// and its presence used to determine whether the environment has yet been
// bootstrapped.
if _, ok := cfg.UnknownAttrs()["bootstrap-ip"]; ok {
return nil, errors.Errorf("bootstrap-ip must not be specified")
}
err = checkLocalPort(cfg.StatePort(), "state port")
if err != nil {
return nil, errors.Trace(err)
}
err = checkLocalPort(cfg.APIPort(), "API port")
if err != nil {
return nil, errors.Trace(err)
}
return p.Open(cfg)
}
示例9: Prepare
// Prepare implements environs.EnvironProvider.Prepare.
func (p environProvider) Prepare(ctx environs.BootstrapContext, cfg *config.Config) (environs.Environ, error) {
// The user must not set bootstrap-ip; this is determined by the provider,
// and its presence used to determine whether the environment has yet been
// bootstrapped.
if _, ok := cfg.UnknownAttrs()["bootstrap-ip"]; ok {
return nil, fmt.Errorf("bootstrap-ip must not be specified")
}
err := checkLocalPort(cfg.StatePort(), "state port")
if err != nil {
return nil, err
}
err = checkLocalPort(cfg.APIPort(), "API port")
if err != nil {
return nil, err
}
// If the user has specified no values for any of the three normal
// proxies, then look in the environment and set them.
attrs := map[string]interface{}{
// We must not proxy SSH through the API server in a
// local provider environment. Besides not being useful,
// it may not work; there is no requirement for sshd to
// be available on machine-0.
"proxy-ssh": false,
}
setIfNotBlank := func(key, value string) {
if value != "" {
attrs[key] = value
}
}
logger.Tracef("Look for proxies?")
if cfg.HttpProxy() == "" &&
cfg.HttpsProxy() == "" &&
cfg.FtpProxy() == "" &&
cfg.NoProxy() == "" {
proxySettings := proxy.DetectProxies()
logger.Tracef("Proxies detected %#v", proxySettings)
setIfNotBlank("http-proxy", proxySettings.Http)
setIfNotBlank("https-proxy", proxySettings.Https)
setIfNotBlank("ftp-proxy", proxySettings.Ftp)
setIfNotBlank("no-proxy", proxySettings.NoProxy)
}
if cfg.AptHttpProxy() == "" &&
cfg.AptHttpsProxy() == "" &&
cfg.AptFtpProxy() == "" {
proxySettings, err := detectAptProxies()
if err != nil {
return nil, err
}
setIfNotBlank("apt-http-proxy", proxySettings.Http)
setIfNotBlank("apt-https-proxy", proxySettings.Https)
setIfNotBlank("apt-ftp-proxy", proxySettings.Ftp)
}
if len(attrs) > 0 {
cfg, err = cfg.Apply(attrs)
if err != nil {
return nil, err
}
}
return p.Open(cfg)
}