doover-cli 0.6.8__tar.gz → 0.7.1__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (101) hide show
  1. {doover_cli-0.6.8 → doover_cli-0.7.1}/PKG-INFO +2 -1
  2. {doover_cli-0.6.8 → doover_cli-0.7.1}/pyproject.toml +2 -1
  3. doover_cli-0.7.1/src/doover_cli/__init__.py +16 -0
  4. {doover_cli-0.6.8 → doover_cli-0.7.1}/src/doover_cli/apps/apps.py +147 -0
  5. {doover_cli-0.6.8 → doover_cli-0.7.1}/src/doover_cli/apps/tunnel.py +70 -176
  6. doover_cli-0.6.8/src/doover_cli/__init__.py → doover_cli-0.7.1/src/doover_cli/cli.py +9 -4
  7. doover_cli-0.7.1/src/doover_cli/entry.py +13 -0
  8. doover_cli-0.7.1/src/doover_cli/tunnel_exec.py +62 -0
  9. {doover_cli-0.6.8 → doover_cli-0.7.1}/src/doover_cli/utils/apps.py +92 -1
  10. {doover_cli-0.6.8 → doover_cli-0.7.1}/tests/test_apps.py +68 -0
  11. {doover_cli-0.6.8 → doover_cli-0.7.1}/tests/test_sentry.py +20 -21
  12. doover_cli-0.7.1/tests/test_tunnel_exec.py +28 -0
  13. {doover_cli-0.6.8 → doover_cli-0.7.1}/tests/test_utils_apps.py +130 -0
  14. {doover_cli-0.6.8 → doover_cli-0.7.1}/uv.lock +13 -0
  15. {doover_cli-0.6.8 → doover_cli-0.7.1}/.github/CONTRIBUTING.md +0 -0
  16. {doover_cli-0.6.8 → doover_cli-0.7.1}/.github/ISSUE_TEMPLATE/bug-report.yaml +0 -0
  17. {doover_cli-0.6.8 → doover_cli-0.7.1}/.github/ISSUE_TEMPLATE/config.yml +0 -0
  18. {doover_cli-0.6.8 → doover_cli-0.7.1}/.github/ISSUE_TEMPLATE/feature-request.yml +0 -0
  19. {doover_cli-0.6.8 → doover_cli-0.7.1}/.github/PULL_REQUEST_TEMPLATE.md +0 -0
  20. {doover_cli-0.6.8 → doover_cli-0.7.1}/.github/workflows/lint-test.yml +0 -0
  21. {doover_cli-0.6.8 → doover_cli-0.7.1}/.github/workflows/release-brew.yml +0 -0
  22. {doover_cli-0.6.8 → doover_cli-0.7.1}/.github/workflows/release-pypi.yml +0 -0
  23. {doover_cli-0.6.8 → doover_cli-0.7.1}/.github/workflows/release.yml +0 -0
  24. {doover_cli-0.6.8 → doover_cli-0.7.1}/.gitignore +0 -0
  25. {doover_cli-0.6.8 → doover_cli-0.7.1}/.pre-commit-config.yaml +0 -0
  26. {doover_cli-0.6.8 → doover_cli-0.7.1}/AGENT.md +0 -0
  27. {doover_cli-0.6.8 → doover_cli-0.7.1}/LICENSE +0 -0
  28. {doover_cli-0.6.8 → doover_cli-0.7.1}/README.md +0 -0
  29. {doover_cli-0.6.8 → doover_cli-0.7.1}/debian/changelog +0 -0
  30. {doover_cli-0.6.8 → doover_cli-0.7.1}/debian/control +0 -0
  31. {doover_cli-0.6.8 → doover_cli-0.7.1}/debian/rules +0 -0
  32. {doover_cli-0.6.8 → doover_cli-0.7.1}/docs/user_stories.md +0 -0
  33. {doover_cli-0.6.8 → doover_cli-0.7.1}/src/doover_cli/agent.py +0 -0
  34. {doover_cli-0.6.8 → doover_cli-0.7.1}/src/doover_cli/api/__init__.py +0 -0
  35. {doover_cli-0.6.8 → doover_cli-0.7.1}/src/doover_cli/api/auth.py +0 -0
  36. {doover_cli-0.6.8 → doover_cli-0.7.1}/src/doover_cli/api/errors.py +0 -0
  37. {doover_cli-0.6.8 → doover_cli-0.7.1}/src/doover_cli/api/session.py +0 -0
  38. {doover_cli-0.6.8 → doover_cli-0.7.1}/src/doover_cli/apps/app_install.py +0 -0
  39. {doover_cli-0.6.8 → doover_cli-0.7.1}/src/doover_cli/apps/device.py +0 -0
  40. {doover_cli-0.6.8 → doover_cli-0.7.1}/src/doover_cli/apps/device_type.py +0 -0
  41. {doover_cli-0.6.8 → doover_cli-0.7.1}/src/doover_cli/apps/migrate.py +0 -0
  42. {doover_cli-0.6.8 → doover_cli-0.7.1}/src/doover_cli/apps/widget_plugin.py +0 -0
  43. {doover_cli-0.6.8 → doover_cli-0.7.1}/src/doover_cli/channel.py +0 -0
  44. {doover_cli-0.6.8 → doover_cli-0.7.1}/src/doover_cli/colours.py +0 -0
  45. {doover_cli-0.6.8 → doover_cli-0.7.1}/src/doover_cli/config_schema.py +0 -0
  46. {doover_cli-0.6.8 → doover_cli-0.7.1}/src/doover_cli/dda_logs.py +0 -0
  47. {doover_cli-0.6.8 → doover_cli-0.7.1}/src/doover_cli/doover_config.py +0 -0
  48. {doover_cli-0.6.8 → doover_cli-0.7.1}/src/doover_cli/grpc.py +0 -0
  49. {doover_cli-0.6.8 → doover_cli-0.7.1}/src/doover_cli/login.py +0 -0
  50. {doover_cli-0.6.8 → doover_cli-0.7.1}/src/doover_cli/notification_schema.py +0 -0
  51. {doover_cli-0.6.8 → doover_cli-0.7.1}/src/doover_cli/registry.py +0 -0
  52. {doover_cli-0.6.8 → doover_cli-0.7.1}/src/doover_cli/renderer/__init__.py +0 -0
  53. {doover_cli-0.6.8 → doover_cli-0.7.1}/src/doover_cli/renderer/_base.py +0 -0
  54. {doover_cli-0.6.8 → doover_cli-0.7.1}/src/doover_cli/renderer/_basic.py +0 -0
  55. {doover_cli-0.6.8 → doover_cli-0.7.1}/src/doover_cli/renderer/_default.py +0 -0
  56. {doover_cli-0.6.8 → doover_cli-0.7.1}/src/doover_cli/renderer/_json.py +0 -0
  57. {doover_cli-0.6.8 → doover_cli-0.7.1}/src/doover_cli/report.py +0 -0
  58. {doover_cli-0.6.8 → doover_cli-0.7.1}/src/doover_cli/simulator.py +0 -0
  59. {doover_cli-0.6.8 → doover_cli-0.7.1}/src/doover_cli/ui_schema.py +0 -0
  60. {doover_cli-0.6.8 → doover_cli-0.7.1}/src/doover_cli/user.py +0 -0
  61. {doover_cli-0.6.8 → doover_cli-0.7.1}/src/doover_cli/utils/__init__.py +0 -0
  62. {doover_cli-0.6.8 → doover_cli-0.7.1}/src/doover_cli/utils/api.py +0 -0
  63. {doover_cli-0.6.8 → doover_cli-0.7.1}/src/doover_cli/utils/context.py +0 -0
  64. {doover_cli-0.6.8 → doover_cli-0.7.1}/src/doover_cli/utils/crud/__init__.py +0 -0
  65. {doover_cli-0.6.8 → doover_cli-0.7.1}/src/doover_cli/utils/crud/commands.py +0 -0
  66. {doover_cli-0.6.8 → doover_cli-0.7.1}/src/doover_cli/utils/crud/lookup.py +0 -0
  67. {doover_cli-0.6.8 → doover_cli-0.7.1}/src/doover_cli/utils/crud/prompting.py +0 -0
  68. {doover_cli-0.6.8 → doover_cli-0.7.1}/src/doover_cli/utils/crud/schema.py +0 -0
  69. {doover_cli-0.6.8 → doover_cli-0.7.1}/src/doover_cli/utils/crud/values.py +0 -0
  70. {doover_cli-0.6.8 → doover_cli-0.7.1}/src/doover_cli/utils/errors.py +0 -0
  71. {doover_cli-0.6.8 → doover_cli-0.7.1}/src/doover_cli/utils/formatters.py +0 -0
  72. {doover_cli-0.6.8 → doover_cli-0.7.1}/src/doover_cli/utils/misc.py +0 -0
  73. {doover_cli-0.6.8 → doover_cli-0.7.1}/src/doover_cli/utils/parsers.py +0 -0
  74. {doover_cli-0.6.8 → doover_cli-0.7.1}/src/doover_cli/utils/prompt.py +0 -0
  75. {doover_cli-0.6.8 → doover_cli-0.7.1}/src/doover_cli/utils/sentry.py +0 -0
  76. {doover_cli-0.6.8 → doover_cli-0.7.1}/src/doover_cli/utils/shell_commands.py +0 -0
  77. {doover_cli-0.6.8 → doover_cli-0.7.1}/src/doover_cli/utils/state.py +0 -0
  78. {doover_cli-0.6.8 → doover_cli-0.7.1}/tests/__init__.py +0 -0
  79. {doover_cli-0.6.8 → doover_cli-0.7.1}/tests/conftest.py +0 -0
  80. {doover_cli-0.6.8 → doover_cli-0.7.1}/tests/test_agent.py +0 -0
  81. {doover_cli-0.6.8 → doover_cli-0.7.1}/tests/test_app_install.py +0 -0
  82. {doover_cli-0.6.8 → doover_cli-0.7.1}/tests/test_auth_integration.py +0 -0
  83. {doover_cli-0.6.8 → doover_cli-0.7.1}/tests/test_auth_unit.py +0 -0
  84. {doover_cli-0.6.8 → doover_cli-0.7.1}/tests/test_basic.py +0 -0
  85. {doover_cli-0.6.8 → doover_cli-0.7.1}/tests/test_crud_commands.py +0 -0
  86. {doover_cli-0.6.8 → doover_cli-0.7.1}/tests/test_crud_lookup.py +0 -0
  87. {doover_cli-0.6.8 → doover_cli-0.7.1}/tests/test_crud_prompting.py +0 -0
  88. {doover_cli-0.6.8 → doover_cli-0.7.1}/tests/test_crud_schema.py +0 -0
  89. {doover_cli-0.6.8 → doover_cli-0.7.1}/tests/test_crud_values.py +0 -0
  90. {doover_cli-0.6.8 → doover_cli-0.7.1}/tests/test_default_renderer.py +0 -0
  91. {doover_cli-0.6.8 → doover_cli-0.7.1}/tests/test_device.py +0 -0
  92. {doover_cli-0.6.8 → doover_cli-0.7.1}/tests/test_device_cli_integration.py +0 -0
  93. {doover_cli-0.6.8 → doover_cli-0.7.1}/tests/test_device_type.py +0 -0
  94. {doover_cli-0.6.8 → doover_cli-0.7.1}/tests/test_device_type_cli_integration.py +0 -0
  95. {doover_cli-0.6.8 → doover_cli-0.7.1}/tests/test_discover.py +0 -0
  96. {doover_cli-0.6.8 → doover_cli-0.7.1}/tests/test_migrate.py +0 -0
  97. {doover_cli-0.6.8 → doover_cli-0.7.1}/tests/test_prompt.py +0 -0
  98. {doover_cli-0.6.8 → doover_cli-0.7.1}/tests/test_registry.py +0 -0
  99. {doover_cli-0.6.8 → doover_cli-0.7.1}/tests/test_schema_export.py +0 -0
  100. {doover_cli-0.6.8 → doover_cli-0.7.1}/tests/test_user.py +0 -0
  101. {doover_cli-0.6.8 → doover_cli-0.7.1}/tests/test_widget_plugin.py +0 -0
@@ -1,12 +1,13 @@
1
1
  Metadata-Version: 2.5
2
2
  Name: doover-cli
3
- Version: 0.6.8
3
+ Version: 0.7.1
4
4
  Summary: CLI for Doover
5
5
  License-File: LICENSE
6
6
  Requires-Python: >=3.11
7
7
  Requires-Dist: click-prompt>=0.6.3
8
8
  Requires-Dist: click>=8.3.1
9
9
  Requires-Dist: docker>=7.1.0
10
+ Requires-Dist: doover-tunnel<0.2,>=0.1.2
10
11
  Requires-Dist: jsf>=0.11.2
11
12
  Requires-Dist: paramiko>=3.5.1
12
13
  Requires-Dist: prompt-toolkit>=3.0.52
@@ -11,6 +11,7 @@ dependencies = [
11
11
  "jsf>=0.11.2",
12
12
  "paramiko>=3.5.1",
13
13
  "pydoover>=1.17.1",
14
+ "doover-tunnel>=0.1.2,<0.2",
14
15
  "pytz>=2025.2",
15
16
  "questionary>=1.10.0",
16
17
  "requests>=2.32.3",
@@ -30,7 +31,7 @@ build-backend = "hatchling.build"
30
31
  path = "src/doover_cli/__init__.py"
31
32
 
32
33
  [project.scripts]
33
- doover = "doover_cli:main"
34
+ doover = "doover_cli.entry:main"
34
35
  docker-credential-doover = "doover_cli.registry:credential_helper"
35
36
 
36
37
  [dependency-groups]
@@ -0,0 +1,16 @@
1
+ """Doover CLI.
2
+
3
+ Importing the package is deliberately cheap: `entry.main` hands `doover ssh`
4
+ and `doover tunnel` to the doover-tunnel binary before `cli` (typer, pydoover,
5
+ docker, ...) loads. `app` and `main` are still reachable here, lazily.
6
+ """
7
+
8
+ __version__ = "0.7.1"
9
+
10
+
11
+ def __getattr__(name: str):
12
+ if name in ("app", "main", "sentry_utils"):
13
+ from . import cli
14
+
15
+ return getattr(cli, name)
16
+ raise AttributeError(f"module {__name__!r} has no attribute {name!r}")
@@ -33,6 +33,7 @@ from ..registry import is_doover_registry, login_for_push, publish_github_output
33
33
  from ..utils.apps import (
34
34
  PACKAGE_APP_TYPES,
35
35
  discover_apps,
36
+ filter_create_only,
36
37
  get_app_directory,
37
38
  call_with_uv,
38
39
  get_docker_path,
@@ -128,6 +129,67 @@ def _detect_git_commit(root_fp: Path) -> str:
128
129
  return result.stdout.strip() if result.returncode == 0 else ""
129
130
 
130
131
 
132
+ def _normalise_remote_url(remote: str) -> str | None:
133
+ """A git remote as a browsable https URL, or None if it isn't one.
134
+
135
+ Remotes here are SSH by convention, which is not a URL anyone can open, and
136
+ the field is rendered as a link.
137
+ """
138
+ remote = remote.strip()
139
+ if not remote:
140
+ return None
141
+
142
+ # scp-style: git@host:org/repo.git
143
+ if "://" not in remote and ":" in remote and not remote.startswith("/"):
144
+ userhost, _, path = remote.partition(":")
145
+ host = userhost.rpartition("@")[2]
146
+ if not host or not path:
147
+ return None
148
+ remote = f"https://{host}/{path}"
149
+ elif remote.startswith(("ssh://", "git://")):
150
+ remote = "https://" + remote.split("://", 1)[1]
151
+ elif not remote.startswith(("http://", "https://")):
152
+ # A local path or a protocol nothing can browse.
153
+ return None
154
+
155
+ scheme, _, rest = remote.partition("://")
156
+ # Strip credentials -- a token embedded in a CI checkout's remote must not
157
+ # be published.
158
+ rest = rest.rpartition("@")[2]
159
+ remote = f"{scheme}://{rest}"
160
+
161
+ if remote.endswith(".git"):
162
+ remote = remote[: -len(".git")]
163
+ remote = remote.rstrip("/")
164
+ return remote or None
165
+
166
+
167
+ def _detect_repository_url(root_fp: Path) -> str | None:
168
+ """Best-effort repository URL for the app dir, from CI or `origin`."""
169
+ server = os.environ.get("GITHUB_SERVER_URL")
170
+ repository = os.environ.get("GITHUB_REPOSITORY")
171
+ if server and repository:
172
+ return f"{server.rstrip('/')}/{repository}"
173
+
174
+ project_url = os.environ.get("CI_PROJECT_URL")
175
+ if project_url:
176
+ return project_url.rstrip("/")
177
+
178
+ try:
179
+ result = subprocess.run(
180
+ ["git", "remote", "get-url", "origin"],
181
+ cwd=root_fp,
182
+ capture_output=True,
183
+ text=True,
184
+ check=False,
185
+ )
186
+ except OSError:
187
+ return None
188
+ if result.returncode != 0:
189
+ return None
190
+ return _normalise_remote_url(result.stdout)
191
+
192
+
131
193
  def _is_multi_platform(build_args: str) -> bool:
132
194
  """Whether `build_args` asks for more than one platform.
133
195
 
@@ -456,6 +518,47 @@ def _resolve_application_id(client, app_config, *, staging: bool) -> int | None:
456
518
  return None
457
519
 
458
520
 
521
+ def _fetch_existing_application(client, app_config, *, staging: bool):
522
+ """The app as the cloud currently holds it, or None if it doesn't exist yet.
523
+
524
+ Publishing is a patch, and some fields are only seeded on create -- see
525
+ CREATE_ONLY_FIELDS -- so the payload can't be decided without knowing what is
526
+ already there.
527
+ """
528
+ app_id = _get_persisted_application_id(app_config, staging=staging)
529
+ if app_id is not None:
530
+ try:
531
+ return client.applications.retrieve(str(app_id))
532
+ except Exception:
533
+ # A pinned id that doesn't resolve is the publish's problem, not
534
+ # ours; it fails with a clearer error a few lines later.
535
+ return None
536
+
537
+ try:
538
+ page = client.applications.list(
539
+ name=app_config.name,
540
+ archived=False,
541
+ page=1,
542
+ per_page=100,
543
+ )
544
+ except Exception:
545
+ return None
546
+
547
+ matches = [
548
+ item for item in page.results if getattr(item, "name", None) == app_config.name
549
+ ]
550
+ return matches[0] if len(matches) == 1 else None
551
+
552
+
553
+ def _report_create_only_skips(skipped: dict) -> None:
554
+ for field, (cloud_value, config_value) in sorted(skipped.items()):
555
+ rich.print(
556
+ f"[yellow]{field}: keeping {cloud_value!r} from the cloud "
557
+ f"(doover_config.json says {config_value!r}). This field is only "
558
+ f"seeded on create -- change it in the admin portal.[/yellow]"
559
+ )
560
+
561
+
459
562
  def _image_package_uri(app_config) -> str | None:
460
563
  """The ECR image a processor deploys from, or None if it ships a package.zip.
461
564
 
@@ -1183,6 +1286,13 @@ def publish(
1183
1286
  help="Upload the widget when publishing. Disable with --no-put-widget.",
1184
1287
  ),
1185
1288
  ] = True,
1289
+ put_artwork: Annotated[
1290
+ bool,
1291
+ typer.Option(
1292
+ help="Upload the icon and banner when publishing. "
1293
+ "Disable with --no-put-artwork.",
1294
+ ),
1295
+ ] = True,
1186
1296
  build_package: Annotated[
1187
1297
  bool,
1188
1298
  typer.Option(
@@ -1295,6 +1405,13 @@ def publish(
1295
1405
  include_deployment_data=True,
1296
1406
  )
1297
1407
 
1408
+ # Seeded from the checkout when doover_config.json doesn't name one. It is
1409
+ # create-only, so a detected value never overwrites what the cloud holds.
1410
+ if "repository_url" not in payload:
1411
+ detected_repository = _detect_repository_url(root_fp)
1412
+ if detected_repository:
1413
+ payload["repository_url"] = detected_repository
1414
+
1298
1415
  client, renderer = get_state()
1299
1416
 
1300
1417
  # The publish endpoints are organisation-scoped: without the
@@ -1322,6 +1439,13 @@ def publish(
1322
1439
  f"Updating application on doover site ({_control_base_url() or 'unknown base URL'})...\n"
1323
1440
  )
1324
1441
 
1442
+ with renderer.loading("Reading current application..."):
1443
+ existing = _fetch_existing_application(
1444
+ client, app_config, staging=resolved_staging
1445
+ )
1446
+ payload, skipped = filter_create_only(payload, existing)
1447
+ _report_create_only_skips(skipped)
1448
+
1325
1449
  try:
1326
1450
  with renderer.loading("Publishing application..."):
1327
1451
  application_id = _get_persisted_application_id(
@@ -1375,6 +1499,29 @@ def publish(
1375
1499
  )
1376
1500
  rich.print("[green]Widget uploaded.[/green]")
1377
1501
 
1502
+ artwork = {
1503
+ kind: path
1504
+ for kind, path in (
1505
+ ("icon", app_config.icon_path),
1506
+ ("banner", app_config.banner_path),
1507
+ )
1508
+ if path is not None
1509
+ }
1510
+ if artwork and put_artwork:
1511
+ for kind, path in artwork.items():
1512
+ if not path.exists():
1513
+ rich.print(f"[red]{kind.title()} file not found at {path}.[/red]")
1514
+ raise typer.Exit(1)
1515
+
1516
+ with renderer.loading("Uploading artwork..."):
1517
+ client.upload_application_artwork(
1518
+ str(application_id),
1519
+ **artwork,
1520
+ )
1521
+ rich.print(
1522
+ f"[green]{', '.join(sorted(artwork)).capitalize()} uploaded.[/green]"
1523
+ )
1524
+
1378
1525
  if app_config.type in PACKAGE_APP_TYPES:
1379
1526
  image_uri = _image_package_uri(app_config)
1380
1527
  if image_uri:
@@ -10,10 +10,7 @@ from ..utils.api import (
10
10
  )
11
11
  from ..utils.crud import (
12
12
  LookupChoice,
13
- build_create_command,
14
- build_update_command,
15
13
  prompt_resource,
16
- resource_autocomplete,
17
14
  )
18
15
  from ..utils.crud.lookup import resolve_resource_lookup
19
16
  from ..utils.crud.prompting import (
@@ -27,6 +24,7 @@ from ..utils.crud.values import (
27
24
  extract_model_values,
28
25
  normalize_model_values,
29
26
  )
27
+ from ..tunnel_exec import INSTALL_HINT, exec_binary, find_binary
30
28
  from ..utils.state import state
31
29
 
32
30
  if TYPE_CHECKING:
@@ -34,7 +32,6 @@ if TYPE_CHECKING:
34
32
  from ..renderer import RendererBase
35
33
 
36
34
 
37
- app = typer.Typer(no_args_is_help=True)
38
35
  device_app = typer.Typer(no_args_is_help=True)
39
36
 
40
37
  _TUNNEL_LABEL_ATTRS = ("name",)
@@ -46,36 +43,6 @@ def get_state() -> tuple["ControlClient", "RendererBase"]:
46
43
  return session.get_control_client(), state.renderer
47
44
 
48
45
 
49
- def _tunnel_autocomplete() -> object:
50
- return resource_autocomplete(
51
- Tunnel,
52
- archived=None,
53
- ordering="name",
54
- label_attrs=_TUNNEL_LABEL_ATTRS,
55
- searchable_attrs=_TUNNEL_LABEL_ATTRS,
56
- )
57
-
58
-
59
- def _resolve_tunnel_id(
60
- client: "ControlClient",
61
- renderer: "RendererBase",
62
- *,
63
- action: str,
64
- lookup: str | None,
65
- ) -> int:
66
- return prompt_resource(
67
- Tunnel,
68
- client,
69
- renderer,
70
- action=action,
71
- lookup=lookup,
72
- archived=None,
73
- ordering="name",
74
- label_attrs=_TUNNEL_LABEL_ATTRS,
75
- searchable_attrs=_TUNNEL_LABEL_ATTRS,
76
- )
77
-
78
-
79
46
  def _resolve_device_context_id(
80
47
  client: "ControlClient",
81
48
  renderer: "RendererBase",
@@ -230,174 +197,101 @@ def _resolve_device_tunnel_id(
230
197
 
231
198
 
232
199
  # ---------------------------------------------------------------------------
233
- # Top-level: doover tunnel ...
200
+ # Top-level: doover tunnel <device> [tunnel]
201
+ #
202
+ # With a device argument these never run: the console entry point execs the
203
+ # binary before the CLI loads (tunnel_exec). They remain for the bare form,
204
+ # which prompts for the device, and for global options before the verb.
234
205
  # ---------------------------------------------------------------------------
235
206
 
236
207
 
237
- @app.command(name="list")
238
- def list_(
239
- ordering: Annotated[
240
- str | None,
241
- typer.Option(
242
- help="Sort expression passed directly to the API, for example name or -name.",
243
- ),
244
- ] = None,
245
- page: Annotated[int | None, typer.Option(help="Page number to request.")] = None,
246
- per_page: Annotated[
247
- int | None, typer.Option("--per-page", help="Number of records per page.")
248
- ] = None,
249
- search: Annotated[str | None, typer.Option(help="Full-text search term.")] = None,
250
- _profile: ProfileAnnotation = None,
251
- ):
252
- """List tunnels across all devices you can access."""
253
- _ = _profile
254
- client, renderer = get_state()
208
+ def _doover_tunnel_binary() -> str:
209
+ found = find_binary()
210
+ if found is None:
211
+ raise typer.BadParameter(INSTALL_HINT)
212
+ return found
255
213
 
256
- with renderer.loading("Loading tunnels..."):
257
- response = client.tunnels.list(
258
- ordering=ordering,
259
- page=page,
260
- per_page=per_page,
261
- search=search,
262
- )
263
214
 
264
- renderer.render_list(response)
265
-
266
-
267
- @app.command()
268
- def get(
269
- tunnel: Annotated[
215
+ def connect(
216
+ ctx: typer.Context,
217
+ device: Annotated[
270
218
  str | None,
271
- typer.Argument(
272
- help="Tunnel ID or exact name to retrieve.",
273
- autocompletion=_tunnel_autocomplete(),
274
- ),
219
+ typer.Argument(help="Device ID or exact display name/name."),
275
220
  ] = None,
276
- _profile: ProfileAnnotation = None,
277
- ):
278
- """Get a tunnel by ID or name."""
279
- _ = _profile
280
- client, renderer = get_state()
281
-
282
- resolved_id = _resolve_tunnel_id(
283
- client,
284
- renderer,
285
- action="get",
286
- lookup=tunnel,
287
- )
288
-
289
- with renderer.loading("Loading tunnel..."):
290
- response = client.tunnels.retrieve(str(resolved_id))
291
-
292
- renderer.render(response)
293
-
294
-
295
- create = build_create_command(
296
- model_cls=Tunnel,
297
- command_help="Create a tunnel.",
298
- get_state=lambda: get_state(),
299
- )
300
- app.command()(create)
301
-
302
-
303
- update = build_update_command(
304
- model_cls=Tunnel,
305
- command_help="Update a tunnel.",
306
- get_state=lambda: get_state(),
307
- resource_id_param_name="tunnel",
308
- resource_id_help="Tunnel ID or exact name to update.",
309
- )
310
- app.command()(update)
311
-
312
-
313
- @app.command()
314
- def delete(
315
221
  tunnel: Annotated[
316
222
  str | None,
317
223
  typer.Argument(
318
- help="Tunnel ID or exact name to delete.",
319
- autocompletion=_tunnel_autocomplete(),
224
+ help="Tunnel name or ID on the device. Optional when it has one TCP tunnel."
320
225
  ),
321
226
  ] = None,
322
- yes: Annotated[
323
- bool, typer.Option("--yes", help="Delete without confirmation.")
227
+ port: Annotated[
228
+ int | None,
229
+ typer.Option(
230
+ "--port", "-p", help="Local port to listen on. Default: a free one."
231
+ ),
232
+ ] = None,
233
+ ssh: Annotated[
234
+ bool,
235
+ typer.Option(
236
+ "--ssh",
237
+ help="Start ssh through the tunnel and close it when ssh exits. "
238
+ "Arguments after `--` go to ssh.",
239
+ ),
324
240
  ] = False,
325
- _profile: ProfileAnnotation = None,
326
- ):
327
- """Permanently delete a tunnel."""
328
- _ = _profile
329
- client, renderer = get_state()
330
-
331
- resolved_id = _resolve_tunnel_id(
332
- client,
333
- renderer,
334
- action="delete",
335
- lookup=tunnel,
336
- )
337
-
338
- if not yes:
339
- typer.confirm(f"Permanently delete tunnel {resolved_id}?", abort=True)
340
-
341
- with renderer.loading("Deleting tunnel..."):
342
- client.tunnels.delete(str(resolved_id))
343
-
344
- print(f"Deleted tunnel {resolved_id}.")
345
-
346
-
347
- @app.command()
348
- def activate(
349
- tunnel: Annotated[
350
- str | None,
351
- typer.Argument(
352
- help="Tunnel ID or exact name to activate.",
353
- autocompletion=_tunnel_autocomplete(),
241
+ ttl: Annotated[
242
+ int | None,
243
+ typer.Option(
244
+ help="Session lifetime in minutes. Default: the tunnel's timeout."
354
245
  ),
355
246
  ] = None,
356
247
  _profile: ProfileAnnotation = None,
357
248
  ):
358
- """Activate a tunnel (open the underlying connection on the device)."""
249
+ """Open a private tunnel to a device and forward it to localhost until Ctrl-C.
250
+
251
+ Nothing is exposed publicly: your laptop and the device both connect out
252
+ to the Doover relay, which bridges them. Point any TCP tool at the local
253
+ address it prints (ssh, Modbus, Foxglove, ...).
254
+ """
359
255
  _ = _profile
360
256
  client, renderer = get_state()
361
-
362
- resolved_id = _resolve_tunnel_id(
363
- client,
364
- renderer,
365
- action="activate",
366
- lookup=tunnel,
367
- )
368
-
369
- with renderer.loading("Activating tunnel..."):
370
- response = client.tunnels.activate(str(resolved_id), body={})
371
-
372
- renderer.render(response)
373
-
374
-
375
- @app.command()
376
- def deactivate(
257
+ device_id = _resolve_device_context_id(client, renderer, device, action="tunnel to")
258
+ args = [_doover_tunnel_binary(), "ssh" if ssh else "open", str(device_id)]
259
+ if tunnel:
260
+ args.append(tunnel)
261
+ args += ["--profile", state.profile_name]
262
+ if port is not None:
263
+ args += ["--port", str(port)]
264
+ if ttl is not None:
265
+ args += ["--ttl", str(ttl)]
266
+ if ctx.args:
267
+ args += ["--", *ctx.args]
268
+ exec_binary(args)
269
+
270
+
271
+ def ssh(
272
+ ctx: typer.Context,
273
+ device: Annotated[
274
+ str | None,
275
+ typer.Argument(help="Device ID or exact display name/name."),
276
+ ] = None,
377
277
  tunnel: Annotated[
378
278
  str | None,
379
- typer.Argument(
380
- help="Tunnel ID or exact name to deactivate.",
381
- autocompletion=_tunnel_autocomplete(),
279
+ typer.Argument(help="Tunnel name or ID. Optional when the device has one."),
280
+ ] = None,
281
+ ttl: Annotated[
282
+ int | None,
283
+ typer.Option(
284
+ help="Session lifetime in minutes. Default: the tunnel's timeout."
382
285
  ),
383
286
  ] = None,
384
287
  _profile: ProfileAnnotation = None,
385
288
  ):
386
- """Deactivate a tunnel (close the underlying connection on the device)."""
387
- _ = _profile
388
- client, renderer = get_state()
389
-
390
- resolved_id = _resolve_tunnel_id(
391
- client,
392
- renderer,
393
- action="deactivate",
394
- lookup=tunnel,
395
- )
289
+ """SSH to a device through a private tunnel.
396
290
 
397
- with renderer.loading("Deactivating tunnel..."):
398
- response = client.tunnels.deactivate(str(resolved_id), body={})
399
-
400
- renderer.render(response)
291
+ Uses the device's SSH tunnel, creating one (localhost:22, the device
292
+ type's ssh user) if it has none. Arguments after `--` go to ssh.
293
+ """
294
+ connect(ctx, device, tunnel, None, True, ttl, _profile)
401
295
 
402
296
 
403
297
  # ---------------------------------------------------------------------------
@@ -1,8 +1,6 @@
1
1
  from doover_cli.renderer import Renderer
2
2
  from typing import Annotated, Optional
3
3
 
4
- __version__ = "0.6.8"
5
-
6
4
  import click
7
5
  import typer
8
6
 
@@ -23,7 +21,7 @@ from .apps.device_type import app as device_type_app
23
21
  from .grpc import app as grpc_app
24
22
  from .login import app as login_app
25
23
  from .report import app as reports_app
26
- from .apps.tunnel import app as tunnels_app
24
+ from .apps import tunnel as tunnel_cmd
27
25
  from .user import org_app, users_app
28
26
  from .utils import sentry as sentry_utils
29
27
  from .utils.state import state
@@ -58,7 +56,14 @@ app.add_typer(
58
56
  )
59
57
  app.add_typer(login_app)
60
58
  app.add_typer(reports_app, name="report", help="Generate and manage reports.")
61
- app.add_typer(tunnels_app, name="tunnel", help="Manage tunnels for remote access.")
59
+ app.command(
60
+ name="tunnel",
61
+ context_settings={"allow_extra_args": True, "ignore_unknown_options": True},
62
+ )(tunnel_cmd.connect)
63
+ app.command(
64
+ name="ssh",
65
+ context_settings={"allow_extra_args": True, "ignore_unknown_options": True},
66
+ )(tunnel_cmd.ssh)
62
67
  app.add_typer(grpc_app, name="grpc", help="Interact with running gRPC servers.")
63
68
  app.add_typer(dda_logs_app, name="dda-logs", help="Convert DDA message logs to JSON.")
64
69
  app.add_typer(device_app, name="device", help="Manipulate devices in Doover 2.0")
@@ -0,0 +1,13 @@
1
+ """Console entry point for `doover`."""
2
+
3
+ import sys
4
+
5
+
6
+ def main() -> None:
7
+ from .tunnel_exec import maybe_exec
8
+
9
+ maybe_exec(sys.argv[1:])
10
+
11
+ from .cli import main as cli_main
12
+
13
+ cli_main()
@@ -0,0 +1,62 @@
1
+ """Hand `doover ssh` / `doover tunnel` to the `doover-tunnel` binary.
2
+
3
+ The binary does the whole job itself (device lookup, session, forwarding),
4
+ so the console entry point calls `maybe_exec` before importing the rest of
5
+ the CLI: that import is most of a second, the binary starts in milliseconds.
6
+ This module must stay free of heavy imports for the same reason.
7
+ """
8
+
9
+ from __future__ import annotations
10
+
11
+ import os
12
+ import shutil
13
+ import subprocess
14
+ import sys
15
+ import sysconfig
16
+ from pathlib import Path
17
+
18
+ INSTALL_HINT = (
19
+ "doover-tunnel is not installed alongside doover-cli. Reinstall with "
20
+ "`pip install -U doover-cli` (or `uv tool install -U doover-cli`)."
21
+ )
22
+
23
+ # doover verb -> doover-tunnel subcommand. Both sides take the same flags.
24
+ FAST_COMMANDS = {"ssh": "ssh", "tunnel": "open"}
25
+
26
+
27
+ def find_binary() -> str | None:
28
+ """The `doover-tunnel` binary the `doover-tunnel` wheel installs next to us."""
29
+ name = "doover-tunnel.exe" if os.name == "nt" else "doover-tunnel"
30
+ candidates = [
31
+ Path(sys.argv[0]).resolve().parent / name,
32
+ Path(sysconfig.get_path("scripts")) / name,
33
+ ]
34
+ for candidate in candidates:
35
+ if candidate.is_file():
36
+ return str(candidate)
37
+ return shutil.which("doover-tunnel")
38
+
39
+
40
+ def exec_binary(args: list[str]) -> None:
41
+ if os.name == "nt":
42
+ sys.exit(subprocess.call(args))
43
+ os.execv(args[0], args)
44
+
45
+
46
+ def fast_args(argv: list[str]) -> list[str] | None:
47
+ """Binary arguments for `argv` (everything after `doover`), or None when
48
+ the Python CLI should handle it: another command, or a bare `doover ssh`
49
+ / `doover tunnel`, which prompts for the device interactively."""
50
+ if len(argv) < 2 or argv[0] not in FAST_COMMANDS:
51
+ return None
52
+ return [FAST_COMMANDS[argv[0]], *argv[1:]]
53
+
54
+
55
+ def maybe_exec(argv: list[str]) -> None:
56
+ args = fast_args(argv)
57
+ if args is None:
58
+ return
59
+ binary = find_binary()
60
+ if binary is None:
61
+ return
62
+ exec_binary([binary, *args])