Skip to content

Commit 69938bc

Browse files
Ivan Zhangdeliahu
authored andcommitted
Use HTTP for APIs by default (#350)
1 parent 68a8057 commit 69938bc

File tree

7 files changed

+27
-18
lines changed

7 files changed

+27
-18
lines changed

cli/cmd/get.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -464,7 +464,7 @@ func describeAPI(name string, resourcesRes *schema.GetResourcesResponse, flagVer
464464
apiEndpoint := urls.Join(resourcesRes.APIsBaseURL, anyAPIStatus.Path)
465465

466466
out := "\n" + console.Bold("url: ") + apiEndpoint + "\n"
467-
out += fmt.Sprintf("%s curl -k -X POST -H \"Content-Type: application/json\" %s -d @samples.json\n\n", console.Bold("curl:"), apiEndpoint)
467+
out += fmt.Sprintf("%s curl -X POST -H \"Content-Type: application/json\" %s -d @samples.json\n\n", console.Bold("curl:"), apiEndpoint)
468468
out += fmt.Sprintf(console.Bold("updated at:")+" %s\n", libtime.LocalTimestamp(updatedAt))
469469

470470
out += "\n"
@@ -554,7 +554,7 @@ func getModelInput(infoAPIPath string) (*schema.ModelInput, error) {
554554
return nil, errors.Wrap(err, "unable to request model input")
555555
}
556556
req.Header.Set("Content-Type", "application/json")
557-
response, err := makeRequest(req)
557+
response, err := httpsNoVerifyClient.makeRequest(req)
558558
if err != nil {
559559
return nil, err
560560
}

cli/cmd/lib_client.go

Lines changed: 20 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -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

5464
func 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

6272
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
7484
return nil, err
7585
}
7686
req.Header.Set("Content-Type", "application/json")
77-
return makeRequest(req)
87+
return httpsNoVerifyClient.makeRequest(req)
7888
}
7989

8090
type 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

120130
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
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)

cli/cmd/predict.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -185,7 +185,7 @@ func makePredictRequest(apiURL string, samplesJSONPath string) (*PredictResponse
185185
}
186186

187187
req.Header.Set("Content-Type", "application/json")
188-
httpResponse, err := makeRequest(req)
188+
httpResponse, err := httpClient.makeRequest(req)
189189
if err != nil {
190190
return nil, err
191191
}

docs/cluster/install.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ cortex get --watch
6060
cortex get tensorflow
6161

6262
# Classify a sample
63-
curl -k -X POST -H "Content-Type: application/json" \
63+
curl -X POST -H "Content-Type: application/json" \
6464
-d '{ "samples": [ { "sepal_length": 5.2, "sepal_width": 3.6, "petal_length": 1.4, "petal_width": 0.3 } ] }' \
6565
<API endpoint>
6666
```

docs/deployments/tutorial.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ $ cortex get --watch
4646
$ cortex get classifier
4747

4848
# Test the API
49-
$ curl -k -X POST -H "Content-Type: application/json" \
49+
$ curl -X POST -H "Content-Type: application/json" \
5050
-d '{ "samples": [ { "sepal_length": 5.2, "sepal_width": 3.6, "petal_length": 1.4, "petal_width": 0.3 } ] }' \
5151
<API endpoint>
5252
```

docs/pipelines/tutorial.md

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -111,8 +111,7 @@ $ cortex get api iris-type
111111
Use cURL to test the API:
112112

113113
```text
114-
$ curl -k \
115-
-X POST \
114+
$ curl -X POST \
116115
-H "Content-Type: application/json" \
117116
-d '{ "samples": [ { "sepal_length": 5.2, "sepal_width": 3.6, "petal_length": 1.4, "petal_width": 0.3 } ] }' \
118117
<API endpoint>

pkg/operator/workloads/api_workload.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -635,7 +635,7 @@ func APIsBaseURL() (string, error) {
635635
if len(service.Status.LoadBalancer.Ingress) == 0 {
636636
return "", ErrorLoadBalancerInitializing()
637637
}
638-
return "https://" + service.Status.LoadBalancer.Ingress[0].Hostname, nil
638+
return "http://" + service.Status.LoadBalancer.Ingress[0].Hostname, nil
639639
}
640640

641641
func APIPodComputeID(containers []kcore.Container) string {

0 commit comments

Comments
 (0)