devdoor 0.1.0__tar.gz → 0.2.0__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.
- {devdoor-0.1.0 → devdoor-0.2.0}/PKG-INFO +35 -8
- {devdoor-0.1.0 → devdoor-0.2.0}/README.md +34 -7
- {devdoor-0.1.0 → devdoor-0.2.0}/pyproject.toml +1 -1
- {devdoor-0.1.0 → devdoor-0.2.0}/pyproject.toml.orig +1 -1
- devdoor-0.2.0/src/devdoor/__init__.py +16 -0
- {devdoor-0.1.0 → devdoor-0.2.0}/src/devdoor/cli/app.py +2 -0
- devdoor-0.2.0/src/devdoor/cli/auth.py +318 -0
- {devdoor-0.1.0 → devdoor-0.2.0}/src/devdoor/cli/domains.py +67 -26
- {devdoor-0.1.0 → devdoor-0.2.0}/src/devdoor/cli/inspector.py +29 -8
- {devdoor-0.1.0 → devdoor-0.2.0}/src/devdoor/cli/local.py +569 -88
- {devdoor-0.1.0 → devdoor-0.2.0}/src/devdoor/cli/share.py +266 -31
- {devdoor-0.1.0 → devdoor-0.2.0}/src/devdoor/core/config.py +156 -10
- {devdoor-0.1.0 → devdoor-0.2.0}/src/devdoor/core/engine.py +57 -17
- {devdoor-0.1.0 → devdoor-0.2.0}/src/devdoor/core/events.py +53 -4
- {devdoor-0.1.0 → devdoor-0.2.0}/src/devdoor/core/router.py +23 -2
- {devdoor-0.1.0 → devdoor-0.2.0}/src/devdoor/inspector/curl.py +29 -2
- devdoor-0.2.0/src/devdoor/inspector/daemon_hook.py +234 -0
- devdoor-0.2.0/src/devdoor/inspector/replay.py +253 -0
- {devdoor-0.1.0 → devdoor-0.2.0}/src/devdoor/inspector/store.py +110 -71
- {devdoor-0.1.0 → devdoor-0.2.0}/src/devdoor/platform/__init__.py +8 -1
- {devdoor-0.1.0 → devdoor-0.2.0}/src/devdoor/platform/base.py +23 -5
- {devdoor-0.1.0 → devdoor-0.2.0}/src/devdoor/platform/darwin.py +93 -16
- {devdoor-0.1.0 → devdoor-0.2.0}/src/devdoor/platform/linux.py +21 -8
- {devdoor-0.1.0 → devdoor-0.2.0}/src/devdoor/platform/windows.py +59 -7
- {devdoor-0.1.0 → devdoor-0.2.0}/src/devdoor/proxy/forwarder.py +218 -39
- {devdoor-0.1.0 → devdoor-0.2.0}/src/devdoor/tui/inspector_app.py +125 -18
- {devdoor-0.1.0 → devdoor-0.2.0}/src/devdoor/tunnel/auth_client.py +170 -27
- {devdoor-0.1.0 → devdoor-0.2.0}/src/devdoor/tunnel/client.py +84 -17
- devdoor-0.2.0/src/devdoor/tunnel/mux.py +856 -0
- {devdoor-0.1.0 → devdoor-0.2.0}/src/devdoor/tunnel/relay_api.py +109 -10
- devdoor-0.1.0/src/devdoor/__init__.py +0 -6
- devdoor-0.1.0/src/devdoor/cli/auth.py +0 -178
- devdoor-0.1.0/src/devdoor/inspector/daemon_hook.py +0 -147
- devdoor-0.1.0/src/devdoor/inspector/replay.py +0 -122
- devdoor-0.1.0/src/devdoor/tunnel/mux.py +0 -566
- {devdoor-0.1.0 → devdoor-0.2.0}/LICENSE +0 -0
- {devdoor-0.1.0 → devdoor-0.2.0}/src/devdoor/__main__.py +0 -0
- {devdoor-0.1.0 → devdoor-0.2.0}/src/devdoor/cli/__init__.py +0 -0
- {devdoor-0.1.0 → devdoor-0.2.0}/src/devdoor/cli/validators.py +0 -0
- {devdoor-0.1.0 → devdoor-0.2.0}/src/devdoor/core/__init__.py +0 -0
- {devdoor-0.1.0 → devdoor-0.2.0}/src/devdoor/core/protocol.py +0 -0
- {devdoor-0.1.0 → devdoor-0.2.0}/src/devdoor/inspector/__init__.py +0 -0
- {devdoor-0.1.0 → devdoor-0.2.0}/src/devdoor/proxy/__init__.py +0 -0
- {devdoor-0.1.0 → devdoor-0.2.0}/src/devdoor/proxy/certs.py +0 -0
- {devdoor-0.1.0 → devdoor-0.2.0}/src/devdoor/proxy/https_server.py +0 -0
- {devdoor-0.1.0 → devdoor-0.2.0}/src/devdoor/tui/__init__.py +0 -0
- {devdoor-0.1.0 → devdoor-0.2.0}/src/devdoor/tunnel/__init__.py +0 -0
- {devdoor-0.1.0 → devdoor-0.2.0}/src/devdoor/tunnel/httperr.py +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: devdoor
|
|
3
|
-
Version: 0.
|
|
3
|
+
Version: 0.2.0
|
|
4
4
|
Summary: Open-source local HTTPS domain proxy, streaming tunnel client, and TUI inspector
|
|
5
5
|
Keywords: https,local-development,reverse-proxy,tunnel,websocket,tui
|
|
6
6
|
Author: Dipak Rathod
|
|
@@ -108,11 +108,11 @@ devdoor stop myapp # stop one domain
|
|
|
108
108
|
devdoor stop # stop all domains
|
|
109
109
|
```
|
|
110
110
|
|
|
111
|
-
Bare names default to `.test` on macOS/Linux (or `.localhost` in zero-admin Windows mode). You can specify any custom TLD explicitly:
|
|
111
|
+
Bare names default to `.test` on macOS/Linux (or `.localhost` in zero-admin Windows mode; override globally with `devdoor config set default-tld ...`). You can specify any custom TLD or upstream host explicitly:
|
|
112
112
|
|
|
113
113
|
```bash
|
|
114
|
-
devdoor start app.loc --port 3000
|
|
115
|
-
devdoor start my.demo --port 4000
|
|
114
|
+
devdoor start app.loc --port 3000 # https://app.loc -> 127.0.0.1:3000
|
|
115
|
+
devdoor start my.demo --port 4000 --host ::1 # https://my.demo -> [::1]:4000
|
|
116
116
|
```
|
|
117
117
|
|
|
118
118
|
> **Note:** Avoid `.local`—it is reserved for mDNS and can cause slow DNS lookups on macOS and Linux.
|
|
@@ -121,6 +121,7 @@ Route multiple URL paths under one domain:
|
|
|
121
121
|
|
|
122
122
|
```bash
|
|
123
123
|
devdoor start myapp --port 3000 --route /api=8080 --route /ws=9000 --cors
|
|
124
|
+
devdoor start myapp --port 3000 --no-cors
|
|
124
125
|
```
|
|
125
126
|
|
|
126
127
|
Or declare services in `devdoor.yaml` (or `.devdoor.yaml`) at your project root:
|
|
@@ -151,21 +152,34 @@ Authenticate via browser OAuth (`GitHub` / `OIDC`) or an API token, then share a
|
|
|
151
152
|
```bash
|
|
152
153
|
devdoor login # browser OAuth device flow
|
|
153
154
|
devdoor login --token dd_your_api_token # headless / CI / self-hosted token
|
|
155
|
+
printf '%s\n' "$DEVDOOR_TOKEN" | devdoor login --token-stdin # read token without shell history
|
|
154
156
|
devdoor logout # clear stored local credentials
|
|
155
157
|
devdoor config set relay https://tunnel.example.com # point to your own devdoor-relay
|
|
156
|
-
devdoor config
|
|
158
|
+
devdoor config set upstream-host ::1 # default upstream host (default: 127.0.0.1)
|
|
159
|
+
devdoor config set control-port 19500 # fixed loopback control port (0 = ephemeral)
|
|
160
|
+
devdoor config set connect-timeout 5.0 # upstream TCP connect timeout (seconds)
|
|
161
|
+
devdoor config set max-exchanges 1000 # bounded inspector.db history size
|
|
162
|
+
devdoor config set cors-origins https://app.example.com # default public CORS allowlist
|
|
163
|
+
devdoor config unset cors-origins # clear optional setting back to default
|
|
164
|
+
devdoor config set record-secrets false # default: redact Cookie/Authorization at capture
|
|
165
|
+
devdoor config show # inspect current config & relay source
|
|
157
166
|
|
|
158
167
|
devdoor share --port 3000 # random subdomain
|
|
159
168
|
devdoor share myapp # share multi-route devdoor.yaml service
|
|
169
|
+
devdoor share --port 3000 --host ::1 # forward tunnel traffic to non-IPv4 loopback
|
|
160
170
|
devdoor share --port 3000 --subdomain demo # reserved vanity subdomain
|
|
161
|
-
devdoor share --port 3000 --password
|
|
171
|
+
devdoor share --port 3000 --password-stdin # read Basic Auth passphrase from stdin (or DEVDOOR_SHARE_PASSWORD)
|
|
162
172
|
devdoor share --port 3000 --ttl 30m # auto-expire after 30 minutes
|
|
163
173
|
devdoor share --port 3000 --domain api.example.com # verified custom domain
|
|
164
174
|
devdoor share --port 3000 --preserve-host # preserve incoming public Host header
|
|
165
|
-
devdoor share --port 3000 --cors #
|
|
175
|
+
devdoor share --port 3000 --cors # non-credentialed wildcard CORS (*)
|
|
176
|
+
devdoor share --port 3000 --cors-origin https://app.example.com # credentialed CORS allowlist
|
|
166
177
|
devdoor share --port 3000 --tui # live Textual inspector during share
|
|
178
|
+
devdoor list --relay https://tunnel.example.com # inspect local domains + relay tunnels
|
|
167
179
|
```
|
|
168
180
|
|
|
181
|
+
Non-loopback relay endpoints require `https://` (`wss://` for `/ws/tunnel`) by default; pass `--allow-insecure-relay` (or set `DEVDOOR_ALLOW_INSECURE_RELAY=1`) only on trusted private networks. Captured traffic in `inspector.db` respects `log_mode` (`full` / `minimal` / `off`) and redacts `Authorization`, `Cookie`, `Set-Cookie`, `Proxy-Authorization`, and `X-Api-Key` headers at capture time unless `--record-secrets` or `devdoor config set record-secrets true` is enabled.
|
|
182
|
+
|
|
169
183
|
Manage verified custom domains and reserved vanity subdomains:
|
|
170
184
|
|
|
171
185
|
```bash
|
|
@@ -199,11 +213,24 @@ devdoor logs --follow myapp # tail logs for one domain (-f)
|
|
|
199
213
|
devdoor logs --flush # clear stored logs from inspector.db
|
|
200
214
|
|
|
201
215
|
devdoor doctor # verify CA, trust store, port forwarding, hosts, certs
|
|
216
|
+
devdoor reset --dry-run # preview OS cleanup without modifying files
|
|
217
|
+
devdoor reset # safely undo OS changes & domains (keeps login & inspector.db)
|
|
218
|
+
devdoor reset --all # also remove auth.json, config.yaml, and inspector.db
|
|
202
219
|
devdoor upgrade # upgrade devdoor via uv/pipx/pip (alias: update)
|
|
203
220
|
devdoor version # print version and Python runtime
|
|
204
|
-
devdoor uninstall #
|
|
221
|
+
devdoor uninstall # full OS undo + remove DevDoor files under ~/.devdoor
|
|
205
222
|
```
|
|
206
223
|
|
|
224
|
+
### Safely Undoing System Changes (`reset` / Manual Fallback)
|
|
225
|
+
|
|
226
|
+
Always run `devdoor reset` (or `devdoor uninstall`) **before** removing the package with `uv tool uninstall devdoor` or `pip uninstall devdoor`. `devdoor reset` probes each subsystem first, validates `/etc/pf.conf` before reloading on macOS, only deletes `# devdoor` entries in `/etc/hosts` and DevDoor-owned port-forwarding rules, and preserves `~/.devdoor/ca/` if an OS step fails so you can retry cleanly.
|
|
227
|
+
|
|
228
|
+
If you already removed the CLI binary before resetting:
|
|
229
|
+
|
|
230
|
+
- **macOS:** Remove `# devdoor` lines from `/etc/hosts`, remove `com.devdoor` anchor lines from `/etc/pf.conf`, delete `/etc/pf.anchors/com.devdoor`, run `sudo pfctl -a com.devdoor -F all && sudo pfctl -vnf /etc/pf.conf && sudo pfctl -f /etc/pf.conf`, and run `sudo security delete-certificate -t -c "DevDoor Root CA" /Library/Keychains/System.keychain`.
|
|
231
|
+
- **Linux:** Remove `# devdoor` lines from `/etc/hosts`, delete `/usr/local/share/ca-certificates/devdoor.crt` (or `/etc/pki/ca-trust/source/anchors/devdoor.crt`) and refresh trust (`sudo update-ca-certificates --fresh` or `sudo update-ca-trust extract`), and delete only the `DEVDOOR` `iptables -t nat` chain or `ip devdoor` `nft` table.
|
|
232
|
+
- **Windows:** Run `certutil -user -delstore Root "DevDoor Root CA"`, remove `# devdoor` lines from `%SystemRoot%\System32\drivers\etc\hosts`, and delete DevDoor `netsh interface portproxy` rules (`connectport=10080` / `10443`) if elevated `.test` mode was used.
|
|
233
|
+
|
|
207
234
|
## Contributing
|
|
208
235
|
|
|
209
236
|
Contributions are welcome! Please read the [Contributing Guide](CONTRIBUTING.md), follow the [Code of Conduct](CODE_OF_CONDUCT.md), and adhere to [CONSTRAINTS.md](CONSTRAINTS.md).
|
|
@@ -73,11 +73,11 @@ devdoor stop myapp # stop one domain
|
|
|
73
73
|
devdoor stop # stop all domains
|
|
74
74
|
```
|
|
75
75
|
|
|
76
|
-
Bare names default to `.test` on macOS/Linux (or `.localhost` in zero-admin Windows mode). You can specify any custom TLD explicitly:
|
|
76
|
+
Bare names default to `.test` on macOS/Linux (or `.localhost` in zero-admin Windows mode; override globally with `devdoor config set default-tld ...`). You can specify any custom TLD or upstream host explicitly:
|
|
77
77
|
|
|
78
78
|
```bash
|
|
79
|
-
devdoor start app.loc --port 3000
|
|
80
|
-
devdoor start my.demo --port 4000
|
|
79
|
+
devdoor start app.loc --port 3000 # https://app.loc -> 127.0.0.1:3000
|
|
80
|
+
devdoor start my.demo --port 4000 --host ::1 # https://my.demo -> [::1]:4000
|
|
81
81
|
```
|
|
82
82
|
|
|
83
83
|
> **Note:** Avoid `.local`—it is reserved for mDNS and can cause slow DNS lookups on macOS and Linux.
|
|
@@ -86,6 +86,7 @@ Route multiple URL paths under one domain:
|
|
|
86
86
|
|
|
87
87
|
```bash
|
|
88
88
|
devdoor start myapp --port 3000 --route /api=8080 --route /ws=9000 --cors
|
|
89
|
+
devdoor start myapp --port 3000 --no-cors
|
|
89
90
|
```
|
|
90
91
|
|
|
91
92
|
Or declare services in `devdoor.yaml` (or `.devdoor.yaml`) at your project root:
|
|
@@ -116,21 +117,34 @@ Authenticate via browser OAuth (`GitHub` / `OIDC`) or an API token, then share a
|
|
|
116
117
|
```bash
|
|
117
118
|
devdoor login # browser OAuth device flow
|
|
118
119
|
devdoor login --token dd_your_api_token # headless / CI / self-hosted token
|
|
120
|
+
printf '%s\n' "$DEVDOOR_TOKEN" | devdoor login --token-stdin # read token without shell history
|
|
119
121
|
devdoor logout # clear stored local credentials
|
|
120
122
|
devdoor config set relay https://tunnel.example.com # point to your own devdoor-relay
|
|
121
|
-
devdoor config
|
|
123
|
+
devdoor config set upstream-host ::1 # default upstream host (default: 127.0.0.1)
|
|
124
|
+
devdoor config set control-port 19500 # fixed loopback control port (0 = ephemeral)
|
|
125
|
+
devdoor config set connect-timeout 5.0 # upstream TCP connect timeout (seconds)
|
|
126
|
+
devdoor config set max-exchanges 1000 # bounded inspector.db history size
|
|
127
|
+
devdoor config set cors-origins https://app.example.com # default public CORS allowlist
|
|
128
|
+
devdoor config unset cors-origins # clear optional setting back to default
|
|
129
|
+
devdoor config set record-secrets false # default: redact Cookie/Authorization at capture
|
|
130
|
+
devdoor config show # inspect current config & relay source
|
|
122
131
|
|
|
123
132
|
devdoor share --port 3000 # random subdomain
|
|
124
133
|
devdoor share myapp # share multi-route devdoor.yaml service
|
|
134
|
+
devdoor share --port 3000 --host ::1 # forward tunnel traffic to non-IPv4 loopback
|
|
125
135
|
devdoor share --port 3000 --subdomain demo # reserved vanity subdomain
|
|
126
|
-
devdoor share --port 3000 --password
|
|
136
|
+
devdoor share --port 3000 --password-stdin # read Basic Auth passphrase from stdin (or DEVDOOR_SHARE_PASSWORD)
|
|
127
137
|
devdoor share --port 3000 --ttl 30m # auto-expire after 30 minutes
|
|
128
138
|
devdoor share --port 3000 --domain api.example.com # verified custom domain
|
|
129
139
|
devdoor share --port 3000 --preserve-host # preserve incoming public Host header
|
|
130
|
-
devdoor share --port 3000 --cors #
|
|
140
|
+
devdoor share --port 3000 --cors # non-credentialed wildcard CORS (*)
|
|
141
|
+
devdoor share --port 3000 --cors-origin https://app.example.com # credentialed CORS allowlist
|
|
131
142
|
devdoor share --port 3000 --tui # live Textual inspector during share
|
|
143
|
+
devdoor list --relay https://tunnel.example.com # inspect local domains + relay tunnels
|
|
132
144
|
```
|
|
133
145
|
|
|
146
|
+
Non-loopback relay endpoints require `https://` (`wss://` for `/ws/tunnel`) by default; pass `--allow-insecure-relay` (or set `DEVDOOR_ALLOW_INSECURE_RELAY=1`) only on trusted private networks. Captured traffic in `inspector.db` respects `log_mode` (`full` / `minimal` / `off`) and redacts `Authorization`, `Cookie`, `Set-Cookie`, `Proxy-Authorization`, and `X-Api-Key` headers at capture time unless `--record-secrets` or `devdoor config set record-secrets true` is enabled.
|
|
147
|
+
|
|
134
148
|
Manage verified custom domains and reserved vanity subdomains:
|
|
135
149
|
|
|
136
150
|
```bash
|
|
@@ -164,11 +178,24 @@ devdoor logs --follow myapp # tail logs for one domain (-f)
|
|
|
164
178
|
devdoor logs --flush # clear stored logs from inspector.db
|
|
165
179
|
|
|
166
180
|
devdoor doctor # verify CA, trust store, port forwarding, hosts, certs
|
|
181
|
+
devdoor reset --dry-run # preview OS cleanup without modifying files
|
|
182
|
+
devdoor reset # safely undo OS changes & domains (keeps login & inspector.db)
|
|
183
|
+
devdoor reset --all # also remove auth.json, config.yaml, and inspector.db
|
|
167
184
|
devdoor upgrade # upgrade devdoor via uv/pipx/pip (alias: update)
|
|
168
185
|
devdoor version # print version and Python runtime
|
|
169
|
-
devdoor uninstall #
|
|
186
|
+
devdoor uninstall # full OS undo + remove DevDoor files under ~/.devdoor
|
|
170
187
|
```
|
|
171
188
|
|
|
189
|
+
### Safely Undoing System Changes (`reset` / Manual Fallback)
|
|
190
|
+
|
|
191
|
+
Always run `devdoor reset` (or `devdoor uninstall`) **before** removing the package with `uv tool uninstall devdoor` or `pip uninstall devdoor`. `devdoor reset` probes each subsystem first, validates `/etc/pf.conf` before reloading on macOS, only deletes `# devdoor` entries in `/etc/hosts` and DevDoor-owned port-forwarding rules, and preserves `~/.devdoor/ca/` if an OS step fails so you can retry cleanly.
|
|
192
|
+
|
|
193
|
+
If you already removed the CLI binary before resetting:
|
|
194
|
+
|
|
195
|
+
- **macOS:** Remove `# devdoor` lines from `/etc/hosts`, remove `com.devdoor` anchor lines from `/etc/pf.conf`, delete `/etc/pf.anchors/com.devdoor`, run `sudo pfctl -a com.devdoor -F all && sudo pfctl -vnf /etc/pf.conf && sudo pfctl -f /etc/pf.conf`, and run `sudo security delete-certificate -t -c "DevDoor Root CA" /Library/Keychains/System.keychain`.
|
|
196
|
+
- **Linux:** Remove `# devdoor` lines from `/etc/hosts`, delete `/usr/local/share/ca-certificates/devdoor.crt` (or `/etc/pki/ca-trust/source/anchors/devdoor.crt`) and refresh trust (`sudo update-ca-certificates --fresh` or `sudo update-ca-trust extract`), and delete only the `DEVDOOR` `iptables -t nat` chain or `ip devdoor` `nft` table.
|
|
197
|
+
- **Windows:** Run `certutil -user -delstore Root "DevDoor Root CA"`, remove `# devdoor` lines from `%SystemRoot%\System32\drivers\etc\hosts`, and delete DevDoor `netsh interface portproxy` rules (`connectport=10080` / `10443`) if elevated `.test` mode was used.
|
|
198
|
+
|
|
172
199
|
## Contributing
|
|
173
200
|
|
|
174
201
|
Contributions are welcome! Please read the [Contributing Guide](CONTRIBUTING.md), follow the [Code of Conduct](CODE_OF_CONDUCT.md), and adhere to [CONSTRAINTS.md](CONSTRAINTS.md).
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
"""DevDoor open-source local HTTPS proxy, streaming tunnel, and TUI inspector."""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
from importlib.metadata import PackageNotFoundError, version
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
def _resolve_version() -> str:
|
|
9
|
+
try:
|
|
10
|
+
return version("devdoor")
|
|
11
|
+
except PackageNotFoundError:
|
|
12
|
+
return "0.2.0"
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
__version__ = _resolve_version()
|
|
16
|
+
__all__ = ["__version__"]
|
|
@@ -18,6 +18,7 @@ from devdoor.cli.local import (
|
|
|
18
18
|
doctor_command,
|
|
19
19
|
down_command,
|
|
20
20
|
list_command,
|
|
21
|
+
reset_command,
|
|
21
22
|
start_command,
|
|
22
23
|
stop_command,
|
|
23
24
|
uninstall_command,
|
|
@@ -38,6 +39,7 @@ app.command("down")(down_command)
|
|
|
38
39
|
app.command("list")(list_command)
|
|
39
40
|
app.command("ls")(list_command)
|
|
40
41
|
app.command("doctor")(doctor_command)
|
|
42
|
+
app.command("reset")(reset_command)
|
|
41
43
|
app.command("uninstall")(uninstall_command)
|
|
42
44
|
app.command("login")(login_command)
|
|
43
45
|
app.command("logout")(logout_command)
|
|
@@ -0,0 +1,318 @@
|
|
|
1
|
+
"""CLI commands for authentication and global DevDoor configuration."""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
import asyncio
|
|
6
|
+
import json
|
|
7
|
+
import sys
|
|
8
|
+
|
|
9
|
+
import typer
|
|
10
|
+
from rich.console import Console
|
|
11
|
+
from rich.table import Table
|
|
12
|
+
|
|
13
|
+
from devdoor.cli.validators import parse_cli_log_mode, parse_cli_port
|
|
14
|
+
from devdoor.core.config import (
|
|
15
|
+
ConfigError,
|
|
16
|
+
GlobalConfig,
|
|
17
|
+
load_global_config,
|
|
18
|
+
mutate_global_config,
|
|
19
|
+
normalize_upstream_host,
|
|
20
|
+
parse_default_tld,
|
|
21
|
+
resolve_paths,
|
|
22
|
+
)
|
|
23
|
+
from devdoor.tunnel.auth_client import (
|
|
24
|
+
AuthClient,
|
|
25
|
+
clear_credentials,
|
|
26
|
+
normalize_relay_url,
|
|
27
|
+
resolve_relay_with_source,
|
|
28
|
+
)
|
|
29
|
+
from devdoor.tunnel.httperr import RelayRequestError
|
|
30
|
+
|
|
31
|
+
config_app = typer.Typer(help="Inspect and update DevDoor configuration.")
|
|
32
|
+
|
|
33
|
+
_CONFIG_KEY_ALIASES: dict[str, str] = {
|
|
34
|
+
"relay": "relay-url",
|
|
35
|
+
"tld": "default-tld",
|
|
36
|
+
"max-exchanges": "inspector-max-exchanges",
|
|
37
|
+
"timeout": "connect-timeout-seconds",
|
|
38
|
+
"connect-timeout": "connect-timeout-seconds",
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
_CLEAR_TOKENS = frozenset({"", "none", "null", "default"})
|
|
42
|
+
|
|
43
|
+
|
|
44
|
+
def _parse_bool(raw: str) -> bool:
|
|
45
|
+
normalized = raw.strip().lower()
|
|
46
|
+
if normalized in {"true", "1", "yes", "on"}:
|
|
47
|
+
return True
|
|
48
|
+
if normalized in {"false", "0", "no", "off"}:
|
|
49
|
+
return False
|
|
50
|
+
raise typer.BadParameter(f"Expected boolean value, got {raw!r}")
|
|
51
|
+
|
|
52
|
+
|
|
53
|
+
def login_command(
|
|
54
|
+
token: str | None = typer.Option(
|
|
55
|
+
None,
|
|
56
|
+
"--token",
|
|
57
|
+
help="Authenticate directly with a static relay API token.",
|
|
58
|
+
),
|
|
59
|
+
token_stdin: bool = typer.Option(
|
|
60
|
+
False,
|
|
61
|
+
"--token-stdin",
|
|
62
|
+
help="Read the static relay API token from standard input.",
|
|
63
|
+
),
|
|
64
|
+
provider: str | None = typer.Option(
|
|
65
|
+
None,
|
|
66
|
+
"--provider",
|
|
67
|
+
help="OAuth provider hint for browser sign-in (e.g., github or oidc).",
|
|
68
|
+
),
|
|
69
|
+
relay: str | None = typer.Option(
|
|
70
|
+
None,
|
|
71
|
+
"--relay",
|
|
72
|
+
help="Override the DevDoor relay URL for login.",
|
|
73
|
+
),
|
|
74
|
+
allow_insecure_relay: bool = typer.Option(
|
|
75
|
+
False,
|
|
76
|
+
"--allow-insecure-relay",
|
|
77
|
+
help="Allow plaintext http:// relay URLs on non-loopback hosts.",
|
|
78
|
+
),
|
|
79
|
+
) -> None:
|
|
80
|
+
"""Authenticate this machine with a DevDoor relay server."""
|
|
81
|
+
if token is not None and token_stdin:
|
|
82
|
+
typer.secho("Cannot combine --token and --token-stdin.", fg=typer.colors.RED, err=True)
|
|
83
|
+
raise typer.Exit(code=1)
|
|
84
|
+
if provider is not None and (token is not None or token_stdin):
|
|
85
|
+
typer.secho(
|
|
86
|
+
"Cannot combine --provider with --token or --token-stdin.",
|
|
87
|
+
fg=typer.colors.RED,
|
|
88
|
+
err=True,
|
|
89
|
+
)
|
|
90
|
+
raise typer.Exit(code=1)
|
|
91
|
+
|
|
92
|
+
resolved_token: str | None = None
|
|
93
|
+
if token_stdin:
|
|
94
|
+
resolved_token = sys.stdin.read().strip()
|
|
95
|
+
if not resolved_token:
|
|
96
|
+
typer.secho("No token read from stdin.", fg=typer.colors.RED, err=True)
|
|
97
|
+
raise typer.Exit(code=1)
|
|
98
|
+
elif token is not None:
|
|
99
|
+
resolved_token = token.strip()
|
|
100
|
+
if not resolved_token:
|
|
101
|
+
typer.secho("Token must not be empty.", fg=typer.colors.RED, err=True)
|
|
102
|
+
raise typer.Exit(code=1)
|
|
103
|
+
|
|
104
|
+
paths = resolve_paths()
|
|
105
|
+
try:
|
|
106
|
+
relay_url, _ = resolve_relay_with_source(
|
|
107
|
+
cli_relay=relay,
|
|
108
|
+
paths=paths,
|
|
109
|
+
allow_insecure=allow_insecure_relay,
|
|
110
|
+
)
|
|
111
|
+
except (ValueError, ConfigError) as exc:
|
|
112
|
+
typer.secho(f"Error: {exc}", fg=typer.colors.RED, err=True)
|
|
113
|
+
raise typer.Exit(code=1) from exc
|
|
114
|
+
|
|
115
|
+
async def _run() -> None:
|
|
116
|
+
async with AuthClient(paths=paths, allow_insecure=allow_insecure_relay) as client:
|
|
117
|
+
if resolved_token is not None:
|
|
118
|
+
creds = await client.login_with_token(resolved_token, relay_url=relay_url)
|
|
119
|
+
else:
|
|
120
|
+
creds = await client.login_with_browser(
|
|
121
|
+
relay_url=relay_url,
|
|
122
|
+
provider=provider,
|
|
123
|
+
notify_fn=typer.echo,
|
|
124
|
+
)
|
|
125
|
+
identity = creds.email or creds.name or "authenticated user"
|
|
126
|
+
typer.echo(f"Logged in to {creds.relay_url} as {identity}.")
|
|
127
|
+
|
|
128
|
+
try:
|
|
129
|
+
asyncio.run(_run())
|
|
130
|
+
except (RelayRequestError, TimeoutError, ValueError) as exc:
|
|
131
|
+
typer.secho(f"Login failed: {exc}", fg=typer.colors.RED, err=True)
|
|
132
|
+
raise typer.Exit(code=1) from exc
|
|
133
|
+
|
|
134
|
+
|
|
135
|
+
def logout_command() -> None:
|
|
136
|
+
"""Remove locally stored relay authentication credentials."""
|
|
137
|
+
paths = resolve_paths()
|
|
138
|
+
removed = clear_credentials(paths=paths)
|
|
139
|
+
if removed:
|
|
140
|
+
typer.echo("Logged out and removed saved credentials.")
|
|
141
|
+
else:
|
|
142
|
+
typer.echo("Already logged out (no saved credentials found).")
|
|
143
|
+
|
|
144
|
+
|
|
145
|
+
@config_app.command("set")
|
|
146
|
+
def config_set_command(
|
|
147
|
+
key: str = typer.Argument(
|
|
148
|
+
...,
|
|
149
|
+
help=(
|
|
150
|
+
"Setting name (relay-url, default-tld, log-mode, cors, cors-origins, "
|
|
151
|
+
"record-secrets, http-port, https-port, control-port, upstream-host, "
|
|
152
|
+
"connect-timeout, inspector-max-exchanges)."
|
|
153
|
+
),
|
|
154
|
+
),
|
|
155
|
+
value: str = typer.Argument(..., help="New value for the setting."),
|
|
156
|
+
allow_insecure_relay: bool = typer.Option(
|
|
157
|
+
False,
|
|
158
|
+
"--allow-insecure-relay",
|
|
159
|
+
help="Allow plaintext http:// relay URLs on non-loopback hosts.",
|
|
160
|
+
),
|
|
161
|
+
) -> None:
|
|
162
|
+
"""Update a global DevDoor configuration value."""
|
|
163
|
+
normalized_key = key.strip().lower().replace("_", "-")
|
|
164
|
+
normalized_key = _CONFIG_KEY_ALIASES.get(normalized_key, normalized_key)
|
|
165
|
+
paths = resolve_paths()
|
|
166
|
+
|
|
167
|
+
def _apply(cfg: GlobalConfig) -> GlobalConfig:
|
|
168
|
+
raw_trimmed = value.strip()
|
|
169
|
+
if normalized_key == "relay-url":
|
|
170
|
+
if raw_trimmed.lower() in _CLEAR_TOKENS:
|
|
171
|
+
return cfg.model_copy(update={"relay_url": None})
|
|
172
|
+
normalized_relay = normalize_relay_url(value, allow_insecure=allow_insecure_relay)
|
|
173
|
+
return cfg.model_copy(update={"relay_url": normalized_relay})
|
|
174
|
+
if normalized_key == "default-tld":
|
|
175
|
+
if raw_trimmed.lower() in _CLEAR_TOKENS:
|
|
176
|
+
return cfg.model_copy(update={"default_tld": None})
|
|
177
|
+
return cfg.model_copy(update={"default_tld": parse_default_tld(value)})
|
|
178
|
+
if normalized_key == "log-mode":
|
|
179
|
+
return cfg.model_copy(update={"log_mode": parse_cli_log_mode(value)})
|
|
180
|
+
if normalized_key == "cors":
|
|
181
|
+
return cfg.model_copy(update={"cors": _parse_bool(value)})
|
|
182
|
+
if normalized_key == "cors-origins":
|
|
183
|
+
if raw_trimmed.lower() in _CLEAR_TOKENS:
|
|
184
|
+
return cfg.model_copy(update={"cors_allowed_origins": []})
|
|
185
|
+
origins = [item.strip() for item in value.split(",") if item.strip()]
|
|
186
|
+
return cfg.model_copy(update={"cors_allowed_origins": origins})
|
|
187
|
+
if normalized_key == "record-secrets":
|
|
188
|
+
return cfg.model_copy(update={"record_secrets": _parse_bool(value)})
|
|
189
|
+
if normalized_key == "http-port":
|
|
190
|
+
return cfg.model_copy(update={"http_port": parse_cli_port(value)})
|
|
191
|
+
if normalized_key == "https-port":
|
|
192
|
+
return cfg.model_copy(update={"https_port": parse_cli_port(value)})
|
|
193
|
+
if normalized_key == "control-port":
|
|
194
|
+
if raw_trimmed.lower() in {"0", "auto", "default"}:
|
|
195
|
+
return cfg.model_copy(update={"control_port": 0})
|
|
196
|
+
return cfg.model_copy(update={"control_port": parse_cli_port(value)})
|
|
197
|
+
if normalized_key == "upstream-host":
|
|
198
|
+
return cfg.model_copy(update={"upstream_host": normalize_upstream_host(value)})
|
|
199
|
+
if normalized_key == "connect-timeout-seconds":
|
|
200
|
+
try:
|
|
201
|
+
seconds = float(raw_trimmed)
|
|
202
|
+
except ValueError as exc:
|
|
203
|
+
raise typer.BadParameter(f"Expected positive float seconds, got {value!r}") from exc
|
|
204
|
+
if not (0.0 < seconds <= 300.0):
|
|
205
|
+
raise typer.BadParameter("connect-timeout must be between 0 and 300 seconds.")
|
|
206
|
+
return cfg.model_copy(update={"connect_timeout_seconds": seconds})
|
|
207
|
+
if normalized_key == "inspector-max-exchanges":
|
|
208
|
+
try:
|
|
209
|
+
count = int(raw_trimmed)
|
|
210
|
+
except ValueError as exc:
|
|
211
|
+
raise typer.BadParameter(f"Expected integer, got {value!r}") from exc
|
|
212
|
+
if not (1 <= count <= 100_000):
|
|
213
|
+
raise typer.BadParameter("inspector-max-exchanges must be between 1 and 100000.")
|
|
214
|
+
return cfg.model_copy(update={"inspector_max_exchanges": count})
|
|
215
|
+
raise typer.BadParameter(f"Unknown configuration key: {key!r}")
|
|
216
|
+
|
|
217
|
+
def _validated_apply(cfg: GlobalConfig) -> GlobalConfig:
|
|
218
|
+
updated = _apply(cfg)
|
|
219
|
+
return GlobalConfig.model_validate(updated.model_dump())
|
|
220
|
+
|
|
221
|
+
try:
|
|
222
|
+
mutate_global_config(_validated_apply, paths=paths)
|
|
223
|
+
except ValueError as exc:
|
|
224
|
+
typer.secho(f"Error: {exc}", fg=typer.colors.RED, err=True)
|
|
225
|
+
raise typer.Exit(code=1) from exc
|
|
226
|
+
|
|
227
|
+
typer.echo(f"Updated {normalized_key}.")
|
|
228
|
+
|
|
229
|
+
|
|
230
|
+
@config_app.command("unset")
|
|
231
|
+
def config_unset_command(
|
|
232
|
+
key: str = typer.Argument(
|
|
233
|
+
...,
|
|
234
|
+
help="Optional setting to reset (relay-url, default-tld, cors-origins).",
|
|
235
|
+
),
|
|
236
|
+
) -> None:
|
|
237
|
+
"""Reset an optional configuration key back to its default behavior."""
|
|
238
|
+
normalized_key = key.strip().lower().replace("_", "-")
|
|
239
|
+
normalized_key = _CONFIG_KEY_ALIASES.get(normalized_key, normalized_key)
|
|
240
|
+
paths = resolve_paths()
|
|
241
|
+
|
|
242
|
+
def _reset_key(cfg: GlobalConfig) -> GlobalConfig:
|
|
243
|
+
if normalized_key == "relay-url":
|
|
244
|
+
return cfg.model_copy(update={"relay_url": None})
|
|
245
|
+
if normalized_key == "default-tld":
|
|
246
|
+
return cfg.model_copy(update={"default_tld": None})
|
|
247
|
+
if normalized_key == "cors-origins":
|
|
248
|
+
return cfg.model_copy(update={"cors_allowed_origins": []})
|
|
249
|
+
raise typer.BadParameter(
|
|
250
|
+
f"Key {key!r} cannot be unset (supported: relay-url, default-tld, cors-origins)."
|
|
251
|
+
)
|
|
252
|
+
|
|
253
|
+
try:
|
|
254
|
+
mutate_global_config(_reset_key, paths=paths)
|
|
255
|
+
except ValueError as exc:
|
|
256
|
+
typer.secho(f"Error: {exc}", fg=typer.colors.RED, err=True)
|
|
257
|
+
raise typer.Exit(code=1) from exc
|
|
258
|
+
typer.echo(f"Reset {normalized_key} to default.")
|
|
259
|
+
|
|
260
|
+
|
|
261
|
+
@config_app.command("show")
|
|
262
|
+
def config_show_command(
|
|
263
|
+
json_output: bool = typer.Option(
|
|
264
|
+
False,
|
|
265
|
+
"--json",
|
|
266
|
+
help="Print configuration as JSON.",
|
|
267
|
+
),
|
|
268
|
+
) -> None:
|
|
269
|
+
"""Display the current global DevDoor configuration."""
|
|
270
|
+
paths = resolve_paths()
|
|
271
|
+
try:
|
|
272
|
+
cfg = load_global_config(paths)
|
|
273
|
+
resolved_relay, relay_source = resolve_relay_with_source(
|
|
274
|
+
paths=paths,
|
|
275
|
+
allow_insecure=True,
|
|
276
|
+
)
|
|
277
|
+
except (ConfigError, ValueError) as exc:
|
|
278
|
+
typer.secho(f"Configuration error: {exc}", fg=typer.colors.RED, err=True)
|
|
279
|
+
raise typer.Exit(code=1) from exc
|
|
280
|
+
if json_output:
|
|
281
|
+
payload = {
|
|
282
|
+
"home": str(paths.home),
|
|
283
|
+
"relay_url": resolved_relay,
|
|
284
|
+
"relay_source": relay_source,
|
|
285
|
+
"default_tld": cfg.default_tld,
|
|
286
|
+
"log_mode": cfg.log_mode,
|
|
287
|
+
"cors": cfg.cors,
|
|
288
|
+
"cors_allowed_origins": cfg.cors_allowed_origins,
|
|
289
|
+
"record_secrets": cfg.record_secrets,
|
|
290
|
+
"http_port": cfg.http_port,
|
|
291
|
+
"https_port": cfg.https_port,
|
|
292
|
+
"control_port": cfg.control_port,
|
|
293
|
+
"upstream_host": cfg.upstream_host,
|
|
294
|
+
"connect_timeout_seconds": cfg.connect_timeout_seconds,
|
|
295
|
+
"inspector_max_exchanges": cfg.inspector_max_exchanges,
|
|
296
|
+
"domain_count": len(cfg.domains),
|
|
297
|
+
}
|
|
298
|
+
typer.echo(json.dumps(payload, indent=2))
|
|
299
|
+
return
|
|
300
|
+
|
|
301
|
+
table = Table(title="DevDoor Configuration")
|
|
302
|
+
table.add_column("Key", style="cyan")
|
|
303
|
+
table.add_column("Value")
|
|
304
|
+
table.add_row("home", str(paths.home))
|
|
305
|
+
table.add_row("relay-url", f"{resolved_relay} ({relay_source})")
|
|
306
|
+
table.add_row("default-tld", cfg.default_tld or "(platform default)")
|
|
307
|
+
table.add_row("log-mode", cfg.log_mode)
|
|
308
|
+
table.add_row("cors", str(cfg.cors).lower())
|
|
309
|
+
table.add_row("cors-origins", ", ".join(cfg.cors_allowed_origins) or "(none)")
|
|
310
|
+
table.add_row("record-secrets", str(cfg.record_secrets).lower())
|
|
311
|
+
table.add_row("http-port", str(cfg.http_port))
|
|
312
|
+
table.add_row("https-port", str(cfg.https_port))
|
|
313
|
+
table.add_row("control-port", str(cfg.control_port or "auto"))
|
|
314
|
+
table.add_row("upstream-host", cfg.upstream_host)
|
|
315
|
+
table.add_row("connect-timeout", f"{cfg.connect_timeout_seconds:g}s")
|
|
316
|
+
table.add_row("inspector-max-exchanges", str(cfg.inspector_max_exchanges))
|
|
317
|
+
table.add_row("domains", str(len(cfg.domains)))
|
|
318
|
+
Console().print(table)
|