doover-cli 0.6.9__tar.gz → 0.7.2__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.9 → doover_cli-0.7.2}/.github/workflows/release.yml +1 -0
  2. {doover_cli-0.6.9 → doover_cli-0.7.2}/PKG-INFO +3 -2
  3. {doover_cli-0.6.9 → doover_cli-0.7.2}/pyproject.toml +3 -2
  4. doover_cli-0.7.2/src/doover_cli/__init__.py +16 -0
  5. {doover_cli-0.6.9 → doover_cli-0.7.2}/src/doover_cli/api/session.py +92 -0
  6. {doover_cli-0.6.9 → doover_cli-0.7.2}/src/doover_cli/apps/apps.py +30 -0
  7. {doover_cli-0.6.9 → doover_cli-0.7.2}/src/doover_cli/apps/tunnel.py +70 -176
  8. doover_cli-0.6.9/src/doover_cli/__init__.py → doover_cli-0.7.2/src/doover_cli/cli.py +9 -4
  9. doover_cli-0.7.2/src/doover_cli/entry.py +13 -0
  10. doover_cli-0.7.2/src/doover_cli/tunnel_exec.py +62 -0
  11. {doover_cli-0.6.9 → doover_cli-0.7.2}/src/doover_cli/utils/api.py +19 -0
  12. {doover_cli-0.6.9 → doover_cli-0.7.2}/src/doover_cli/utils/apps.py +30 -0
  13. {doover_cli-0.6.9 → doover_cli-0.7.2}/tests/test_apps.py +2 -0
  14. {doover_cli-0.6.9 → doover_cli-0.7.2}/tests/test_sentry.py +20 -21
  15. doover_cli-0.7.2/tests/test_tunnel_exec.py +28 -0
  16. {doover_cli-0.6.9 → doover_cli-0.7.2}/uv.lock +17 -4
  17. {doover_cli-0.6.9 → doover_cli-0.7.2}/.github/CONTRIBUTING.md +0 -0
  18. {doover_cli-0.6.9 → doover_cli-0.7.2}/.github/ISSUE_TEMPLATE/bug-report.yaml +0 -0
  19. {doover_cli-0.6.9 → doover_cli-0.7.2}/.github/ISSUE_TEMPLATE/config.yml +0 -0
  20. {doover_cli-0.6.9 → doover_cli-0.7.2}/.github/ISSUE_TEMPLATE/feature-request.yml +0 -0
  21. {doover_cli-0.6.9 → doover_cli-0.7.2}/.github/PULL_REQUEST_TEMPLATE.md +0 -0
  22. {doover_cli-0.6.9 → doover_cli-0.7.2}/.github/workflows/lint-test.yml +0 -0
  23. {doover_cli-0.6.9 → doover_cli-0.7.2}/.github/workflows/release-brew.yml +0 -0
  24. {doover_cli-0.6.9 → doover_cli-0.7.2}/.github/workflows/release-pypi.yml +0 -0
  25. {doover_cli-0.6.9 → doover_cli-0.7.2}/.gitignore +0 -0
  26. {doover_cli-0.6.9 → doover_cli-0.7.2}/.pre-commit-config.yaml +0 -0
  27. {doover_cli-0.6.9 → doover_cli-0.7.2}/AGENT.md +0 -0
  28. {doover_cli-0.6.9 → doover_cli-0.7.2}/LICENSE +0 -0
  29. {doover_cli-0.6.9 → doover_cli-0.7.2}/README.md +0 -0
  30. {doover_cli-0.6.9 → doover_cli-0.7.2}/debian/changelog +0 -0
  31. {doover_cli-0.6.9 → doover_cli-0.7.2}/debian/control +0 -0
  32. {doover_cli-0.6.9 → doover_cli-0.7.2}/debian/rules +0 -0
  33. {doover_cli-0.6.9 → doover_cli-0.7.2}/docs/user_stories.md +0 -0
  34. {doover_cli-0.6.9 → doover_cli-0.7.2}/src/doover_cli/agent.py +0 -0
  35. {doover_cli-0.6.9 → doover_cli-0.7.2}/src/doover_cli/api/__init__.py +0 -0
  36. {doover_cli-0.6.9 → doover_cli-0.7.2}/src/doover_cli/api/auth.py +0 -0
  37. {doover_cli-0.6.9 → doover_cli-0.7.2}/src/doover_cli/api/errors.py +0 -0
  38. {doover_cli-0.6.9 → doover_cli-0.7.2}/src/doover_cli/apps/app_install.py +0 -0
  39. {doover_cli-0.6.9 → doover_cli-0.7.2}/src/doover_cli/apps/device.py +0 -0
  40. {doover_cli-0.6.9 → doover_cli-0.7.2}/src/doover_cli/apps/device_type.py +0 -0
  41. {doover_cli-0.6.9 → doover_cli-0.7.2}/src/doover_cli/apps/migrate.py +0 -0
  42. {doover_cli-0.6.9 → doover_cli-0.7.2}/src/doover_cli/apps/widget_plugin.py +0 -0
  43. {doover_cli-0.6.9 → doover_cli-0.7.2}/src/doover_cli/channel.py +0 -0
  44. {doover_cli-0.6.9 → doover_cli-0.7.2}/src/doover_cli/colours.py +0 -0
  45. {doover_cli-0.6.9 → doover_cli-0.7.2}/src/doover_cli/config_schema.py +0 -0
  46. {doover_cli-0.6.9 → doover_cli-0.7.2}/src/doover_cli/dda_logs.py +0 -0
  47. {doover_cli-0.6.9 → doover_cli-0.7.2}/src/doover_cli/doover_config.py +0 -0
  48. {doover_cli-0.6.9 → doover_cli-0.7.2}/src/doover_cli/grpc.py +0 -0
  49. {doover_cli-0.6.9 → doover_cli-0.7.2}/src/doover_cli/login.py +0 -0
  50. {doover_cli-0.6.9 → doover_cli-0.7.2}/src/doover_cli/notification_schema.py +0 -0
  51. {doover_cli-0.6.9 → doover_cli-0.7.2}/src/doover_cli/registry.py +0 -0
  52. {doover_cli-0.6.9 → doover_cli-0.7.2}/src/doover_cli/renderer/__init__.py +0 -0
  53. {doover_cli-0.6.9 → doover_cli-0.7.2}/src/doover_cli/renderer/_base.py +0 -0
  54. {doover_cli-0.6.9 → doover_cli-0.7.2}/src/doover_cli/renderer/_basic.py +0 -0
  55. {doover_cli-0.6.9 → doover_cli-0.7.2}/src/doover_cli/renderer/_default.py +0 -0
  56. {doover_cli-0.6.9 → doover_cli-0.7.2}/src/doover_cli/renderer/_json.py +0 -0
  57. {doover_cli-0.6.9 → doover_cli-0.7.2}/src/doover_cli/report.py +0 -0
  58. {doover_cli-0.6.9 → doover_cli-0.7.2}/src/doover_cli/simulator.py +0 -0
  59. {doover_cli-0.6.9 → doover_cli-0.7.2}/src/doover_cli/ui_schema.py +0 -0
  60. {doover_cli-0.6.9 → doover_cli-0.7.2}/src/doover_cli/user.py +0 -0
  61. {doover_cli-0.6.9 → doover_cli-0.7.2}/src/doover_cli/utils/__init__.py +0 -0
  62. {doover_cli-0.6.9 → doover_cli-0.7.2}/src/doover_cli/utils/context.py +0 -0
  63. {doover_cli-0.6.9 → doover_cli-0.7.2}/src/doover_cli/utils/crud/__init__.py +0 -0
  64. {doover_cli-0.6.9 → doover_cli-0.7.2}/src/doover_cli/utils/crud/commands.py +0 -0
  65. {doover_cli-0.6.9 → doover_cli-0.7.2}/src/doover_cli/utils/crud/lookup.py +0 -0
  66. {doover_cli-0.6.9 → doover_cli-0.7.2}/src/doover_cli/utils/crud/prompting.py +0 -0
  67. {doover_cli-0.6.9 → doover_cli-0.7.2}/src/doover_cli/utils/crud/schema.py +0 -0
  68. {doover_cli-0.6.9 → doover_cli-0.7.2}/src/doover_cli/utils/crud/values.py +0 -0
  69. {doover_cli-0.6.9 → doover_cli-0.7.2}/src/doover_cli/utils/errors.py +0 -0
  70. {doover_cli-0.6.9 → doover_cli-0.7.2}/src/doover_cli/utils/formatters.py +0 -0
  71. {doover_cli-0.6.9 → doover_cli-0.7.2}/src/doover_cli/utils/misc.py +0 -0
  72. {doover_cli-0.6.9 → doover_cli-0.7.2}/src/doover_cli/utils/parsers.py +0 -0
  73. {doover_cli-0.6.9 → doover_cli-0.7.2}/src/doover_cli/utils/prompt.py +0 -0
  74. {doover_cli-0.6.9 → doover_cli-0.7.2}/src/doover_cli/utils/sentry.py +0 -0
  75. {doover_cli-0.6.9 → doover_cli-0.7.2}/src/doover_cli/utils/shell_commands.py +0 -0
  76. {doover_cli-0.6.9 → doover_cli-0.7.2}/src/doover_cli/utils/state.py +0 -0
  77. {doover_cli-0.6.9 → doover_cli-0.7.2}/tests/__init__.py +0 -0
  78. {doover_cli-0.6.9 → doover_cli-0.7.2}/tests/conftest.py +0 -0
  79. {doover_cli-0.6.9 → doover_cli-0.7.2}/tests/test_agent.py +0 -0
  80. {doover_cli-0.6.9 → doover_cli-0.7.2}/tests/test_app_install.py +0 -0
  81. {doover_cli-0.6.9 → doover_cli-0.7.2}/tests/test_auth_integration.py +0 -0
  82. {doover_cli-0.6.9 → doover_cli-0.7.2}/tests/test_auth_unit.py +0 -0
  83. {doover_cli-0.6.9 → doover_cli-0.7.2}/tests/test_basic.py +0 -0
  84. {doover_cli-0.6.9 → doover_cli-0.7.2}/tests/test_crud_commands.py +0 -0
  85. {doover_cli-0.6.9 → doover_cli-0.7.2}/tests/test_crud_lookup.py +0 -0
  86. {doover_cli-0.6.9 → doover_cli-0.7.2}/tests/test_crud_prompting.py +0 -0
  87. {doover_cli-0.6.9 → doover_cli-0.7.2}/tests/test_crud_schema.py +0 -0
  88. {doover_cli-0.6.9 → doover_cli-0.7.2}/tests/test_crud_values.py +0 -0
  89. {doover_cli-0.6.9 → doover_cli-0.7.2}/tests/test_default_renderer.py +0 -0
  90. {doover_cli-0.6.9 → doover_cli-0.7.2}/tests/test_device.py +0 -0
  91. {doover_cli-0.6.9 → doover_cli-0.7.2}/tests/test_device_cli_integration.py +0 -0
  92. {doover_cli-0.6.9 → doover_cli-0.7.2}/tests/test_device_type.py +0 -0
  93. {doover_cli-0.6.9 → doover_cli-0.7.2}/tests/test_device_type_cli_integration.py +0 -0
  94. {doover_cli-0.6.9 → doover_cli-0.7.2}/tests/test_discover.py +0 -0
  95. {doover_cli-0.6.9 → doover_cli-0.7.2}/tests/test_migrate.py +0 -0
  96. {doover_cli-0.6.9 → doover_cli-0.7.2}/tests/test_prompt.py +0 -0
  97. {doover_cli-0.6.9 → doover_cli-0.7.2}/tests/test_registry.py +0 -0
  98. {doover_cli-0.6.9 → doover_cli-0.7.2}/tests/test_schema_export.py +0 -0
  99. {doover_cli-0.6.9 → doover_cli-0.7.2}/tests/test_user.py +0 -0
  100. {doover_cli-0.6.9 → doover_cli-0.7.2}/tests/test_utils_apps.py +0 -0
  101. {doover_cli-0.6.9 → doover_cli-0.7.2}/tests/test_widget_plugin.py +0 -0
@@ -64,6 +64,7 @@ jobs:
64
64
  deb-s3 upload \
65
65
  debian/build/*.deb \
66
66
  --lock \
67
+ --preserve-versions \
67
68
  --bucket "apt.u.doover.com" \
68
69
  --s3-region "${AWS_DEFAULT_REGION}" \
69
70
  --sign "${REPO_SIGNING_KEY_ID}" \
@@ -1,16 +1,17 @@
1
1
  Metadata-Version: 2.5
2
2
  Name: doover-cli
3
- Version: 0.6.9
3
+ Version: 0.7.2
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
13
- Requires-Dist: pydoover>=1.17.1
14
+ Requires-Dist: pydoover>=1.18.5
14
15
  Requires-Dist: pytz>=2025.2
15
16
  Requires-Dist: questionary>=1.10.0
16
17
  Requires-Dist: requests>=2.32.3
@@ -10,7 +10,8 @@ dependencies = [
10
10
  "docker>=7.1.0",
11
11
  "jsf>=0.11.2",
12
12
  "paramiko>=3.5.1",
13
- "pydoover>=1.17.1",
13
+ "pydoover>=1.18.5",
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.2"
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}")
@@ -3,6 +3,8 @@ import os
3
3
  import typer
4
4
 
5
5
  from pydoover.api import DataClient, ControlClient
6
+ from pydoover.api.auth._base import SyncAuthBase
7
+ from pydoover.models.data.exceptions import TokenRefreshError
6
8
  from pydoover.api.auth import ConfigManager
7
9
 
8
10
  from .auth import DooverCLIAuthClient
@@ -72,6 +74,65 @@ class DooverCLISession:
72
74
  auth = TrustedPublisherAuthClient(**kwargs)
73
75
  return cls(config_manager=None, profile_name=None, auth=auth)
74
76
 
77
+ @classmethod
78
+ def from_service_account(
79
+ cls,
80
+ service_account_id: str,
81
+ *,
82
+ audience: str | None = None,
83
+ data_base_url: str | None = None,
84
+ control_base_url: str | None = None,
85
+ timeout: float = 60.0,
86
+ ) -> "DooverCLISession":
87
+ """Build a session acting as a service account that trusts this CI job:
88
+ the job's OIDC token (GitHub Actions, with id-token permission) is
89
+ exchanged on doover-data for the account's token. No stored secret."""
90
+ from pydoover.api.auth import ServiceAccountAuthClient
91
+
92
+ kwargs = dict(timeout=timeout)
93
+ if audience:
94
+ kwargs["audience"] = audience
95
+ if data_base_url:
96
+ kwargs["data_base_url"] = data_base_url
97
+ if control_base_url:
98
+ kwargs["control_base_url"] = control_base_url
99
+ auth = ServiceAccountAuthClient(service_account_id, **kwargs)
100
+ return cls(config_manager=None, profile_name=None, auth=auth)
101
+
102
+ @classmethod
103
+ def from_github_actions(
104
+ cls,
105
+ *,
106
+ audience: str | None = None,
107
+ data_base_url: str | None = None,
108
+ control_base_url: str | None = None,
109
+ timeout: float = 60.0,
110
+ ) -> "DooverCLISession":
111
+ """Inside GitHub Actions with no account named: the service account
112
+ that trusts this job if data finds one, else trusted publishing."""
113
+ from pydoover.api.auth import (
114
+ ServiceAccountAuthClient,
115
+ TrustedPublisherAuthClient,
116
+ )
117
+
118
+ account = dict(timeout=timeout)
119
+ if data_base_url:
120
+ account["data_base_url"] = data_base_url
121
+ if control_base_url:
122
+ account["control_base_url"] = control_base_url
123
+ publisher = dict(
124
+ provider="GH", control_base_url=control_base_url, timeout=timeout
125
+ )
126
+ if audience:
127
+ account["audience"] = audience
128
+ publisher["audience"] = audience
129
+ auth = _ServiceAccountOrPublisher(
130
+ ServiceAccountAuthClient(**account),
131
+ TrustedPublisherAuthClient(**publisher),
132
+ timeout=timeout,
133
+ )
134
+ return cls(config_manager=None, profile_name=None, auth=auth)
135
+
75
136
  @classmethod
76
137
  def from_env(cls, *, timeout: float = 60.0) -> "DooverCLISession":
77
138
  token = os.environ.get("DOOVER_API_TOKEN")
@@ -125,3 +186,34 @@ class DooverCLISession:
125
186
  return None
126
187
  raise NotImplementedError()
127
188
  # self.get_control_client().agents
189
+
190
+
191
+ class _ServiceAccountOrPublisher(SyncAuthBase):
192
+ """The service account that trusts this CI job, found by data; if none
193
+ does (data answers 401), trusted publishing, for the rest of the run."""
194
+
195
+ def __init__(self, account, publisher, *, timeout: float):
196
+ super().__init__(token=None, timeout=timeout)
197
+ self._account = account
198
+ self._publisher = publisher
199
+ self._use_publisher = False
200
+ self.control_base_url = getattr(account, "control_base_url", None) or getattr(
201
+ publisher, "control_base_url", None
202
+ )
203
+
204
+ def refresh_access_token(self) -> None:
205
+ if not self._use_publisher:
206
+ try:
207
+ self._account.refresh_access_token()
208
+ self._set_access_token(
209
+ self._account.token, token_expires=self._account.token_expires
210
+ )
211
+ return
212
+ except TokenRefreshError as e:
213
+ if " 401 " not in f" {e} ":
214
+ raise
215
+ self._use_publisher = True
216
+ self._publisher.refresh_access_token()
217
+ self._set_access_token(
218
+ self._publisher.token, token_expires=self._publisher.token_expires
219
+ )
@@ -1286,6 +1286,13 @@ def publish(
1286
1286
  help="Upload the widget when publishing. Disable with --no-put-widget.",
1287
1287
  ),
1288
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,
1289
1296
  build_package: Annotated[
1290
1297
  bool,
1291
1298
  typer.Option(
@@ -1492,6 +1499,29 @@ def publish(
1492
1499
  )
1493
1500
  rich.print("[green]Widget uploaded.[/green]")
1494
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
+
1495
1525
  if app_config.type in PACKAGE_APP_TYPES:
1496
1526
  image_uri = _image_package_uri(app_config)
1497
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.9"
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])
@@ -31,7 +31,26 @@ def setup_session(
31
31
  if os.environ.get("DOOVER_API_TOKEN"):
32
32
  return DooverCLISession.from_env()
33
33
 
34
+ # A service account trusting this CI job: preferred over the older
35
+ # trusted-publisher flow when named.
36
+ service_account = os.environ.get("DOOVER_SERVICE_ACCOUNT")
37
+ if service_account:
38
+ return DooverCLISession.from_service_account(
39
+ service_account,
40
+ audience=os.environ.get("DOOVER_OIDC_AUDIENCE"),
41
+ data_base_url=os.environ.get("DOOVER_DATA_API_BASE_URL"),
42
+ control_base_url=os.environ.get("DOOVER_CONTROL_API_BASE_URL"),
43
+ )
44
+
34
45
  provider = _trusted_publisher_provider()
46
+ if provider == "GH" and not os.environ.get("DOOVER_TRUSTED_PUBLISHER"):
47
+ # No account named: data finds the one trusting this job, else
48
+ # trusted publishing.
49
+ return DooverCLISession.from_github_actions(
50
+ audience=os.environ.get("DOOVER_OIDC_AUDIENCE"),
51
+ data_base_url=os.environ.get("DOOVER_DATA_API_BASE_URL"),
52
+ control_base_url=os.environ.get("DOOVER_CONTROL_API_BASE_URL"),
53
+ )
35
54
  if provider:
36
55
  return DooverCLISession.from_trusted_publisher(
37
56
  provider=provider,