developer-platform-cli 0.1.0__py3-none-any.whl → 0.3.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.
- {developer_platform_cli-0.1.0.dist-info → developer_platform_cli-0.3.0.dist-info}/METADATA +15 -6
- developer_platform_cli-0.3.0.dist-info/RECORD +16 -0
- platform_cli/__init__.py +1 -1
- platform_cli/__main__.py +337 -30
- platform_cli/api_contract.json +8292 -0
- platform_cli/authentication.py +136 -0
- platform_cli/client.py +104 -12
- platform_cli/commands.py +467 -0
- platform_cli/config.py +19 -4
- platform_cli/errors.py +2 -2
- platform_cli/models.py +22 -0
- platform_cli/profiles.py +155 -0
- platform_cli/registry.py +187 -0
- platform_cli/tunnel.py +78 -0
- developer_platform_cli-0.1.0.dist-info/RECORD +0 -10
- {developer_platform_cli-0.1.0.dist-info → developer_platform_cli-0.3.0.dist-info}/WHEEL +0 -0
- {developer_platform_cli-0.1.0.dist-info → developer_platform_cli-0.3.0.dist-info}/entry_points.txt +0 -0
|
@@ -1,9 +1,11 @@
|
|
|
1
|
-
Metadata-Version: 2.
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
2
|
Name: developer-platform-cli
|
|
3
|
-
Version: 0.
|
|
3
|
+
Version: 0.3.0
|
|
4
4
|
Summary: Command-line client for the Developer Platform API
|
|
5
5
|
Requires-Python: >=3.12
|
|
6
6
|
Requires-Dist: httpx<1,>=0.28
|
|
7
|
+
Requires-Dist: keyring<26,>=25
|
|
8
|
+
Requires-Dist: platformdirs<5,>=4
|
|
7
9
|
Requires-Dist: pydantic<3,>=2.10
|
|
8
10
|
Requires-Dist: rich<14,>=13.9
|
|
9
11
|
Requires-Dist: typer<1,>=0.15
|
|
@@ -14,9 +16,13 @@ Description-Content-Type: text/markdown
|
|
|
14
16
|
|
|
15
17
|
# Developer Platform CLI
|
|
16
18
|
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
19
|
+
This source-adjacent README provides the minimal development example. The
|
|
20
|
+
canonical user documentation is the [CLI guide](../../docs/developers/cli.md);
|
|
21
|
+
implementation ownership is in the [maintainer guide](../../docs/maintainers/cli.md).
|
|
22
|
+
|
|
23
|
+
`devplat` is the command-line client for the Developer Platform API. It supports
|
|
24
|
+
CI deployments and project administration, including hosted application access.
|
|
25
|
+
Use `devplat --help` and `devplat access --help` to inspect commands.
|
|
20
26
|
|
|
21
27
|
Install an editable development copy:
|
|
22
28
|
|
|
@@ -37,4 +43,7 @@ devplat deploy apply --project hello --file examples/project.json --wait
|
|
|
37
43
|
|
|
38
44
|
`PLATFORM_ACCESS_TOKEN` may be used instead of the deployment-credential variables
|
|
39
45
|
for a short-lived, externally obtained token. The CLI never persists either form of
|
|
40
|
-
authentication material.
|
|
46
|
+
authentication material. Deployment credentials authorize deployment and observation
|
|
47
|
+
only; access administration requires a human project-administrator login or an
|
|
48
|
+
externally supplied administrator token. See the [CLI guide](../../docs/developers/cli.md)
|
|
49
|
+
for profiles, login, access commands, and versioned updates.
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
platform_cli/__init__.py,sha256=-5ircjNc_Qf9IbNPFW7cDmcZ7vRY_DBg56Xlw5TfZGo,69
|
|
2
|
+
platform_cli/__main__.py,sha256=8ali54MOYXtfbz61GYVSoHMeMnvfhOX1zUoVDkYpf90,19230
|
|
3
|
+
platform_cli/api_contract.json,sha256=xbd-LzF0UNvG6WM1-RX8uaPgLv3Vl3BgME0KDHPXK8k,210668
|
|
4
|
+
platform_cli/authentication.py,sha256=zMXky1tj2zi5WddkUtwZC0UE32BDGcAtY1VqlH40D8M,7071
|
|
5
|
+
platform_cli/client.py,sha256=5pWCgYIA5UXHicq0xmry6-3Zi2jXB91Tigr2yB9NKP8,10788
|
|
6
|
+
platform_cli/commands.py,sha256=lH4Lwsv8zl2swrg4Mx-rcebumg5n3bci_BbNQqeAALI,23952
|
|
7
|
+
platform_cli/config.py,sha256=5bnFRT4Z_qgQ6WWa4mODvidUuqzwsxwCKj1mMOhJOYA,3776
|
|
8
|
+
platform_cli/errors.py,sha256=jc8COhzP0KKYu93w9ZaVMLfXy5FT5bfSUvuKeOrhcZM,1188
|
|
9
|
+
platform_cli/models.py,sha256=DeUjuS0ma8dXPDHch8xnj0dQrtvq7PvOe_Bu4EIukUQ,1756
|
|
10
|
+
platform_cli/profiles.py,sha256=KMaiKFxf3NTc0bfSDa4E5kNs_Mby4BuXtBc9VG_G1Nc,6263
|
|
11
|
+
platform_cli/registry.py,sha256=9_CkVxtnx8ubDQYH9JOi1oBdLJB8XboK2ncLaCfsiow,16405
|
|
12
|
+
platform_cli/tunnel.py,sha256=OHvhQLpwmhKgqOc_T2tTl4Y8GM043Ji4wncVFwa09Co,3727
|
|
13
|
+
developer_platform_cli-0.3.0.dist-info/METADATA,sha256=KuCAQq-2JV2Z8hYs4VN57umR2Y8U0v-P_QQ0c-5QjB8,2045
|
|
14
|
+
developer_platform_cli-0.3.0.dist-info/WHEEL,sha256=W3fkpkm7-wf9vBI5Z-7s0eWkeM-spu78I8Neb98DeEg,87
|
|
15
|
+
developer_platform_cli-0.3.0.dist-info/entry_points.txt,sha256=M7MpiSzj86vx01JPP3zjnrykkQuxJjTnS9o5Rs0CAkI,55
|
|
16
|
+
developer_platform_cli-0.3.0.dist-info/RECORD,,
|
platform_cli/__init__.py
CHANGED
platform_cli/__main__.py
CHANGED
|
@@ -3,6 +3,8 @@
|
|
|
3
3
|
from __future__ import annotations
|
|
4
4
|
|
|
5
5
|
import json
|
|
6
|
+
from dataclasses import asdict, dataclass
|
|
7
|
+
import os
|
|
6
8
|
from pathlib import Path
|
|
7
9
|
import sys
|
|
8
10
|
import time
|
|
@@ -10,19 +12,72 @@ from typing import Annotated
|
|
|
10
12
|
|
|
11
13
|
import typer
|
|
12
14
|
|
|
13
|
-
from .client import
|
|
15
|
+
from .client import PlatformClient, wait_for_operation
|
|
14
16
|
from .config import ConfigurationError, authentication_source, runtime_config
|
|
15
17
|
from .errors import ApiError
|
|
16
18
|
from .models import OperationStatus, application_body
|
|
19
|
+
from .commands import context_state as _state, emit, fail, register, watch_access
|
|
20
|
+
from .profiles import Profile, ProfileStore, SessionStore
|
|
21
|
+
from .registry import COMMANDS
|
|
22
|
+
from .tunnel import run_tunnel, ssh_command
|
|
17
23
|
|
|
18
24
|
|
|
19
25
|
app = typer.Typer(no_args_is_help=True, add_completion=False, help="Developer Platform command-line client.")
|
|
20
26
|
deploy_app = typer.Typer(no_args_is_help=True, help="Deploy versioned application specifications.")
|
|
21
|
-
auth_app = typer.Typer(no_args_is_help=True, help="Inspect
|
|
27
|
+
auth_app = typer.Typer(no_args_is_help=True, help="Inspect, create, or clear human login sessions.")
|
|
22
28
|
app.add_typer(deploy_app, name="deploy")
|
|
23
29
|
app.add_typer(auth_app, name="auth")
|
|
24
30
|
|
|
25
31
|
|
|
32
|
+
def _version_callback(value: bool):
|
|
33
|
+
if value:
|
|
34
|
+
from importlib.metadata import version
|
|
35
|
+
typer.echo(version("developer-platform-cli"))
|
|
36
|
+
raise typer.Exit()
|
|
37
|
+
|
|
38
|
+
|
|
39
|
+
@dataclass(frozen=True)
|
|
40
|
+
class Settings:
|
|
41
|
+
profile: str | None = None
|
|
42
|
+
api_url: str | None = None
|
|
43
|
+
output: str | None = None
|
|
44
|
+
insecure: bool = False
|
|
45
|
+
quiet: bool = False
|
|
46
|
+
debug: bool = False
|
|
47
|
+
|
|
48
|
+
|
|
49
|
+
@app.callback()
|
|
50
|
+
def root(ctx: typer.Context,
|
|
51
|
+
version: Annotated[bool, typer.Option("--version", callback=_version_callback, is_eager=True,
|
|
52
|
+
help="Show the installed CLI version.")] = False,
|
|
53
|
+
profile: Annotated[str | None, typer.Option("--profile")] = None,
|
|
54
|
+
api_url: Annotated[str | None, typer.Option("--api-url")] = None,
|
|
55
|
+
output: Annotated[str | None, typer.Option("--output")] = None,
|
|
56
|
+
no_color: Annotated[bool, typer.Option("--no-color")] = False,
|
|
57
|
+
quiet: Annotated[bool, typer.Option("--quiet")] = False,
|
|
58
|
+
debug: Annotated[bool, typer.Option("--debug")] = False,
|
|
59
|
+
insecure: Annotated[bool, typer.Option("--insecure")] = False):
|
|
60
|
+
if output and output not in {"table", "plain", "json"}:
|
|
61
|
+
raise typer.BadParameter("Use table, plain, or json.", param_hint="--output")
|
|
62
|
+
if no_color:
|
|
63
|
+
import os
|
|
64
|
+
os.environ["NO_COLOR"] = "1"
|
|
65
|
+
if insecure:
|
|
66
|
+
typer.echo("TLS verification disabled for this invocation.", err=True)
|
|
67
|
+
ctx.obj = Settings(profile, api_url, output, insecure, quiet, debug)
|
|
68
|
+
|
|
69
|
+
|
|
70
|
+
def _effective_output(ctx: typer.Context, output: str | None) -> str:
|
|
71
|
+
if output or _state(ctx).output:
|
|
72
|
+
return output or _state(ctx).output
|
|
73
|
+
if not _state(ctx).profile and os.environ.get("PLATFORM_API_URL") and any(
|
|
74
|
+
os.environ.get(key) for key in ("PLATFORM_ACCESS_TOKEN", "PLATFORM_TOKEN_ENDPOINT",
|
|
75
|
+
"PLATFORM_CLIENT_ID", "PLATFORM_CLIENT_SECRET")):
|
|
76
|
+
return "table"
|
|
77
|
+
_, selected = ProfileStore().selected(_state(ctx).profile)
|
|
78
|
+
return selected.output if selected else "table"
|
|
79
|
+
|
|
80
|
+
|
|
26
81
|
def _read_json(path: str) -> dict[str, object]:
|
|
27
82
|
try:
|
|
28
83
|
contents = sys.stdin.read() if path == "-" else Path(path).read_text(encoding="utf-8")
|
|
@@ -41,56 +96,47 @@ def _emit(value: object, output: str) -> None:
|
|
|
41
96
|
typer.echo(str(value))
|
|
42
97
|
|
|
43
98
|
|
|
44
|
-
def _failure(error: Exception, output: str) -> typer.Exit:
|
|
45
|
-
if isinstance(error, ApiError):
|
|
46
|
-
payload = {"status": error.status_code, "detail": error.detail, "code": error.code, "request_id": error.request_id}
|
|
47
|
-
if output == "json":
|
|
48
|
-
typer.echo(json.dumps(payload, separators=(",", ":")), err=True)
|
|
49
|
-
else:
|
|
50
|
-
typer.echo(error.detail, err=True)
|
|
51
|
-
return typer.Exit(error.exit_code)
|
|
52
|
-
if isinstance(error, ConfigurationError):
|
|
53
|
-
typer.echo(str(error), err=True)
|
|
54
|
-
return typer.Exit(2)
|
|
55
|
-
if isinstance(error, OperationFailed):
|
|
56
|
-
typer.echo(f"Operation {error.status.operation_id} failed: {error}", err=True)
|
|
57
|
-
return typer.Exit(9)
|
|
58
|
-
if isinstance(error, OperationTimeout):
|
|
59
|
-
typer.echo(f"{error} Resume with devplat operations watch {error.operation_id} when available.", err=True)
|
|
60
|
-
return typer.Exit(10)
|
|
61
|
-
typer.echo(str(error), err=True)
|
|
62
|
-
return typer.Exit(8)
|
|
63
|
-
|
|
64
|
-
|
|
65
99
|
@auth_app.command("status")
|
|
66
100
|
def auth_status(
|
|
67
|
-
|
|
101
|
+
ctx: typer.Context,
|
|
102
|
+
output: Annotated[str | None, typer.Option("--output", case_sensitive=False)] = None,
|
|
68
103
|
) -> None:
|
|
69
104
|
"""Show the active authentication source without disclosing credentials."""
|
|
70
105
|
try:
|
|
71
|
-
|
|
72
|
-
|
|
106
|
+
config = runtime_config(profile_name=_state(ctx).profile, api_url_override=_state(ctx).api_url,
|
|
107
|
+
insecure=_state(ctx).insecure)
|
|
108
|
+
source = authentication_source(config)
|
|
109
|
+
result = {"source": source, "persistent": False}
|
|
110
|
+
if source == "human-profile-session":
|
|
111
|
+
session = SessionStore(config.profile_name, config.profile).get()
|
|
112
|
+
result = {"source": source, "persistent": bool(session), "profile": config.profile_name,
|
|
113
|
+
"subject": session["subject"] if session else None}
|
|
114
|
+
_emit(result, _effective_output(ctx, output))
|
|
73
115
|
except Exception as error:
|
|
74
|
-
raise
|
|
116
|
+
raise fail(error, output or _state(ctx).output or "table") from None
|
|
75
117
|
|
|
76
118
|
|
|
77
119
|
@deploy_app.command("apply")
|
|
78
120
|
def deploy_apply(
|
|
121
|
+
ctx: typer.Context,
|
|
79
122
|
project: Annotated[str, typer.Option("--project", min=1, help="Target project name.")],
|
|
80
123
|
file: Annotated[str, typer.Option("--file", help="JSON specification file, or - for stdin.")],
|
|
81
124
|
wait: Annotated[bool, typer.Option("--wait", help="Wait for durable operation success and readiness.")] = False,
|
|
82
125
|
timeout: Annotated[float, typer.Option("--timeout", min=1.0, help="Maximum wait time in seconds.")] = 300.0,
|
|
83
126
|
poll_interval: Annotated[float, typer.Option("--poll-interval", min=0.1, help="Operation poll interval in seconds.")] = 2.0,
|
|
84
127
|
if_match: Annotated[str | None, typer.Option("--if-match", help="Expected current revision.")] = None,
|
|
85
|
-
output: Annotated[str, typer.Option("--output", case_sensitive=False)] =
|
|
128
|
+
output: Annotated[str | None, typer.Option("--output", case_sensitive=False)] = None,
|
|
86
129
|
) -> None:
|
|
87
130
|
"""Apply one JSON application specification using environment authentication."""
|
|
131
|
+
output = _effective_output(ctx, output)
|
|
88
132
|
if output not in {"table", "json", "plain"}:
|
|
89
133
|
raise typer.BadParameter("must be table, json, or plain", param_hint="--output")
|
|
90
134
|
try:
|
|
91
135
|
body = _read_json(file)
|
|
92
|
-
config = runtime_config()
|
|
136
|
+
config = runtime_config(profile_name=_state(ctx).profile, api_url_override=_state(ctx).api_url,
|
|
137
|
+
insecure=_state(ctx).insecure)
|
|
93
138
|
client = PlatformClient(config)
|
|
139
|
+
client.debug = _state(ctx).debug
|
|
94
140
|
try:
|
|
95
141
|
token = client.access_token()
|
|
96
142
|
accepted = client.deploy(project, body, token, if_match)
|
|
@@ -117,7 +163,268 @@ def deploy_apply(
|
|
|
117
163
|
typer.echo("Waiting interrupted; the durable platform operation continues.", err=True)
|
|
118
164
|
raise typer.Exit(10) from None
|
|
119
165
|
except Exception as error:
|
|
120
|
-
raise
|
|
166
|
+
raise fail(error, output) from None
|
|
167
|
+
|
|
168
|
+
|
|
169
|
+
profiles_app = typer.Typer(no_args_is_help=True, help="Named non-secret connection profiles.")
|
|
170
|
+
app.add_typer(profiles_app, name="profiles")
|
|
171
|
+
|
|
172
|
+
|
|
173
|
+
@profiles_app.command("create")
|
|
174
|
+
def profile_create(name: str, api_url: Annotated[str, typer.Option("--api-url")],
|
|
175
|
+
issuer: Annotated[str, typer.Option("--issuer")],
|
|
176
|
+
client_id: Annotated[str, typer.Option("--client-id")] = "platform-cli",
|
|
177
|
+
ca_bundle: Annotated[str | None, typer.Option("--ca-bundle")] = None,
|
|
178
|
+
project: Annotated[str | None, typer.Option("--project")] = None,
|
|
179
|
+
output: Annotated[str, typer.Option("--output")] = "table"):
|
|
180
|
+
"""Save only API and OIDC connection settings."""
|
|
181
|
+
try:
|
|
182
|
+
store = ProfileStore()
|
|
183
|
+
store.create(name, Profile(api_url, issuer, client_id, ca_bundle, project, output))
|
|
184
|
+
emit({"profile": name, "active": store.read().get("active") == name}, output)
|
|
185
|
+
except Exception as error:
|
|
186
|
+
raise fail(error, output) from None
|
|
187
|
+
|
|
188
|
+
|
|
189
|
+
@profiles_app.command("show")
|
|
190
|
+
def profile_show(ctx: typer.Context, name: str | None = None,
|
|
191
|
+
output: Annotated[str | None, typer.Option("--output")] = None):
|
|
192
|
+
"""Display a profile without credentials."""
|
|
193
|
+
try:
|
|
194
|
+
selected, profile = ProfileStore().selected(name or _state(ctx).profile)
|
|
195
|
+
if profile is None:
|
|
196
|
+
raise ConfigurationError("No profile selected.")
|
|
197
|
+
emit({"name": selected, **asdict(profile)}, _effective_output(ctx, output))
|
|
198
|
+
except Exception as error:
|
|
199
|
+
raise fail(error, output or _state(ctx).output or "table") from None
|
|
200
|
+
|
|
201
|
+
|
|
202
|
+
@profiles_app.command("use")
|
|
203
|
+
def profile_use(name: str):
|
|
204
|
+
"""Select the default profile."""
|
|
205
|
+
try:
|
|
206
|
+
ProfileStore().use(name)
|
|
207
|
+
emit({"active": name}, "table")
|
|
208
|
+
except Exception as error:
|
|
209
|
+
raise fail(error) from None
|
|
210
|
+
|
|
211
|
+
|
|
212
|
+
@profiles_app.command("delete")
|
|
213
|
+
def profile_delete(name: str):
|
|
214
|
+
"""Remove a profile and its bound keyring session."""
|
|
215
|
+
try:
|
|
216
|
+
_, profile = ProfileStore().selected(name)
|
|
217
|
+
SessionStore(name, profile).delete()
|
|
218
|
+
ProfileStore().delete(name)
|
|
219
|
+
emit({"deleted": name}, "table")
|
|
220
|
+
except Exception as error:
|
|
221
|
+
raise fail(error) from None
|
|
222
|
+
|
|
223
|
+
|
|
224
|
+
@auth_app.command("login")
|
|
225
|
+
def auth_login(ctx: typer.Context,
|
|
226
|
+
timeout: Annotated[float, typer.Option("--timeout", min=1)] = 300,
|
|
227
|
+
open_browser: Annotated[bool, typer.Option("--open-browser")] = False,
|
|
228
|
+
output: Annotated[str | None, typer.Option("--output")] = None):
|
|
229
|
+
"""Sign in with OIDC Device Authorization and PKCE."""
|
|
230
|
+
selected_output = _effective_output(ctx, output)
|
|
231
|
+
try:
|
|
232
|
+
client = PlatformClient(runtime_config(profile_name=_state(ctx).profile,
|
|
233
|
+
api_url_override=_state(ctx).api_url, insecure=_state(ctx).insecure))
|
|
234
|
+
try:
|
|
235
|
+
def notify(uri: str, code: str):
|
|
236
|
+
typer.echo("Open " + uri + " and enter code " + code, err=True)
|
|
237
|
+
if open_browser:
|
|
238
|
+
import webbrowser
|
|
239
|
+
webbrowser.open(uri)
|
|
240
|
+
subject = client.human_authentication().login(notify, timeout=timeout)
|
|
241
|
+
emit({"profile": client.config.profile_name, "subject": subject}, selected_output)
|
|
242
|
+
finally:
|
|
243
|
+
client.close()
|
|
244
|
+
except KeyboardInterrupt:
|
|
245
|
+
raise typer.Exit(10) from None
|
|
246
|
+
except Exception as error:
|
|
247
|
+
raise fail(error, selected_output) from None
|
|
248
|
+
|
|
249
|
+
|
|
250
|
+
@auth_app.command("logout")
|
|
251
|
+
def auth_logout(ctx: typer.Context,
|
|
252
|
+
output: Annotated[str | None, typer.Option("--output")] = None):
|
|
253
|
+
"""Clear the human session and request provider revocation."""
|
|
254
|
+
selected_output = _effective_output(ctx, output)
|
|
255
|
+
try:
|
|
256
|
+
client = PlatformClient(runtime_config(profile_name=_state(ctx).profile,
|
|
257
|
+
api_url_override=_state(ctx).api_url, insecure=_state(ctx).insecure))
|
|
258
|
+
try:
|
|
259
|
+
client.human_authentication().logout()
|
|
260
|
+
emit({"profile": client.config.profile_name, "logged_out": True}, selected_output)
|
|
261
|
+
finally:
|
|
262
|
+
client.close()
|
|
263
|
+
except Exception as error:
|
|
264
|
+
raise fail(error, selected_output) from None
|
|
265
|
+
|
|
266
|
+
|
|
267
|
+
def _tree(parent: typer.Typer, names: tuple[str, ...]) -> typer.Typer:
|
|
268
|
+
for name in names:
|
|
269
|
+
children = getattr(parent, "_devplat_children", None)
|
|
270
|
+
if children is None:
|
|
271
|
+
children = {}
|
|
272
|
+
setattr(parent, "_devplat_children", children)
|
|
273
|
+
if name not in children:
|
|
274
|
+
child = typer.Typer(no_args_is_help=True, help=name.replace("-", " ").capitalize() + " commands.")
|
|
275
|
+
parent.add_typer(child, name=name)
|
|
276
|
+
children[name] = child
|
|
277
|
+
parent = children[name]
|
|
278
|
+
return parent
|
|
279
|
+
|
|
280
|
+
|
|
281
|
+
for specification in COMMANDS:
|
|
282
|
+
if specification.command == "deploy apply":
|
|
283
|
+
continue
|
|
284
|
+
if specification.command == "logs":
|
|
285
|
+
register(_tree(app, ("logs",)), specification)
|
|
286
|
+
continue
|
|
287
|
+
parts = specification.command.split()
|
|
288
|
+
register(_tree(app, tuple(parts[:-1])), specification)
|
|
289
|
+
|
|
290
|
+
|
|
291
|
+
def _client(ctx: typer.Context) -> PlatformClient:
|
|
292
|
+
client = PlatformClient(runtime_config(profile_name=_state(ctx).profile,
|
|
293
|
+
api_url_override=_state(ctx).api_url, insecure=_state(ctx).insecure))
|
|
294
|
+
client.debug = _state(ctx).debug
|
|
295
|
+
return client
|
|
296
|
+
|
|
297
|
+
|
|
298
|
+
@_tree(app, ("stores", "access")).command("tunnel")
|
|
299
|
+
def stores_access_tunnel(ctx: typer.Context, credential_id: str,
|
|
300
|
+
identity_file: Annotated[str, typer.Option("--identity-file", help="Private Ed25519 key registered with the platform.")],
|
|
301
|
+
known_hosts: Annotated[str, typer.Option("--known-hosts", help="Verified SSH host key file.")],
|
|
302
|
+
local_port: Annotated[int, typer.Option("--local-port", min=1, max=65535)]):
|
|
303
|
+
"""Forward an active store lease to a local TCP port until interrupted."""
|
|
304
|
+
try:
|
|
305
|
+
from uuid import UUID
|
|
306
|
+
credential_id = str(UUID(credential_id))
|
|
307
|
+
client = _client(ctx)
|
|
308
|
+
try:
|
|
309
|
+
credential, _ = client.request_json("GET", "/v1/store-access/credentials/" + credential_id)
|
|
310
|
+
finally:
|
|
311
|
+
client.close()
|
|
312
|
+
command = ssh_command(credential, identity_file, known_hosts, local_port)
|
|
313
|
+
typer.echo(f"{credential['provider']} tunnel on 127.0.0.1:{local_port}; press Ctrl-C to close.", err=True)
|
|
314
|
+
result = run_tunnel(command)
|
|
315
|
+
if result:
|
|
316
|
+
raise typer.Exit(result)
|
|
317
|
+
except KeyboardInterrupt:
|
|
318
|
+
raise typer.Exit(10) from None
|
|
319
|
+
except typer.Exit:
|
|
320
|
+
raise
|
|
321
|
+
except Exception as error:
|
|
322
|
+
raise fail(error) from None
|
|
323
|
+
|
|
324
|
+
|
|
325
|
+
@app.command("status")
|
|
326
|
+
def status(ctx: typer.Context, project: Annotated[str | None, typer.Option("--project")] = None,
|
|
327
|
+
output: Annotated[str | None, typer.Option("--output")] = None):
|
|
328
|
+
"""Inspect project metadata and component state."""
|
|
329
|
+
selected_output = _effective_output(ctx, output)
|
|
330
|
+
try:
|
|
331
|
+
client = _client(ctx)
|
|
332
|
+
try:
|
|
333
|
+
project = project or (client.config.profile.project if client.config.profile else None)
|
|
334
|
+
if not project:
|
|
335
|
+
raise ConfigurationError("Supply --project or select a profile with a default project.")
|
|
336
|
+
projects, _ = client.request_json("GET", "/projects")
|
|
337
|
+
row = next((item for item in projects if item.get("name") == project), None)
|
|
338
|
+
if row is None:
|
|
339
|
+
raise ApiError(404, "Project not found in authorized project list.")
|
|
340
|
+
components, _ = client.request_json("GET", "/projects/" + project + "/components")
|
|
341
|
+
emit({"project": row, "components": components}, selected_output)
|
|
342
|
+
finally:
|
|
343
|
+
client.close()
|
|
344
|
+
except Exception as error:
|
|
345
|
+
raise fail(error, selected_output) from None
|
|
346
|
+
|
|
347
|
+
|
|
348
|
+
@_tree(app, ("projects",)).command("show")
|
|
349
|
+
def projects_show(ctx: typer.Context, project: Annotated[str | None, typer.Option("--project")] = None,
|
|
350
|
+
output: Annotated[str | None, typer.Option("--output")] = None):
|
|
351
|
+
"""Show an authorized project list entry."""
|
|
352
|
+
selected_output = _effective_output(ctx, output)
|
|
353
|
+
try:
|
|
354
|
+
client = _client(ctx)
|
|
355
|
+
try:
|
|
356
|
+
project = project or (client.config.profile.project if client.config.profile else None)
|
|
357
|
+
if not project:
|
|
358
|
+
raise ConfigurationError("Supply --project or select a profile with a default project.")
|
|
359
|
+
rows, _ = client.request_json("GET", "/projects")
|
|
360
|
+
row = next((item for item in rows if item.get("name") == project), None)
|
|
361
|
+
if row is None:
|
|
362
|
+
raise ApiError(404, "Project not found in authorized project list.")
|
|
363
|
+
emit(row, selected_output)
|
|
364
|
+
finally:
|
|
365
|
+
client.close()
|
|
366
|
+
except Exception as error:
|
|
367
|
+
raise fail(error, selected_output) from None
|
|
368
|
+
|
|
369
|
+
|
|
370
|
+
@_tree(app, ("operations",)).command("watch")
|
|
371
|
+
def operations_watch(ctx: typer.Context, operation_id: str,
|
|
372
|
+
timeout: Annotated[float, typer.Option("--timeout", min=1)] = 300,
|
|
373
|
+
poll_interval: Annotated[float, typer.Option("--poll-interval", min=0.1)] = 2,
|
|
374
|
+
output: Annotated[str | None, typer.Option("--output")] = None):
|
|
375
|
+
"""Resume bounded deployment operation watching."""
|
|
376
|
+
selected_output = _effective_output(ctx, output)
|
|
377
|
+
try:
|
|
378
|
+
client = _client(ctx)
|
|
379
|
+
try:
|
|
380
|
+
token = client.access_token()
|
|
381
|
+
path = "/v1/operations/" + operation_id
|
|
382
|
+
first = client.operation(path, token)
|
|
383
|
+
accepted = OperationAccepted(operation_id=first.operation_id, state=first.state,
|
|
384
|
+
revision=first.revision, status_url=path)
|
|
385
|
+
result = wait_for_operation(client, accepted, token, timeout, poll_interval,
|
|
386
|
+
time.monotonic, time.sleep, lambda _: None)
|
|
387
|
+
emit(result.model_dump(), selected_output)
|
|
388
|
+
finally:
|
|
389
|
+
client.close()
|
|
390
|
+
except Exception as error:
|
|
391
|
+
raise fail(error, selected_output) from None
|
|
392
|
+
|
|
393
|
+
|
|
394
|
+
@_tree(app, ("access", "operations")).command("watch")
|
|
395
|
+
def access_operations_watch(ctx: typer.Context, operation_id: str,
|
|
396
|
+
timeout: Annotated[float, typer.Option("--timeout", min=1)] = 300,
|
|
397
|
+
poll_interval: Annotated[float, typer.Option("--poll-interval", min=0.1)] = 2,
|
|
398
|
+
output: Annotated[str | None, typer.Option("--output")] = None):
|
|
399
|
+
"""Resume hosted access operation watching."""
|
|
400
|
+
selected_output = _effective_output(ctx, output)
|
|
401
|
+
try:
|
|
402
|
+
client = _client(ctx)
|
|
403
|
+
try:
|
|
404
|
+
emit(watch_access(client, operation_id, timeout, poll_interval,
|
|
405
|
+
lambda _: None), selected_output)
|
|
406
|
+
finally:
|
|
407
|
+
client.close()
|
|
408
|
+
except Exception as error:
|
|
409
|
+
raise fail(error, selected_output) from None
|
|
410
|
+
|
|
411
|
+
|
|
412
|
+
@_tree(app, ("contract",)).command("check")
|
|
413
|
+
def contract_check(ctx: typer.Context,
|
|
414
|
+
output: Annotated[str | None, typer.Option("--output")] = None):
|
|
415
|
+
"""Report registry coverage of the packaged public API contract."""
|
|
416
|
+
selected_output = _effective_output(ctx, output)
|
|
417
|
+
from importlib.resources import files
|
|
418
|
+
from .registry import EXCLUSIONS
|
|
419
|
+
contract = json.loads(files("platform_cli").joinpath("api_contract.json").read_text())
|
|
420
|
+
expected = {(method.upper(), path) for path, methods in contract["paths"].items()
|
|
421
|
+
for method in methods if method.upper() in {"GET", "POST", "PUT", "PATCH", "DELETE"}}
|
|
422
|
+
actual = {(spec.method, spec.path) for spec in COMMANDS}
|
|
423
|
+
missing = sorted(expected - actual - EXCLUSIONS.keys())
|
|
424
|
+
extra = sorted(actual - expected)
|
|
425
|
+
emit({"covered": len(actual), "excluded": len(EXCLUSIONS), "missing": missing, "extra": extra}, selected_output)
|
|
426
|
+
if missing or extra:
|
|
427
|
+
raise typer.Exit(7)
|
|
121
428
|
|
|
122
429
|
|
|
123
430
|
def main() -> None:
|