|
4 | 4 | Relies on the Helm class for deployment aspects. |
5 | 5 | """ |
6 | 6 |
|
| 7 | +import os |
7 | 8 | import re |
8 | 9 | import webbrowser |
9 | 10 | from datetime import datetime |
10 | 11 | from pathlib import Path |
11 | 12 | from time import sleep |
12 | 13 |
|
13 | 14 | import polars |
| 15 | +import typer |
14 | 16 | from ruamel.yaml import YAML |
15 | 17 |
|
16 | 18 | from edge_containers_cli import globals |
|
20 | 22 | ServicesDataFrame, |
21 | 23 | ServicesSchema, |
22 | 24 | ) |
23 | | -from edge_containers_cli.definitions import ECContext |
| 25 | +from edge_containers_cli.definitions import ENV, ECContext |
24 | 26 | from edge_containers_cli.git import check_exists, del_key, set_value |
25 | 27 | from edge_containers_cli.logging import log |
26 | 28 | from edge_containers_cli.shell import ShellError, shell |
@@ -279,12 +281,26 @@ def _validate_target(self): |
279 | 281 | """ |
280 | 282 | Verify we have a good namespace that exists in the cluster |
281 | 283 | """ |
| 284 | + retries = 2 |
| 285 | + |
282 | 286 | cmd = f"argocd app get {self._target}" |
283 | 287 | try: |
284 | 288 | shell.run_command(cmd, error_OK=False) |
285 | 289 | except ShellError as e: |
286 | | - if "code = Unauthenticated" in str(e): |
287 | | - raise CommandError("Not authenticated to argocd server") from e |
| 290 | + if "Unauthenticated" in str(e) or "unspecified" in str(e): |
| 291 | + retries -= 1 |
| 292 | + login = os.environ.get(ENV.login.value) |
| 293 | + if retries <= 0 or not login: |
| 294 | + raise CommandError("Not authenticated to argocd server") from e |
| 295 | + |
| 296 | + # try to log in |
| 297 | + if not login or not typer.confirm("Login to ArgoCD?", default=True): |
| 298 | + raise typer.Abort() from e |
| 299 | + shell.run_command(login, error_OK=False, skip_on_dryrun=True) |
| 300 | + |
| 301 | + # retry validation |
| 302 | + self._validate_target() |
| 303 | + |
288 | 304 | elif "code = PermissionDenied" in str(e): |
289 | 305 | raise CommandError(f"Target '{self._target}' not found") from e |
290 | 306 | else: |
|
0 commit comments