Skip to content

Commit c2ce25a

Browse files
committed
mozzle: Respect the Insecure target option
1 parent 401b26d commit c2ce25a

File tree

1 file changed

+28
-4
lines changed

1 file changed

+28
-4
lines changed

monitor.go

Lines changed: 28 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import (
66
"fmt"
77
"io/ioutil"
88
"log"
9+
"net"
910
"net/http"
1011
"net/url"
1112
"os"
@@ -84,9 +85,13 @@ func Monitor(ctx context.Context, t Target, e Emitter) (err error) {
8485
if err != nil {
8586
return err
8687
}
88+
var httpClient = http.DefaultClient
89+
if t.Insecure {
90+
httpClient = defaultInsecureClient
91+
}
8792
cf := &ccv2.Client{
8893
API: u,
89-
HTTPClient: http.DefaultClient,
94+
HTTPClient: httpClient,
9095
}
9196

9297
infoCtx, cancel := context.WithTimeout(ctx, DefaultRPCTimeout)
@@ -104,13 +109,15 @@ func Monitor(ctx context.Context, t Target, e Emitter) (err error) {
104109
},
105110
}
106111

107-
token, err := oauthConfig.PasswordCredentialsToken(context.Background(), t.Username, t.Password)
112+
// clientCtx is used to pass a non-default *http.Client to package aouth2.
113+
clientCtx := context.WithValue(context.Background(), oauth2.HTTPClient, httpClient)
114+
token, err := oauthConfig.PasswordCredentialsToken(clientCtx, t.Username, t.Password)
108115
if err != nil {
109116
return err
110117
}
111118
cf = &ccv2.Client{
112119
API: u,
113-
HTTPClient: oauthConfig.Client(context.Background(), token),
120+
HTTPClient: oauthConfig.Client(clientCtx, token),
114121
}
115122

116123
tlsConfig := &tls.Config{InsecureSkipVerify: t.Insecure}
@@ -121,7 +128,7 @@ func Monitor(ctx context.Context, t Target, e Emitter) (err error) {
121128
}
122129
}()
123130

124-
uaa := oauthConfig.TokenSource(context.Background(), token)
131+
uaa := oauthConfig.TokenSource(clientCtx, token)
125132
tr := tokenRefresher{uaa}
126133
firehose.RefreshTokenFrom(&tr)
127134

@@ -359,3 +366,20 @@ func (tr *tokenRefresher) RefreshAuthToken() (string, error) {
359366
}
360367
return t.TokenType + " " + t.AccessToken, nil
361368
}
369+
370+
var defaultInsecureClient = &http.Client{
371+
Transport: &http.Transport{
372+
Proxy: http.ProxyFromEnvironment,
373+
DialContext: (&net.Dialer{
374+
Timeout: 30 * time.Second,
375+
KeepAlive: 30 * time.Second,
376+
}).DialContext,
377+
MaxIdleConns: 100,
378+
IdleConnTimeout: 90 * time.Second,
379+
TLSHandshakeTimeout: 10 * time.Second,
380+
ExpectContinueTimeout: 1 * time.Second,
381+
TLSClientConfig: &tls.Config{
382+
InsecureSkipVerify: true,
383+
},
384+
},
385+
}

0 commit comments

Comments
 (0)