@@ -42,21 +42,31 @@ import (
42
42
"github.com/cortexlabs/cortex/pkg/operator/api/schema"
43
43
)
44
44
45
- var httpTransport = & http. Transport {
46
- TLSClientConfig : & tls. Config { InsecureSkipVerify : true },
45
+ type cortexClient struct {
46
+ * http. Client
47
47
}
48
48
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
+ },
52
62
}
53
63
54
64
func HTTPGet (endpoint string , qParams ... map [string ]string ) ([]byte , error ) {
55
65
req , err := operatorRequest ("GET" , endpoint , nil , qParams )
56
66
if err != nil {
57
67
return nil , err
58
68
}
59
- return makeRequest (req )
69
+ return httpsNoVerifyClient . makeRequest (req )
60
70
}
61
71
62
72
func HTTPPostJSONData (endpoint string , requestData interface {}, qParams ... map [string ]string ) ([]byte , error ) {
@@ -74,7 +84,7 @@ func HTTPPostJSON(endpoint string, jsonRequestData []byte, qParams ...map[string
74
84
return nil , err
75
85
}
76
86
req .Header .Set ("Content-Type" , "application/json" )
77
- return makeRequest (req )
87
+ return httpsNoVerifyClient . makeRequest (req )
78
88
}
79
89
80
90
type HTTPUploadInput struct {
@@ -114,7 +124,7 @@ func HTTPUpload(endpoint string, input *HTTPUploadInput, qParams ...map[string]s
114
124
}
115
125
116
126
req .Header .Set ("Content-Type" , writer .FormDataContentType ())
117
- return makeRequest (req )
127
+ return httpsNoVerifyClient . makeRequest (req )
118
128
}
119
129
120
130
func 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
254
264
return req , nil
255
265
}
256
266
257
- func makeRequest (request * http.Request ) ([]byte , error ) {
267
+ func ( client * cortexClient ) makeRequest (request * http.Request ) ([]byte , error ) {
258
268
request .Header .Set ("Authorization" , authHeader ())
259
269
request .Header .Set ("CortexAPIVersion" , consts .CortexVersion )
260
270
261
- response , err := httpClient .Do (request )
271
+ response , err := client .Do (request )
262
272
if err != nil {
263
273
cliConfig := getValidCliConfig ()
264
274
return nil , ErrorFailedToConnect (cliConfig .CortexURL )
0 commit comments