devdoor 0.1.0__py3-none-any.whl

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/__init__.py ADDED
@@ -0,0 +1,6 @@
1
+ """DevDoor open-source local HTTPS proxy, streaming tunnel, and TUI inspector."""
2
+
3
+ from __future__ import annotations
4
+
5
+ __version__ = "0.1.0"
6
+ __all__ = ["__version__"]
devdoor/__main__.py ADDED
@@ -0,0 +1,8 @@
1
+ """Module entrypoint enabling ``python -m devdoor``."""
2
+
3
+ from __future__ import annotations
4
+
5
+ from devdoor.cli.app import main
6
+
7
+ if __name__ == "__main__":
8
+ main()
@@ -0,0 +1 @@
1
+ """Typer command-line interface entrypoints for DevDoor."""
devdoor/cli/app.py ADDED
@@ -0,0 +1,99 @@
1
+ """Root Typer CLI application for DevDoor."""
2
+
3
+ from __future__ import annotations
4
+
5
+ import platform
6
+ import shutil
7
+ import subprocess
8
+ from collections.abc import Callable
9
+
10
+ import typer
11
+
12
+ from devdoor import __version__
13
+ from devdoor.cli.auth import config_app, login_command, logout_command
14
+ from devdoor.cli.domains import domain_app, subdomain_app
15
+ from devdoor.cli.inspector import inspect_command, logs_command
16
+ from devdoor.cli.local import (
17
+ daemon_entrypoint,
18
+ doctor_command,
19
+ down_command,
20
+ list_command,
21
+ start_command,
22
+ stop_command,
23
+ uninstall_command,
24
+ up_command,
25
+ )
26
+ from devdoor.cli.share import share_command
27
+
28
+ app = typer.Typer(
29
+ name="devdoor",
30
+ help="Open-source local HTTPS domain proxy, streaming tunnel, and TUI inspector.",
31
+ no_args_is_help=True,
32
+ )
33
+
34
+ app.command("start")(start_command)
35
+ app.command("stop")(stop_command)
36
+ app.command("up")(up_command)
37
+ app.command("down")(down_command)
38
+ app.command("list")(list_command)
39
+ app.command("ls")(list_command)
40
+ app.command("doctor")(doctor_command)
41
+ app.command("uninstall")(uninstall_command)
42
+ app.command("login")(login_command)
43
+ app.command("logout")(logout_command)
44
+ app.command("share")(share_command)
45
+ app.command("inspect")(inspect_command)
46
+ app.command("logs")(logs_command)
47
+ app.command("_daemon", hidden=True)(daemon_entrypoint)
48
+ app.add_typer(config_app, name="config")
49
+ app.add_typer(domain_app, name="domain")
50
+ app.add_typer(subdomain_app, name="subdomain")
51
+
52
+
53
+ @app.command("version")
54
+ def version_command() -> None:
55
+ """Print installed DevDoor version and Python runtime."""
56
+ typer.echo(f"devdoor {__version__} (Python {platform.python_version()})")
57
+
58
+
59
+ def detect_upgrade_command(
60
+ which_fn: Callable[[str], str | None] = shutil.which,
61
+ ) -> list[str] | None:
62
+ """Select the available user package manager command for upgrading DevDoor."""
63
+ if which_fn("uv") is not None:
64
+ return ["uv", "tool", "upgrade", "devdoor"]
65
+ if which_fn("pipx") is not None:
66
+ return ["pipx", "upgrade", "devdoor"]
67
+ if which_fn("pip") is not None:
68
+ return ["pip", "install", "-U", "devdoor"]
69
+ return None
70
+
71
+
72
+ @app.command("upgrade")
73
+ @app.command("update")
74
+ def upgrade_command(
75
+ check_only: bool = typer.Option(
76
+ False,
77
+ "--check",
78
+ help="Print upgrade command without executing it.",
79
+ ),
80
+ ) -> None:
81
+ """Upgrade DevDoor to the latest published release."""
82
+ cmd = detect_upgrade_command()
83
+ if cmd is None:
84
+ typer.secho(
85
+ "No supported package manager found. Upgrade manually with: uv tool upgrade devdoor",
86
+ fg=typer.colors.YELLOW,
87
+ )
88
+ return
89
+ if check_only:
90
+ typer.echo(f"Run: {' '.join(cmd)}")
91
+ return
92
+ result = subprocess.run(cmd, check=False)
93
+ if result.returncode != 0:
94
+ raise typer.Exit(code=result.returncode)
95
+
96
+
97
+ def main() -> None:
98
+ """Console entrypoint for the ``devdoor`` CLI."""
99
+ app()
devdoor/cli/auth.py ADDED
@@ -0,0 +1,178 @@
1
+ """CLI commands for authentication and global DevDoor configuration."""
2
+
3
+ from __future__ import annotations
4
+
5
+ import asyncio
6
+ import json
7
+
8
+ import typer
9
+ from rich.console import Console
10
+ from rich.table import Table
11
+
12
+ from devdoor.cli.validators import parse_cli_log_mode, parse_cli_port
13
+ from devdoor.core.config import (
14
+ ConfigError,
15
+ GlobalConfig,
16
+ load_global_config,
17
+ mutate_global_config,
18
+ resolve_paths,
19
+ )
20
+ from devdoor.tunnel.auth_client import (
21
+ AuthClient,
22
+ clear_credentials,
23
+ normalize_relay_url,
24
+ resolve_relay_url,
25
+ )
26
+ from devdoor.tunnel.httperr import RelayRequestError
27
+
28
+ config_app = typer.Typer(help="Inspect and update DevDoor configuration.")
29
+
30
+ _CONFIG_KEY_ALIASES: dict[str, str] = {
31
+ "relay": "relay-url",
32
+ "tld": "default-tld",
33
+ }
34
+
35
+
36
+ def _parse_bool(raw: str) -> bool:
37
+ normalized = raw.strip().lower()
38
+ if normalized in {"true", "1", "yes", "on"}:
39
+ return True
40
+ if normalized in {"false", "0", "no", "off"}:
41
+ return False
42
+ raise typer.BadParameter(f"Expected boolean value, got {raw!r}")
43
+
44
+
45
+ def login_command(
46
+ token: str | None = typer.Option(
47
+ None,
48
+ "--token",
49
+ help="Authenticate directly with a static relay API token.",
50
+ ),
51
+ provider: str | None = typer.Option(
52
+ None,
53
+ "--provider",
54
+ help="OAuth provider hint for browser sign-in (e.g., github or oidc).",
55
+ ),
56
+ relay: str | None = typer.Option(
57
+ None,
58
+ "--relay",
59
+ help="Override the DevDoor relay URL for login.",
60
+ ),
61
+ ) -> None:
62
+ """Authenticate this machine with a DevDoor relay server."""
63
+ paths = resolve_paths()
64
+ try:
65
+ relay_url = resolve_relay_url(cli_relay=relay, paths=paths)
66
+ except (ValueError, ConfigError) as exc:
67
+ typer.secho(f"Error: {exc}", fg=typer.colors.RED, err=True)
68
+ raise typer.Exit(code=1) from exc
69
+
70
+ async def _run() -> None:
71
+ async with AuthClient(paths=paths) as client:
72
+ if token is not None:
73
+ creds = await client.login_with_token(token, relay_url=relay_url)
74
+ else:
75
+ creds = await client.login_with_browser(
76
+ relay_url=relay_url,
77
+ provider=provider,
78
+ notify_fn=typer.echo,
79
+ )
80
+ identity = creds.email or creds.name or "authenticated user"
81
+ typer.echo(f"Logged in to {creds.relay_url} as {identity}.")
82
+
83
+ try:
84
+ asyncio.run(_run())
85
+ except (RelayRequestError, TimeoutError) as exc:
86
+ typer.secho(f"Login failed: {exc}", fg=typer.colors.RED, err=True)
87
+ raise typer.Exit(code=1) from exc
88
+
89
+
90
+ def logout_command() -> None:
91
+ """Remove locally stored relay authentication credentials."""
92
+ paths = resolve_paths()
93
+ removed = clear_credentials(paths=paths)
94
+ if removed:
95
+ typer.echo("Logged out and removed saved credentials.")
96
+ else:
97
+ typer.echo("Already logged out (no saved credentials found).")
98
+
99
+
100
+ @config_app.command("set")
101
+ def config_set_command(
102
+ key: str = typer.Argument(
103
+ ...,
104
+ help=(
105
+ "Setting name (relay / relay-url, default-tld, log-mode, cors, http-port, https-port)."
106
+ ),
107
+ ),
108
+ value: str = typer.Argument(..., help="New value for the setting."),
109
+ ) -> None:
110
+ """Update a global DevDoor configuration value."""
111
+ normalized_key = key.strip().lower().replace("_", "-")
112
+ normalized_key = _CONFIG_KEY_ALIASES.get(normalized_key, normalized_key)
113
+ paths = resolve_paths()
114
+
115
+ def _apply(cfg: GlobalConfig) -> GlobalConfig:
116
+ if normalized_key == "relay-url":
117
+ return cfg.model_copy(update={"relay_url": normalize_relay_url(value)})
118
+ if normalized_key == "default-tld":
119
+ tld = "." + value.strip().lower().lstrip(".")
120
+ if len(tld) < 2:
121
+ raise typer.BadParameter(f"Invalid default TLD: {value!r}")
122
+ return cfg.model_copy(update={"default_tld": tld})
123
+ if normalized_key == "log-mode":
124
+ return cfg.model_copy(update={"log_mode": parse_cli_log_mode(value)})
125
+ if normalized_key == "cors":
126
+ return cfg.model_copy(update={"cors": _parse_bool(value)})
127
+ if normalized_key == "http-port":
128
+ return cfg.model_copy(update={"http_port": parse_cli_port(value)})
129
+ if normalized_key == "https-port":
130
+ return cfg.model_copy(update={"https_port": parse_cli_port(value)})
131
+ raise typer.BadParameter(f"Unknown configuration key: {key!r}")
132
+
133
+ try:
134
+ mutate_global_config(_apply, paths=paths)
135
+ except ValueError as exc:
136
+ typer.secho(f"Error: {exc}", fg=typer.colors.RED, err=True)
137
+ raise typer.Exit(code=1) from exc
138
+
139
+ typer.echo(f"Updated {normalized_key}.")
140
+
141
+
142
+ @config_app.command("show")
143
+ def config_show_command(
144
+ json_output: bool = typer.Option(
145
+ False,
146
+ "--json",
147
+ help="Print configuration as JSON.",
148
+ ),
149
+ ) -> None:
150
+ """Display the current global DevDoor configuration."""
151
+ paths = resolve_paths()
152
+ cfg = load_global_config(paths)
153
+ if json_output:
154
+ payload = {
155
+ "home": str(paths.home),
156
+ "relay_url": resolve_relay_url(paths=paths),
157
+ "default_tld": cfg.default_tld,
158
+ "log_mode": cfg.log_mode,
159
+ "cors": cfg.cors,
160
+ "http_port": cfg.http_port,
161
+ "https_port": cfg.https_port,
162
+ "domain_count": len(cfg.domains),
163
+ }
164
+ typer.echo(json.dumps(payload, indent=2))
165
+ return
166
+
167
+ table = Table(title="DevDoor Configuration")
168
+ table.add_column("Key", style="cyan")
169
+ table.add_column("Value")
170
+ table.add_row("home", str(paths.home))
171
+ table.add_row("relay-url", resolve_relay_url(paths=paths))
172
+ table.add_row("default-tld", cfg.default_tld or "(platform default)")
173
+ table.add_row("log-mode", cfg.log_mode)
174
+ table.add_row("cors", str(cfg.cors).lower())
175
+ table.add_row("http-port", str(cfg.http_port))
176
+ table.add_row("https-port", str(cfg.https_port))
177
+ table.add_row("domains", str(len(cfg.domains)))
178
+ Console().print(table)
devdoor/cli/domains.py ADDED
@@ -0,0 +1,214 @@
1
+ """CLI subcommands for custom domains and reserved vanity subdomains."""
2
+
3
+ from __future__ import annotations
4
+
5
+ import asyncio
6
+ import json
7
+
8
+ import typer
9
+ from rich.console import Console
10
+ from rich.table import Table
11
+
12
+ from devdoor.core.config import resolve_paths
13
+ from devdoor.tunnel.auth_client import resolve_auth_token, resolve_relay_url
14
+ from devdoor.tunnel.httperr import RelayRequestError
15
+ from devdoor.tunnel.relay_api import DomainRecord, RelayApiClient
16
+
17
+ domain_app = typer.Typer(help="Manage verified custom domains on the relay.")
18
+ subdomain_app = typer.Typer(help="Manage reserved vanity subdomains on the relay.")
19
+
20
+
21
+ def _require_client_args(relay: str | None) -> tuple[str, str]:
22
+ paths = resolve_paths()
23
+ token = resolve_auth_token(paths=paths)
24
+ if not token:
25
+ typer.secho("Not logged in. Run 'devdoor login' first.", fg=typer.colors.RED, err=True)
26
+ raise typer.Exit(code=1)
27
+ try:
28
+ relay_url = resolve_relay_url(cli_relay=relay, paths=paths)
29
+ except ValueError as exc:
30
+ typer.secho(f"Invalid relay URL: {exc}", fg=typer.colors.RED, err=True)
31
+ raise typer.Exit(code=1) from exc
32
+ return relay_url, token
33
+
34
+
35
+ def _print_dns_instructions(record: DomainRecord) -> None:
36
+ typer.echo(f"Domain: {record.domain} (id: {record.id})")
37
+ if record.txt_name and record.txt_value:
38
+ typer.echo(f" TXT {record.txt_name} -> {record.txt_value}")
39
+ if record.cname_target:
40
+ typer.echo(f" CNAME {record.domain} -> {record.cname_target}")
41
+ elif record.a_target:
42
+ typer.echo(f" A {record.domain} -> {record.a_target}")
43
+
44
+
45
+ @domain_app.command("add")
46
+ def domain_add_command(
47
+ fqdn: str = typer.Argument(..., help="Custom fully qualified domain name to register."),
48
+ relay: str | None = typer.Option(None, "--relay", help="Override relay URL."),
49
+ json_output: bool = typer.Option(False, "--json", help="Print output as JSON."),
50
+ ) -> None:
51
+ """Register a custom domain and print DNS verification records."""
52
+ relay_url, token = _require_client_args(relay)
53
+
54
+ async def _run() -> DomainRecord:
55
+ async with RelayApiClient(relay_url=relay_url, token=token) as client:
56
+ return await client.add_domain(fqdn)
57
+
58
+ try:
59
+ record = asyncio.run(_run())
60
+ except (RelayRequestError, ValueError) as exc:
61
+ typer.secho(f"Failed to add domain: {exc}", fg=typer.colors.RED, err=True)
62
+ raise typer.Exit(code=1) from exc
63
+
64
+ if json_output:
65
+ typer.echo(record.model_dump_json(indent=2))
66
+ return
67
+ _print_dns_instructions(record)
68
+
69
+
70
+ @domain_app.command("list")
71
+ def domain_list_command(
72
+ relay: str | None = typer.Option(None, "--relay", help="Override relay URL."),
73
+ json_output: bool = typer.Option(False, "--json", help="Print output as JSON."),
74
+ ) -> None:
75
+ """List custom domains registered to your account."""
76
+ relay_url, token = _require_client_args(relay)
77
+
78
+ async def _run() -> list[DomainRecord]:
79
+ async with RelayApiClient(relay_url=relay_url, token=token) as client:
80
+ return await client.list_domains()
81
+
82
+ try:
83
+ records = asyncio.run(_run())
84
+ except RelayRequestError as exc:
85
+ typer.secho(f"Failed to list domains: {exc}", fg=typer.colors.RED, err=True)
86
+ raise typer.Exit(code=1) from exc
87
+
88
+ if json_output:
89
+ typer.echo(json.dumps([item.model_dump() for item in records], indent=2))
90
+ return
91
+
92
+ table = Table(title="Custom Domains")
93
+ table.add_column("Domain", style="cyan")
94
+ table.add_column("Verified")
95
+ table.add_column("CNAME / Target")
96
+ for item in records:
97
+ status = "yes" if item.verified else "pending"
98
+ target = item.cname_target or item.a_target or "-"
99
+ table.add_row(item.domain, status, target)
100
+ Console().print(table)
101
+
102
+
103
+ @domain_app.command("verify")
104
+ def domain_verify_command(
105
+ fqdn: str = typer.Argument(..., help="Custom domain name or ID to verify."),
106
+ relay: str | None = typer.Option(None, "--relay", help="Override relay URL."),
107
+ json_output: bool = typer.Option(False, "--json", help="Print output as JSON."),
108
+ ) -> None:
109
+ """Verify DNS ownership records for a registered custom domain."""
110
+ relay_url, token = _require_client_args(relay)
111
+
112
+ async def _run() -> DomainRecord:
113
+ async with RelayApiClient(relay_url=relay_url, token=token) as client:
114
+ return await client.verify_domain(fqdn)
115
+
116
+ try:
117
+ record = asyncio.run(_run())
118
+ except RelayRequestError as exc:
119
+ typer.secho(f"Verification failed: {exc}", fg=typer.colors.RED, err=True)
120
+ raise typer.Exit(code=1) from exc
121
+
122
+ if json_output:
123
+ typer.echo(record.model_dump_json(indent=2))
124
+ return
125
+ state = "verified" if record.verified else "pending DNS propagation"
126
+ typer.echo(f"{record.domain}: {state}")
127
+
128
+
129
+ @domain_app.command("remove")
130
+ def domain_remove_command(
131
+ fqdn: str = typer.Argument(..., help="Custom domain name or ID to remove."),
132
+ force: bool = typer.Option(False, "--force", "-f", help="Disconnect active tunnels."),
133
+ yes: bool = typer.Option(False, "--yes", "-y", help="Skip confirmation prompt on conflict."),
134
+ relay: str | None = typer.Option(None, "--relay", help="Override relay URL."),
135
+ ) -> None:
136
+ """Remove a registered custom domain from your account."""
137
+ relay_url, token = _require_client_args(relay)
138
+
139
+ async def _delete(*, use_force: bool) -> None:
140
+ async with RelayApiClient(relay_url=relay_url, token=token) as client:
141
+ await client.remove_domain(fqdn, force=use_force)
142
+
143
+ try:
144
+ asyncio.run(_delete(use_force=force))
145
+ except RelayRequestError as exc:
146
+ if exc.status == 409 and not force:
147
+ confirmed = yes or typer.confirm(
148
+ f"{fqdn} has an active tunnel. Force remove and drop the tunnel?"
149
+ )
150
+ if not confirmed:
151
+ raise typer.Exit(code=1) from exc
152
+ try:
153
+ asyncio.run(_delete(use_force=True))
154
+ except RelayRequestError as retry_exc:
155
+ typer.secho(f"Remove failed: {retry_exc}", fg=typer.colors.RED, err=True)
156
+ raise typer.Exit(code=1) from retry_exc
157
+ else:
158
+ typer.secho(f"Remove failed: {exc}", fg=typer.colors.RED, err=True)
159
+ raise typer.Exit(code=1) from exc
160
+
161
+ typer.echo(f"Removed custom domain {fqdn}.")
162
+
163
+
164
+ @subdomain_app.command("list")
165
+ def subdomain_list_command(
166
+ relay: str | None = typer.Option(None, "--relay", help="Override relay URL."),
167
+ json_output: bool = typer.Option(False, "--json", help="Print output as JSON."),
168
+ ) -> None:
169
+ """List reserved vanity subdomains on your account."""
170
+ relay_url, token = _require_client_args(relay)
171
+
172
+ async def _run() -> list[dict[str, object]]:
173
+ async with RelayApiClient(relay_url=relay_url, token=token) as client:
174
+ records = await client.list_subdomains()
175
+ return [item.model_dump() for item in records]
176
+
177
+ try:
178
+ items = asyncio.run(_run())
179
+ except RelayRequestError as exc:
180
+ typer.secho(f"Failed to list subdomains: {exc}", fg=typer.colors.RED, err=True)
181
+ raise typer.Exit(code=1) from exc
182
+
183
+ if json_output:
184
+ typer.echo(json.dumps(items, indent=2))
185
+ return
186
+
187
+ table = Table(title="Reserved Subdomains")
188
+ table.add_column("Subdomain", style="cyan")
189
+ table.add_column("URL")
190
+ table.add_column("Active")
191
+ for item in items:
192
+ table.add_row(str(item["name"]), str(item["url"]), "yes" if item["active"] else "no")
193
+ Console().print(table)
194
+
195
+
196
+ @subdomain_app.command("release")
197
+ def subdomain_release_command(
198
+ name: str = typer.Argument(..., help="Reserved subdomain name to release."),
199
+ relay: str | None = typer.Option(None, "--relay", help="Override relay URL."),
200
+ ) -> None:
201
+ """Release a reserved vanity subdomain back to the shared pool."""
202
+ relay_url, token = _require_client_args(relay)
203
+
204
+ async def _run() -> None:
205
+ async with RelayApiClient(relay_url=relay_url, token=token) as client:
206
+ await client.release_subdomain(name)
207
+
208
+ try:
209
+ asyncio.run(_run())
210
+ except RelayRequestError as exc:
211
+ typer.secho(f"Failed to release subdomain: {exc}", fg=typer.colors.RED, err=True)
212
+ raise typer.Exit(code=1) from exc
213
+
214
+ typer.echo(f"Released subdomain {name}.")