-
Notifications
You must be signed in to change notification settings - Fork 183
/
proxy.go
47 lines (38 loc) · 974 Bytes
/
proxy.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
package monitors
import (
"os"
"strings"
"github.com/signalfx/signalfx-agent/internal/core/services"
)
const (
noProxy = "no_proxy"
)
func setNoProxyEnvvar(value string) {
os.Setenv("no_proxy", value)
os.Setenv("NO_PROXY", value)
}
func isProxying() bool {
return os.Getenv("http_proxy") != "" || os.Getenv("https_proxy") != "" ||
os.Getenv("HTTP_PROXY") != "" || os.Getenv("HTTPS_PROXY") != ""
}
func getNoProxyEnvvar() string {
noProxy := os.Getenv("NO_PROXY")
if noProxy == "" {
noProxy = os.Getenv("no_proxy")
}
return noProxy
}
// sets the service IPs/hostnames in the no_proxy environment variable
func ensureProxyingDisabledForService(service services.Endpoint) {
host := service.Core().Host
if isProxying() && len(host) > 0 {
serviceIP := host
noProxy := getNoProxyEnvvar()
for _, existingIP := range strings.Split(noProxy, ",") {
if existingIP == serviceIP {
return
}
}
setNoProxyEnvvar(noProxy + "," + serviceIP)
}
}