Skip to content

Commit 44191d2

Browse files
committed
Revert "Use HTTP for APIs by default (#350)"
This reverts commit 69938bc.
1 parent cb8e01c commit 44191d2

File tree

7 files changed

+18
-27
lines changed

7 files changed

+18
-27
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 -X POST -H \"Content-Type: application/json\" %s -d @samples.json\n\n", console.Bold("curl:"), apiEndpoint)
467+
out += fmt.Sprintf("%s curl -k -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 := httpsNoVerifyClient.makeRequest(req)
557+
response, err := makeRequest(req)
558558
if err != nil {
559559
return nil, err
560560
}

cli/cmd/lib_client.go

Lines changed: 10 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -42,31 +42,21 @@ import (
4242
"github.com/cortexlabs/cortex/pkg/operator/api/schema"
4343
)
4444

45-
type cortexClient struct {
46-
*http.Client
45+
var httpTransport = &http.Transport{
46+
TLSClientConfig: &tls.Config{InsecureSkipVerify: true},
4747
}
4848

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-
},
49+
var httpClient = &http.Client{
50+
Timeout: time.Second * 20,
51+
Transport: httpTransport,
6252
}
6353

6454
func HTTPGet(endpoint string, qParams ...map[string]string) ([]byte, error) {
6555
req, err := operatorRequest("GET", endpoint, nil, qParams)
6656
if err != nil {
6757
return nil, err
6858
}
69-
return httpsNoVerifyClient.makeRequest(req)
59+
return makeRequest(req)
7060
}
7161

7262
func HTTPPostJSONData(endpoint string, requestData interface{}, qParams ...map[string]string) ([]byte, error) {
@@ -84,7 +74,7 @@ func HTTPPostJSON(endpoint string, jsonRequestData []byte, qParams ...map[string
8474
return nil, err
8575
}
8676
req.Header.Set("Content-Type", "application/json")
87-
return httpsNoVerifyClient.makeRequest(req)
77+
return makeRequest(req)
8878
}
8979

9080
type HTTPUploadInput struct {
@@ -124,7 +114,7 @@ func HTTPUpload(endpoint string, input *HTTPUploadInput, qParams ...map[string]s
124114
}
125115

126116
req.Header.Set("Content-Type", writer.FormDataContentType())
127-
return httpsNoVerifyClient.makeRequest(req)
117+
return makeRequest(req)
128118
}
129119

130120
func addFileToMultipart(fileName string, writer *multipart.Writer, reader io.Reader) error {
@@ -264,11 +254,11 @@ func operatorRequest(method string, endpoint string, body io.Reader, qParams []m
264254
return req, nil
265255
}
266256

267-
func (client *cortexClient) makeRequest(request *http.Request) ([]byte, error) {
257+
func makeRequest(request *http.Request) ([]byte, error) {
268258
request.Header.Set("Authorization", authHeader())
269259
request.Header.Set("CortexAPIVersion", consts.CortexVersion)
270260

271-
response, err := client.Do(request)
261+
response, err := httpClient.Do(request)
272262
if err != nil {
273263
cliConfig := getValidCliConfig()
274264
return nil, ErrorFailedToConnect(cliConfig.CortexURL)

cli/cmd/predict.go

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

171171
req.Header.Set("Content-Type", "application/json")
172-
httpResponse, err := httpClient.makeRequest(req)
172+
httpResponse, err := makeRequest(req)
173173
if err != nil {
174174
return nil, err
175175
}

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 -X POST -H "Content-Type: application/json" \
63+
curl -k -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 -X POST -H "Content-Type: application/json" \
49+
$ curl -k -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: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,8 @@ $ cortex get api iris-type
111111
Use cURL to test the API:
112112

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

pkg/operator/workloads/api_workload.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -573,7 +573,7 @@ func APIsBaseURL() (string, error) {
573573
if len(service.Status.LoadBalancer.Ingress) == 0 {
574574
return "", ErrorLoadBalancerInitializing()
575575
}
576-
return "http://" + service.Status.LoadBalancer.Ingress[0].Hostname, nil
576+
return "https://" + service.Status.LoadBalancer.Ingress[0].Hostname, nil
577577
}
578578

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

0 commit comments

Comments
 (0)