Skip to content

http default support #350

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Aug 19, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions cli/cmd/get.go
Original file line number Diff line number Diff line change
Expand Up @@ -464,7 +464,7 @@ func describeAPI(name string, resourcesRes *schema.GetResourcesResponse, flagVer
apiEndpoint := urls.Join(resourcesRes.APIsBaseURL, anyAPIStatus.Path)

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

out += "\n"
Expand Down Expand Up @@ -554,7 +554,7 @@ func getModelInput(infoAPIPath string) (*schema.ModelInput, error) {
return nil, errors.Wrap(err, "unable to request model input")
}
req.Header.Set("Content-Type", "application/json")
response, err := makeRequest(req)
response, err := httpsNoVerifyClient.makeRequest(req)
if err != nil {
return nil, err
}
Expand Down
30 changes: 20 additions & 10 deletions cli/cmd/lib_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,21 +42,31 @@ import (
"github.com/cortexlabs/cortex/pkg/operator/api/schema"
)

var httpTransport = &http.Transport{
TLSClientConfig: &tls.Config{InsecureSkipVerify: true},
type cortexClient struct {
*http.Client
}

var httpClient = &http.Client{
Timeout: time.Second * 20,
Transport: httpTransport,
var httpClient = &cortexClient{
Client: &http.Client{
Timeout: time.Second * 20,
},
}

var httpsNoVerifyClient = &cortexClient{
Client: &http.Client{
Timeout: time.Second * 20,
Transport: &http.Transport{
TLSClientConfig: &tls.Config{InsecureSkipVerify: true},
},
},
}

func HTTPGet(endpoint string, qParams ...map[string]string) ([]byte, error) {
req, err := operatorRequest("GET", endpoint, nil, qParams)
if err != nil {
return nil, err
}
return makeRequest(req)
return httpsNoVerifyClient.makeRequest(req)
}

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

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

req.Header.Set("Content-Type", writer.FormDataContentType())
return makeRequest(req)
return httpsNoVerifyClient.makeRequest(req)
}

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

func makeRequest(request *http.Request) ([]byte, error) {
func (client *cortexClient) makeRequest(request *http.Request) ([]byte, error) {
request.Header.Set("Authorization", authHeader())
request.Header.Set("CortexAPIVersion", consts.CortexVersion)

response, err := httpClient.Do(request)
response, err := client.Do(request)
if err != nil {
cliConfig := getValidCliConfig()
return nil, ErrorFailedToConnect(cliConfig.CortexURL)
Expand Down
2 changes: 1 addition & 1 deletion cli/cmd/predict.go
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@ func makePredictRequest(apiURL string, samplesJSONPath string) (*PredictResponse
}

req.Header.Set("Content-Type", "application/json")
httpResponse, err := makeRequest(req)
httpResponse, err := httpClient.makeRequest(req)
if err != nil {
return nil, err
}
Expand Down
2 changes: 1 addition & 1 deletion docs/cluster/install.md
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ cortex get --watch
cortex get tensorflow

# Classify a sample
curl -k -X POST -H "Content-Type: application/json" \
curl -X POST -H "Content-Type: application/json" \
-d '{ "samples": [ { "sepal_length": 5.2, "sepal_width": 3.6, "petal_length": 1.4, "petal_width": 0.3 } ] }' \
<API endpoint>
```
Expand Down
2 changes: 1 addition & 1 deletion docs/deployments/tutorial.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ $ cortex get --watch
$ cortex get classifier

# Test the API
$ curl -k -X POST -H "Content-Type: application/json" \
$ curl -X POST -H "Content-Type: application/json" \
-d '{ "samples": [ { "sepal_length": 5.2, "sepal_width": 3.6, "petal_length": 1.4, "petal_width": 0.3 } ] }' \
<API endpoint>
```
Expand Down
3 changes: 1 addition & 2 deletions docs/pipelines/tutorial.md
Original file line number Diff line number Diff line change
Expand Up @@ -111,8 +111,7 @@ $ cortex get api iris-type
Use cURL to test the API:

```text
$ curl -k \
-X POST \
$ curl -X POST \
-H "Content-Type: application/json" \
-d '{ "samples": [ { "sepal_length": 5.2, "sepal_width": 3.6, "petal_length": 1.4, "petal_width": 0.3 } ] }' \
<API endpoint>
Expand Down
2 changes: 1 addition & 1 deletion pkg/operator/workloads/api_workload.go
Original file line number Diff line number Diff line change
Expand Up @@ -635,7 +635,7 @@ func APIsBaseURL() (string, error) {
if len(service.Status.LoadBalancer.Ingress) == 0 {
return "", ErrorLoadBalancerInitializing()
}
return "https://" + service.Status.LoadBalancer.Ingress[0].Hostname, nil
return "http://" + service.Status.LoadBalancer.Ingress[0].Hostname, nil
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should tell you somewhere in the docs that you can use https (and that it will use a cert that we generated on install), can you add that? Omer should have an opinion on where to add it in the docs.

}

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