developer-platform-cli 0.1.0__tar.gz → 0.3.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.
Files changed (24) hide show
  1. {developer_platform_cli-0.1.0 → developer_platform_cli-0.3.0}/PKG-INFO +15 -6
  2. {developer_platform_cli-0.1.0 → developer_platform_cli-0.3.0}/README.md +11 -4
  3. {developer_platform_cli-0.1.0 → developer_platform_cli-0.3.0}/pyproject.toml +7 -1
  4. {developer_platform_cli-0.1.0 → developer_platform_cli-0.3.0}/src/platform_cli/__init__.py +1 -1
  5. developer_platform_cli-0.3.0/src/platform_cli/__main__.py +435 -0
  6. developer_platform_cli-0.3.0/src/platform_cli/api_contract.json +8292 -0
  7. developer_platform_cli-0.3.0/src/platform_cli/authentication.py +136 -0
  8. developer_platform_cli-0.3.0/src/platform_cli/client.py +219 -0
  9. developer_platform_cli-0.3.0/src/platform_cli/commands.py +467 -0
  10. {developer_platform_cli-0.1.0 → developer_platform_cli-0.3.0}/src/platform_cli/config.py +19 -4
  11. {developer_platform_cli-0.1.0 → developer_platform_cli-0.3.0}/src/platform_cli/errors.py +2 -2
  12. {developer_platform_cli-0.1.0 → developer_platform_cli-0.3.0}/src/platform_cli/models.py +22 -0
  13. developer_platform_cli-0.3.0/src/platform_cli/profiles.py +155 -0
  14. developer_platform_cli-0.3.0/src/platform_cli/registry.py +187 -0
  15. developer_platform_cli-0.3.0/src/platform_cli/tunnel.py +78 -0
  16. developer_platform_cli-0.3.0/tests/test_administration.py +342 -0
  17. {developer_platform_cli-0.1.0 → developer_platform_cli-0.3.0}/tests/test_client.py +21 -0
  18. developer_platform_cli-0.3.0/tests/test_commands.py +46 -0
  19. developer_platform_cli-0.3.0/tests/test_profiles_authentication.py +90 -0
  20. developer_platform_cli-0.1.0/src/platform_cli/__main__.py +0 -128
  21. developer_platform_cli-0.1.0/src/platform_cli/client.py +0 -127
  22. developer_platform_cli-0.1.0/tests/test_commands.py +0 -16
  23. {developer_platform_cli-0.1.0 → developer_platform_cli-0.3.0}/.gitignore +0 -0
  24. {developer_platform_cli-0.1.0 → developer_platform_cli-0.3.0}/tests/test_config.py +0 -0
@@ -1,9 +1,11 @@
1
- Metadata-Version: 2.5
1
+ Metadata-Version: 2.4
2
2
  Name: developer-platform-cli
3
- Version: 0.1.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
- `devplat` is the command-line client for the Developer Platform API. Its first
18
- supported workflow is CI-style deployment using a project-scoped deployment
19
- credential supplied only through environment variables.
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.
@@ -1,8 +1,12 @@
1
1
  # Developer Platform CLI
2
2
 
3
- `devplat` is the command-line client for the Developer Platform API. Its first
4
- supported workflow is CI-style deployment using a project-scoped deployment
5
- credential supplied only through environment variables.
3
+ This source-adjacent README provides the minimal development example. The
4
+ canonical user documentation is the [CLI guide](../../docs/developers/cli.md);
5
+ implementation ownership is in the [maintainer guide](../../docs/maintainers/cli.md).
6
+
7
+ `devplat` is the command-line client for the Developer Platform API. It supports
8
+ CI deployments and project administration, including hosted application access.
9
+ Use `devplat --help` and `devplat access --help` to inspect commands.
6
10
 
7
11
  Install an editable development copy:
8
12
 
@@ -23,4 +27,7 @@ devplat deploy apply --project hello --file examples/project.json --wait
23
27
 
24
28
  `PLATFORM_ACCESS_TOKEN` may be used instead of the deployment-credential variables
25
29
  for a short-lived, externally obtained token. The CLI never persists either form of
26
- authentication material.
30
+ authentication material. Deployment credentials authorize deployment and observation
31
+ only; access administration requires a human project-administrator login or an
32
+ externally supplied administrator token. See the [CLI guide](../../docs/developers/cli.md)
33
+ for profiles, login, access commands, and versioned updates.
@@ -4,7 +4,7 @@ build-backend = "hatchling.build"
4
4
 
5
5
  [project]
6
6
  name = "developer-platform-cli"
7
- version = "0.1.0"
7
+ version = "0.3.0"
8
8
  description = "Command-line client for the Developer Platform API"
9
9
  readme = "README.md"
10
10
  requires-python = ">=3.12"
@@ -13,6 +13,8 @@ dependencies = [
13
13
  "pydantic>=2.10,<3",
14
14
  "rich>=13.9,<14",
15
15
  "typer>=0.15,<1",
16
+ "platformdirs>=4,<5",
17
+ "keyring>=25,<26",
16
18
  ]
17
19
 
18
20
  [project.optional-dependencies]
@@ -26,6 +28,10 @@ devplat = "platform_cli.__main__:main"
26
28
 
27
29
  [tool.hatch.build.targets.wheel]
28
30
  packages = ["src/platform_cli"]
31
+ core-metadata-version = "2.4"
32
+
33
+ [tool.hatch.build.targets.sdist]
34
+ core-metadata-version = "2.4"
29
35
 
30
36
  [tool.pytest.ini_options]
31
37
  testpaths = ["tests"]
@@ -1,3 +1,3 @@
1
1
  """Developer Platform command-line client."""
2
2
 
3
- __version__ = "0.1.0"
3
+ __version__ = "0.3.0"
@@ -0,0 +1,435 @@
1
+ """The devplat executable."""
2
+
3
+ from __future__ import annotations
4
+
5
+ import json
6
+ from dataclasses import asdict, dataclass
7
+ import os
8
+ from pathlib import Path
9
+ import sys
10
+ import time
11
+ from typing import Annotated
12
+
13
+ import typer
14
+
15
+ from .client import PlatformClient, wait_for_operation
16
+ from .config import ConfigurationError, authentication_source, runtime_config
17
+ from .errors import ApiError
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
23
+
24
+
25
+ app = typer.Typer(no_args_is_help=True, add_completion=False, help="Developer Platform command-line client.")
26
+ deploy_app = typer.Typer(no_args_is_help=True, help="Deploy versioned application specifications.")
27
+ auth_app = typer.Typer(no_args_is_help=True, help="Inspect, create, or clear human login sessions.")
28
+ app.add_typer(deploy_app, name="deploy")
29
+ app.add_typer(auth_app, name="auth")
30
+
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
+
81
+ def _read_json(path: str) -> dict[str, object]:
82
+ try:
83
+ contents = sys.stdin.read() if path == "-" else Path(path).read_text(encoding="utf-8")
84
+ return application_body(json.loads(contents))
85
+ except (OSError, json.JSONDecodeError, ValueError) as error:
86
+ raise typer.BadParameter(f"unable to read a JSON application specification: {error}", param_hint="--file") from error
87
+
88
+
89
+ def _emit(value: object, output: str) -> None:
90
+ if output == "json":
91
+ typer.echo(json.dumps(value, separators=(",", ":"), default=str))
92
+ return
93
+ if isinstance(value, dict) and "operation_id" in value:
94
+ typer.echo(f"Operation {value['operation_id']} is {value.get('state', 'unknown')} (revision {value.get('revision', 'unknown')}).")
95
+ return
96
+ typer.echo(str(value))
97
+
98
+
99
+ @auth_app.command("status")
100
+ def auth_status(
101
+ ctx: typer.Context,
102
+ output: Annotated[str | None, typer.Option("--output", case_sensitive=False)] = None,
103
+ ) -> None:
104
+ """Show the active authentication source without disclosing credentials."""
105
+ try:
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))
115
+ except Exception as error:
116
+ raise fail(error, output or _state(ctx).output or "table") from None
117
+
118
+
119
+ @deploy_app.command("apply")
120
+ def deploy_apply(
121
+ ctx: typer.Context,
122
+ project: Annotated[str, typer.Option("--project", min=1, help="Target project name.")],
123
+ file: Annotated[str, typer.Option("--file", help="JSON specification file, or - for stdin.")],
124
+ wait: Annotated[bool, typer.Option("--wait", help="Wait for durable operation success and readiness.")] = False,
125
+ timeout: Annotated[float, typer.Option("--timeout", min=1.0, help="Maximum wait time in seconds.")] = 300.0,
126
+ poll_interval: Annotated[float, typer.Option("--poll-interval", min=0.1, help="Operation poll interval in seconds.")] = 2.0,
127
+ if_match: Annotated[str | None, typer.Option("--if-match", help="Expected current revision.")] = None,
128
+ output: Annotated[str | None, typer.Option("--output", case_sensitive=False)] = None,
129
+ ) -> None:
130
+ """Apply one JSON application specification using environment authentication."""
131
+ output = _effective_output(ctx, output)
132
+ if output not in {"table", "json", "plain"}:
133
+ raise typer.BadParameter("must be table, json, or plain", param_hint="--output")
134
+ try:
135
+ body = _read_json(file)
136
+ config = runtime_config(profile_name=_state(ctx).profile, api_url_override=_state(ctx).api_url,
137
+ insecure=_state(ctx).insecure)
138
+ client = PlatformClient(config)
139
+ client.debug = _state(ctx).debug
140
+ try:
141
+ token = client.access_token()
142
+ accepted = client.deploy(project, body, token, if_match)
143
+ if not wait:
144
+ _emit(accepted.model_dump(), output)
145
+ return
146
+
147
+ def update(status: OperationStatus) -> None:
148
+ if output != "json":
149
+ typer.echo(
150
+ f"Operation {status.operation_id}: {status.state}; readiness {status.readiness.state}.",
151
+ err=True,
152
+ )
153
+
154
+ completed = wait_for_operation(
155
+ client, accepted, token, timeout, poll_interval, time.monotonic, time.sleep, update
156
+ )
157
+ _emit(completed.model_dump(), output)
158
+ finally:
159
+ client.close()
160
+ except typer.BadParameter:
161
+ raise
162
+ except KeyboardInterrupt:
163
+ typer.echo("Waiting interrupted; the durable platform operation continues.", err=True)
164
+ raise typer.Exit(10) from None
165
+ except Exception as error:
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)
428
+
429
+
430
+ def main() -> None:
431
+ app()
432
+
433
+
434
+ if __name__ == "__main__":
435
+ main()