Only validate this during prompt, not when reading from file
(endpoint string)
| 208 | |
| 209 | // Only validate this during prompt, not when reading from file |
| 210 | func 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 | |
| 257 | func getDefaultEnv() (*string, error) { |
| 258 | cliConfig, err := readCLIConfig() |
no test coverage detected