| 71 | } |
| 72 | |
| 73 | func waitForServer(ctx context.Context, url string) error { |
| 74 | ctx, cancel := context.WithTimeout(ctx, 3*time.Second) |
| 75 | defer cancel() |
| 76 | |
| 77 | req, err := http.NewRequestWithContext(ctx, http.MethodGet, url, http.NoBody) |
| 78 | if err != nil { |
| 79 | return err |
| 80 | } |
| 81 | |
| 82 | _, retryErr := backoff.Retry(ctx, func() (any, error) { |
| 83 | resp, err := http.DefaultClient.Do(req) |
| 84 | if err != nil { |
| 85 | return nil, err |
| 86 | } |
| 87 | defer resp.Body.Close() |
| 88 | _, _ = io.Copy(io.Discard, resp.Body) |
| 89 | if resp.StatusCode == http.StatusOK { |
| 90 | return nil, nil |
| 91 | } |
| 92 | return nil, fmt.Errorf("failed to connect to local server. error code: %d", resp.StatusCode) |
| 93 | }, backoff.WithBackOff(backoff.NewConstantBackOff(100*time.Millisecond))) |
| 94 | return retryErr |
| 95 | } |
| 96 | |
| 97 | func runLogin(ctx context.Context, cmd *cobra.Command) (err error) { |
| 98 | accountsURL := env.GetEnvOrDefault("CLOUDQUERY_ACCOUNTS_URL", defaultAccountsURL) |