MCPcopy
hub / github.com/cortexlabs/cortex / makeOperatorRequest

Function makeOperatorRequest

cli/cluster/lib_http_client.go:173–234  ·  view source on GitHub ↗
(operatorConfig OperatorConfig, request *http.Request)

Source from the content-addressed store, hash-verified

171}
172
173func makeOperatorRequest(operatorConfig OperatorConfig, request *http.Request) ([]byte, error) {
174 if operatorConfig.Telemetry {
175 values := request.URL.Query()
176 values.Set("clientID", operatorConfig.ClientID)
177 request.URL.RawQuery = values.Encode()
178 }
179
180 request.Header.Set("CortexAPIVersion", consts.CortexVersion)
181 awsClient, err := aws.New()
182 if err != nil {
183 return nil, err
184 }
185
186 authHeader, err := awsClient.IdentityRequestAsHeader()
187 if err != nil {
188 return nil, err
189 }
190 request.Header.Set(consts.AuthHeader, authHeader)
191
192 timeout := 600 * time.Second
193 if request.URL.Path == "/info" {
194 timeout = 10 * time.Second
195 }
196
197 client := &http.Client{
198 Timeout: timeout,
199 Transport: &http.Transport{
200 TLSClientConfig: &tls.Config{InsecureSkipVerify: true},
201 },
202 }
203
204 response, err := client.Do(request)
205 if err != nil {
206 return nil, ErrorFailedToConnectOperator(err, operatorConfig.EnvName, operatorConfig.OperatorEndpoint)
207 }
208 defer response.Body.Close()
209
210 if response.StatusCode != 200 {
211 bodyBytes, err := ioutil.ReadAll(response.Body)
212 if err != nil {
213 return nil, errors.Wrap(err, _errStrRead)
214 }
215
216 var output schema.ErrorResponse
217 err = json.Unmarshal(bodyBytes, &output)
218 if err != nil || output.Message == "" {
219 return nil, ErrorOperatorResponseUnknown(string(bodyBytes), response.StatusCode)
220 }
221
222 return nil, errors.WithStack(&errors.Error{
223 Kind: output.Kind,
224 Message: output.Message,
225 NoTelemetry: true,
226 })
227 }
228
229 bodyBytes, err := ioutil.ReadAll(response.Body)
230 if err != nil {

Callers 5

HTTPGetFunction · 0.85
HTTPPostJSONFunction · 0.85
HTTPPostNoBodyFunction · 0.85
HTTPDeleteFunction · 0.85
HTTPUploadFunction · 0.85

Calls 8

NewFunction · 0.92
WrapFunction · 0.92
UnmarshalFunction · 0.92
WithStackFunction · 0.92
SetMethod · 0.80

Tested by

no test coverage detected