@@ -42,21 +42,31 @@ import (
4242 "github.com/cortexlabs/cortex/pkg/operator/api/schema"
4343)
4444
45- var httpTransport = & http. Transport {
46- TLSClientConfig : & tls. Config { InsecureSkipVerify : true },
45+ type cortexClient struct {
46+ * http. Client
4747}
4848
49- var httpClient = & http.Client {
50- Timeout : time .Second * 20 ,
51- Transport : httpTransport ,
49+ var httpClient = & cortexClient {
50+ Client : & http.Client {
51+ Timeout : time .Second * 20 ,
52+ },
53+ }
54+
55+ var httpsNoVerifyClient = & cortexClient {
56+ Client : & http.Client {
57+ Timeout : time .Second * 20 ,
58+ Transport : & http.Transport {
59+ TLSClientConfig : & tls.Config {InsecureSkipVerify : true },
60+ },
61+ },
5262}
5363
5464func HTTPGet (endpoint string , qParams ... map [string ]string ) ([]byte , error ) {
5565 req , err := operatorRequest ("GET" , endpoint , nil , qParams )
5666 if err != nil {
5767 return nil , err
5868 }
59- return makeRequest (req )
69+ return httpsNoVerifyClient . makeRequest (req )
6070}
6171
6272func HTTPPostJSONData (endpoint string , requestData interface {}, qParams ... map [string ]string ) ([]byte , error ) {
@@ -74,7 +84,7 @@ func HTTPPostJSON(endpoint string, jsonRequestData []byte, qParams ...map[string
7484 return nil , err
7585 }
7686 req .Header .Set ("Content-Type" , "application/json" )
77- return makeRequest (req )
87+ return httpsNoVerifyClient . makeRequest (req )
7888}
7989
8090type HTTPUploadInput struct {
@@ -114,7 +124,7 @@ func HTTPUpload(endpoint string, input *HTTPUploadInput, qParams ...map[string]s
114124 }
115125
116126 req .Header .Set ("Content-Type" , writer .FormDataContentType ())
117- return makeRequest (req )
127+ return httpsNoVerifyClient . makeRequest (req )
118128}
119129
120130func addFileToMultipart (fileName string , writer * multipart.Writer , reader io.Reader ) error {
@@ -254,11 +264,11 @@ func operatorRequest(method string, endpoint string, body io.Reader, qParams []m
254264 return req , nil
255265}
256266
257- func makeRequest (request * http.Request ) ([]byte , error ) {
267+ func ( client * cortexClient ) makeRequest (request * http.Request ) ([]byte , error ) {
258268 request .Header .Set ("Authorization" , authHeader ())
259269 request .Header .Set ("CortexAPIVersion" , consts .CortexVersion )
260270
261- response , err := httpClient .Do (request )
271+ response , err := client .Do (request )
262272 if err != nil {
263273 cliConfig := getValidCliConfig ()
264274 return nil , ErrorFailedToConnect (cliConfig .CortexURL )
0 commit comments