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

Function validateOperatorEndpoint

cli/cmd/lib_cli_config.go:210–255  ·  view source on GitHub ↗

Only validate this during prompt, not when reading from file

(endpoint string)

Source from the content-addressed store, hash-verified

208
209// Only validate this during prompt, not when reading from file
210func validateOperatorEndpoint(endpoint string) (string, error) {
211 url, err := cliconfig.CortexEndpointValidator(endpoint)
212 if err != nil {
213 return "", err
214 }
215
216 parsedURL, err := urls.Parse(url)
217 if err != nil {
218 return "", err
219 }
220
221 url = parsedURL.String()
222
223 req, err := http.NewRequest("GET", urls.Join(url, "/verifycortex"), nil)
224 if err != nil {
225 return "", errors.Wrap(err, "verifying operator endpoint", url)
226 }
227
228 client := http.Client{
229 Transport: &http.Transport{
230 TLSClientConfig: &tls.Config{InsecureSkipVerify: true},
231 },
232 }
233
234 response, err := client.Do(req)
235 if err != nil {
236 return "", ErrorInvalidOperatorEndpoint(url)
237 }
238 defer response.Body.Close()
239
240 if response.StatusCode != 200 {
241 return "", ErrorInvalidOperatorEndpoint(url)
242 }
243
244 bodyBytes, err := ioutil.ReadAll(response.Body)
245 if err != nil {
246 return "", errors.Wrap(err, _errStrRead)
247 }
248
249 var verifyCortex schema.VerifyCortexResponse
250 if err = json.Unmarshal(bodyBytes, &verifyCortex); err != nil {
251 return "", errors.Wrap(err, endpoint, string(bodyBytes))
252 }
253
254 return url, nil
255}
256
257func getDefaultEnv() (*string, error) {
258 cliConfig, err := readCLIConfig()

Callers 2

env.goFile · 0.85
promptEnvFunction · 0.85

Calls 7

CortexEndpointValidatorFunction · 0.92
ParseFunction · 0.92
JoinFunction · 0.92
WrapFunction · 0.92
UnmarshalFunction · 0.92
StringMethod · 0.45

Tested by

no test coverage detected