simple-module-remote 0.0.50__tar.gz → 0.0.51__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.
- {simple_module_remote-0.0.50 → simple_module_remote-0.0.51}/PKG-INFO +1 -1
- {simple_module_remote-0.0.50 → simple_module_remote-0.0.51}/pyproject.toml +1 -1
- {simple_module_remote-0.0.50 → simple_module_remote-0.0.51}/simple_module_remote/__init__.py +2 -1
- {simple_module_remote-0.0.50 → simple_module_remote-0.0.51}/simple_module_remote/commands/auth_cmd.py +56 -9
- simple_module_remote-0.0.51/simple_module_remote/commands/device_login.py +222 -0
- {simple_module_remote-0.0.50 → simple_module_remote-0.0.51}/simple_module_remote/commands/doctor_cmd.py +5 -0
- {simple_module_remote-0.0.50 → simple_module_remote-0.0.51}/simple_module_remote/commands/env_cmd.py +25 -6
- {simple_module_remote-0.0.50 → simple_module_remote-0.0.51}/simple_module_remote/commands/generated.py +21 -0
- {simple_module_remote-0.0.50 → simple_module_remote-0.0.51}/simple_module_remote/commands/root.py +21 -6
- {simple_module_remote-0.0.50 → simple_module_remote-0.0.51}/simple_module_remote/commands/runtime.py +8 -2
- {simple_module_remote-0.0.50 → simple_module_remote-0.0.51}/simple_module_remote/commands/schema_cmd.py +42 -18
- {simple_module_remote-0.0.50 → simple_module_remote-0.0.51}/simple_module_remote/config/_file_store.py +21 -1
- {simple_module_remote-0.0.50 → simple_module_remote-0.0.51}/simple_module_remote/config/environments.py +28 -2
- {simple_module_remote-0.0.50 → simple_module_remote-0.0.51}/simple_module_remote/config/resolve.py +3 -1
- simple_module_remote-0.0.51/simple_module_remote/curated/__init__.py +1 -0
- simple_module_remote-0.0.51/simple_module_remote/curated/_tenants_ops.py +171 -0
- simple_module_remote-0.0.51/simple_module_remote/curated/loader.py +210 -0
- simple_module_remote-0.0.51/simple_module_remote/curated/provider.py +281 -0
- simple_module_remote-0.0.51/simple_module_remote/curated/settings.py +296 -0
- simple_module_remote-0.0.51/simple_module_remote/curated/settings_io.py +190 -0
- simple_module_remote-0.0.51/simple_module_remote/curated/tenants.py +212 -0
- simple_module_remote-0.0.51/simple_module_remote/curated/users.py +296 -0
- {simple_module_remote-0.0.50 → simple_module_remote-0.0.51}/simple_module_remote/generate/body.py +80 -35
- simple_module_remote-0.0.51/simple_module_remote/generate/body_help.py +62 -0
- simple_module_remote-0.0.51/simple_module_remote/generate/body_path.py +142 -0
- {simple_module_remote-0.0.50 → simple_module_remote-0.0.51}/simple_module_remote/generate/context.py +2 -0
- {simple_module_remote-0.0.50 → simple_module_remote-0.0.51}/simple_module_remote/generate/emit.py +29 -18
- {simple_module_remote-0.0.50 → simple_module_remote-0.0.51}/simple_module_remote/generate/execute.py +46 -12
- {simple_module_remote-0.0.50 → simple_module_remote-0.0.51}/simple_module_remote/generate/operations.py +7 -1
- simple_module_remote-0.0.51/simple_module_remote/generate/pagination.py +144 -0
- {simple_module_remote-0.0.50 → simple_module_remote-0.0.51}/simple_module_remote/generate/params.py +45 -4
- {simple_module_remote-0.0.50 → simple_module_remote-0.0.51}/simple_module_remote/generate/prepare.py +12 -3
- {simple_module_remote-0.0.50 → simple_module_remote-0.0.51}/simple_module_remote/http/client.py +6 -3
- simple_module_remote-0.0.51/simple_module_remote/http/error_kinds.py +98 -0
- {simple_module_remote-0.0.50 → simple_module_remote-0.0.51}/simple_module_remote/http/errors.py +1 -1
- {simple_module_remote-0.0.50 → simple_module_remote-0.0.51}/simple_module_remote/http/safety.py +9 -3
- {simple_module_remote-0.0.50 → simple_module_remote-0.0.51}/tests/commands/test_api_cmd.py +10 -2
- {simple_module_remote-0.0.50 → simple_module_remote-0.0.51}/tests/commands/test_auth_cmd.py +5 -3
- simple_module_remote-0.0.51/tests/commands/test_auth_login.py +79 -0
- simple_module_remote-0.0.51/tests/commands/test_device_login.py +201 -0
- {simple_module_remote-0.0.50 → simple_module_remote-0.0.51}/tests/commands/test_env_cmd.py +30 -0
- simple_module_remote-0.0.51/tests/commands/test_generated_help.py +34 -0
- {simple_module_remote-0.0.50 → simple_module_remote-0.0.51}/tests/commands/test_schema_sync.py +34 -0
- simple_module_remote-0.0.51/tests/config/test_credentials_read_errors.py +91 -0
- simple_module_remote-0.0.51/tests/curated/test_curated_security.py +293 -0
- simple_module_remote-0.0.51/tests/curated/test_loader.py +224 -0
- simple_module_remote-0.0.51/tests/curated/test_settings.py +288 -0
- simple_module_remote-0.0.51/tests/curated/test_tenants.py +185 -0
- simple_module_remote-0.0.51/tests/curated/test_users.py +219 -0
- simple_module_remote-0.0.51/tests/generate/test_body_help.py +113 -0
- simple_module_remote-0.0.51/tests/generate/test_body_polish.py +135 -0
- simple_module_remote-0.0.51/tests/generate/test_error_hints.py +125 -0
- {simple_module_remote-0.0.50 → simple_module_remote-0.0.51}/tests/generate/test_execute.py +2 -2
- simple_module_remote-0.0.51/tests/generate/test_execute_output.py +197 -0
- {simple_module_remote-0.0.50 → simple_module_remote-0.0.51}/tests/generate/test_pagination.py +78 -1
- {simple_module_remote-0.0.50 → simple_module_remote-0.0.51}/tests/generate/test_params.py +104 -0
- {simple_module_remote-0.0.50 → simple_module_remote-0.0.51}/tests/http/test_client_redirects.py +34 -0
- {simple_module_remote-0.0.50 → simple_module_remote-0.0.51}/tests/http/test_safety.py +22 -0
- simple_module_remote-0.0.50/simple_module_remote/curated/__init__.py +0 -1
- simple_module_remote-0.0.50/simple_module_remote/generate/pagination.py +0 -80
- simple_module_remote-0.0.50/tests/commands/test_auth_login.py +0 -34
- simple_module_remote-0.0.50/tests/config/test_credentials_read_errors.py +0 -45
- simple_module_remote-0.0.50/tests/generate/test_execute_output.py +0 -81
- {simple_module_remote-0.0.50 → simple_module_remote-0.0.51}/.gitignore +0 -0
- {simple_module_remote-0.0.50 → simple_module_remote-0.0.51}/LICENSE +0 -0
- {simple_module_remote-0.0.50 → simple_module_remote-0.0.51}/README.md +0 -0
- {simple_module_remote-0.0.50 → simple_module_remote-0.0.51}/simple_module_remote/commands/__init__.py +0 -0
- {simple_module_remote-0.0.50 → simple_module_remote-0.0.51}/simple_module_remote/commands/api_cmd.py +0 -0
- {simple_module_remote-0.0.50 → simple_module_remote-0.0.51}/simple_module_remote/commands/schema_fetch.py +0 -0
- {simple_module_remote-0.0.50 → simple_module_remote-0.0.51}/simple_module_remote/commands/schema_source.py +0 -0
- {simple_module_remote-0.0.50 → simple_module_remote-0.0.51}/simple_module_remote/config/__init__.py +0 -0
- {simple_module_remote-0.0.50 → simple_module_remote-0.0.51}/simple_module_remote/config/_private_dir.py +0 -0
- {simple_module_remote-0.0.50 → simple_module_remote-0.0.51}/simple_module_remote/config/credentials.py +0 -0
- {simple_module_remote-0.0.50 → simple_module_remote-0.0.51}/simple_module_remote/config/paths.py +0 -0
- {simple_module_remote-0.0.50 → simple_module_remote-0.0.51}/simple_module_remote/generate/__init__.py +0 -0
- {simple_module_remote-0.0.50 → simple_module_remote-0.0.51}/simple_module_remote/generate/confirm.py +0 -0
- {simple_module_remote-0.0.50 → simple_module_remote-0.0.51}/simple_module_remote/generate/naming.py +0 -0
- {simple_module_remote-0.0.50 → simple_module_remote-0.0.51}/simple_module_remote/generate/pairs.py +0 -0
- {simple_module_remote-0.0.50 → simple_module_remote-0.0.51}/simple_module_remote/generate/tree.py +0 -0
- {simple_module_remote-0.0.50 → simple_module_remote-0.0.51}/simple_module_remote/generate/trust.py +0 -0
- {simple_module_remote-0.0.50 → simple_module_remote-0.0.51}/simple_module_remote/generate/validate.py +0 -0
- {simple_module_remote-0.0.50 → simple_module_remote-0.0.51}/simple_module_remote/http/__init__.py +0 -0
- {simple_module_remote-0.0.50 → simple_module_remote-0.0.51}/simple_module_remote/output/__init__.py +0 -0
- {simple_module_remote-0.0.50 → simple_module_remote-0.0.51}/simple_module_remote/output/reasons.py +0 -0
- {simple_module_remote-0.0.50 → simple_module_remote-0.0.51}/simple_module_remote/output/render.py +0 -0
- {simple_module_remote-0.0.50 → simple_module_remote-0.0.51}/simple_module_remote/output/sanitize.py +0 -0
- {simple_module_remote-0.0.50 → simple_module_remote-0.0.51}/simple_module_remote/py.typed +0 -0
- {simple_module_remote-0.0.50 → simple_module_remote-0.0.51}/simple_module_remote/schema/__init__.py +0 -0
- {simple_module_remote-0.0.50 → simple_module_remote-0.0.51}/simple_module_remote/schema/cache.py +0 -0
- {simple_module_remote-0.0.50 → simple_module_remote-0.0.51}/simple_module_remote/schema/loader.py +0 -0
- {simple_module_remote-0.0.50 → simple_module_remote-0.0.51}/tests/commands/test_auth_tenant.py +0 -0
- {simple_module_remote-0.0.50 → simple_module_remote-0.0.51}/tests/commands/test_doctor_cmd.py +0 -0
- {simple_module_remote-0.0.50 → simple_module_remote-0.0.51}/tests/commands/test_env_normalise.py +0 -0
- {simple_module_remote-0.0.50 → simple_module_remote-0.0.51}/tests/commands/test_schema_etag.py +0 -0
- {simple_module_remote-0.0.50 → simple_module_remote-0.0.51}/tests/commands/test_schema_live_shapes.py +0 -0
- {simple_module_remote-0.0.50 → simple_module_remote-0.0.51}/tests/commands/test_schema_live_trust.py +0 -0
- {simple_module_remote-0.0.50 → simple_module_remote-0.0.51}/tests/commands/test_whoami_validation.py +0 -0
- {simple_module_remote-0.0.50 → simple_module_remote-0.0.51}/tests/config/test_credential_index.py +0 -0
- {simple_module_remote-0.0.50 → simple_module_remote-0.0.51}/tests/config/test_credentials.py +0 -0
- {simple_module_remote-0.0.50 → simple_module_remote-0.0.51}/tests/config/test_environments.py +0 -0
- {simple_module_remote-0.0.50 → simple_module_remote-0.0.51}/tests/config/test_import_isolation.py +0 -0
- {simple_module_remote-0.0.50 → simple_module_remote-0.0.51}/tests/config/test_private_dir_fifo.py +0 -0
- {simple_module_remote-0.0.50 → simple_module_remote-0.0.51}/tests/conftest.py +0 -0
- {simple_module_remote-0.0.50 → simple_module_remote-0.0.51}/tests/generate/fixtures/mini_openapi.json +0 -0
- {simple_module_remote-0.0.50 → simple_module_remote-0.0.51}/tests/generate/test_body.py +0 -0
- {simple_module_remote-0.0.50 → simple_module_remote-0.0.51}/tests/generate/test_execute_failures.py +0 -0
- {simple_module_remote-0.0.50 → simple_module_remote-0.0.51}/tests/generate/test_execute_flags.py +0 -0
- {simple_module_remote-0.0.50 → simple_module_remote-0.0.51}/tests/generate/test_execute_request.py +0 -0
- {simple_module_remote-0.0.50 → simple_module_remote-0.0.51}/tests/generate/test_naming.py +0 -0
- {simple_module_remote-0.0.50 → simple_module_remote-0.0.51}/tests/generate/test_operations.py +0 -0
- {simple_module_remote-0.0.50 → simple_module_remote-0.0.51}/tests/generate/test_server_text_safety.py +0 -0
- {simple_module_remote-0.0.50 → simple_module_remote-0.0.51}/tests/generate/test_tree.py +0 -0
- {simple_module_remote-0.0.50 → simple_module_remote-0.0.51}/tests/http/test_client.py +0 -0
- {simple_module_remote-0.0.50 → simple_module_remote-0.0.51}/tests/output/test_render.py +0 -0
- {simple_module_remote-0.0.50 → simple_module_remote-0.0.51}/tests/output/test_sanitize.py +0 -0
- {simple_module_remote-0.0.50 → simple_module_remote-0.0.51}/tests/schema/test_cache.py +0 -0
- {simple_module_remote-0.0.50 → simple_module_remote-0.0.51}/tests/schema/test_loader.py +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.5
|
|
2
2
|
Name: simple_module_remote
|
|
3
|
-
Version: 0.0.
|
|
3
|
+
Version: 0.0.51
|
|
4
4
|
Summary: Client-only engine for a per-project CLI over a simple_module app's REST API
|
|
5
5
|
Project-URL: Homepage, https://github.com/antosubash/simple_module_python
|
|
6
6
|
Project-URL: Repository, https://github.com/antosubash/simple_module_python
|
{simple_module_remote-0.0.50 → simple_module_remote-0.0.51}/simple_module_remote/__init__.py
RENAMED
|
@@ -8,5 +8,6 @@ except PackageNotFoundError: # pragma: no cover - source checkout without insta
|
|
|
8
8
|
__version__ = "0.0.0"
|
|
9
9
|
|
|
10
10
|
from simple_module_remote.commands.root import build_cli
|
|
11
|
+
from simple_module_remote.curated.provider import CuratedContext, CuratedError, CuratedProvider
|
|
11
12
|
|
|
12
|
-
__all__ = ["__version__", "build_cli"]
|
|
13
|
+
__all__ = ["CuratedContext", "CuratedError", "CuratedProvider", "__version__", "build_cli"]
|
|
@@ -6,7 +6,15 @@ import sys
|
|
|
6
6
|
|
|
7
7
|
import click
|
|
8
8
|
|
|
9
|
-
from simple_module_remote.commands.
|
|
9
|
+
from simple_module_remote.commands.device_login import run_device_login
|
|
10
|
+
from simple_module_remote.commands.runtime import (
|
|
11
|
+
WHOAMI_PATH,
|
|
12
|
+
AppState,
|
|
13
|
+
CliError,
|
|
14
|
+
fetch_whoami,
|
|
15
|
+
state_of,
|
|
16
|
+
)
|
|
17
|
+
from simple_module_remote.commands.schema_cmd import sync_env_best_effort
|
|
10
18
|
from simple_module_remote.config.credentials import (
|
|
11
19
|
CredentialError,
|
|
12
20
|
StoredCredential,
|
|
@@ -18,6 +26,7 @@ from simple_module_remote.config.credentials import (
|
|
|
18
26
|
tenant_matches,
|
|
19
27
|
validate_token,
|
|
20
28
|
)
|
|
29
|
+
from simple_module_remote.config.environments import save_config
|
|
21
30
|
from simple_module_remote.config.resolve import find_credential
|
|
22
31
|
from simple_module_remote.http.errors import AUTH_STATUSES, ApiError, exit_code_for
|
|
23
32
|
from simple_module_remote.output.sanitize import sanitize
|
|
@@ -44,25 +53,41 @@ class _LoginCommand(click.Command):
|
|
|
44
53
|
return super().parse_args(ctx, args)
|
|
45
54
|
except click.UsageError:
|
|
46
55
|
raise CliError(
|
|
47
|
-
"login takes no arguments and no token value:
|
|
48
|
-
"or --token
|
|
56
|
+
"login takes no arguments and no token value: run `login` for browser sign-in, "
|
|
57
|
+
"or use --token (hidden prompt) / --token-stdin "
|
|
58
|
+
"(--env and --tenant go before the word login)"
|
|
49
59
|
) from None
|
|
50
60
|
|
|
51
61
|
|
|
52
62
|
@click.command(
|
|
53
|
-
"login",
|
|
63
|
+
"login",
|
|
64
|
+
cls=_LoginCommand,
|
|
65
|
+
help="Sign in via browser device approval, or store a personal access token.",
|
|
54
66
|
)
|
|
55
67
|
@click.option("--token", "prompt_token", is_flag=True, help="Prompt for the token (hidden input).")
|
|
56
68
|
@click.option("--token-stdin", is_flag=True, help="Read the token from one line of stdin.")
|
|
69
|
+
@click.option(
|
|
70
|
+
"--no-browser",
|
|
71
|
+
is_flag=True,
|
|
72
|
+
help="Print the verification URL instead of opening a browser.",
|
|
73
|
+
)
|
|
57
74
|
@click.pass_context
|
|
58
|
-
def login(
|
|
75
|
+
def login(
|
|
76
|
+
ctx: click.Context,
|
|
77
|
+
prompt_token: bool,
|
|
78
|
+
token_stdin: bool,
|
|
79
|
+
no_browser: bool,
|
|
80
|
+
) -> None:
|
|
59
81
|
state = state_of(ctx)
|
|
60
82
|
if prompt_token and token_stdin:
|
|
61
83
|
raise CliError("choose one of --token and --token-stdin")
|
|
62
|
-
if
|
|
63
|
-
raise CliError("browser
|
|
64
|
-
env,
|
|
65
|
-
|
|
84
|
+
if no_browser and (prompt_token or token_stdin):
|
|
85
|
+
raise CliError("--no-browser applies only to browser login, not --token or --token-stdin")
|
|
86
|
+
env, explicit = state.select()
|
|
87
|
+
used_browser = not (prompt_token or token_stdin)
|
|
88
|
+
if used_browser:
|
|
89
|
+
candidate = run_device_login(state, env, no_browser=no_browser)
|
|
90
|
+
elif token_stdin:
|
|
66
91
|
candidate = sys.stdin.readline(MAX_TOKEN_CHARS + 2).strip()
|
|
67
92
|
if len(candidate) > MAX_TOKEN_CHARS:
|
|
68
93
|
raise CliError(f"the token is longer than {MAX_TOKEN_CHARS} characters")
|
|
@@ -112,6 +137,28 @@ def login(ctx: click.Context, prompt_token: bool, token_stdin: bool) -> None:
|
|
|
112
137
|
if store.using_fallback:
|
|
113
138
|
click.echo("warning: no OS keyring; token stored in a 0600 file", err=True)
|
|
114
139
|
click.echo(f"logged in to {where} as {sanitize(str(who.get('email', 'unknown')))}")
|
|
140
|
+
_adopt_as_current(state, env.name)
|
|
141
|
+
if used_browser:
|
|
142
|
+
sync_env_best_effort(state, env, explicit, token=candidate)
|
|
143
|
+
|
|
144
|
+
|
|
145
|
+
def _adopt_as_current(state: AppState, name: str) -> None:
|
|
146
|
+
"""With no current environment yet, a configured one just logged in to becomes it (#1241).
|
|
147
|
+
|
|
148
|
+
The login itself has already succeeded, so a config that cannot be saved is a
|
|
149
|
+
warning, not a failure.
|
|
150
|
+
"""
|
|
151
|
+
try:
|
|
152
|
+
config = state.config()
|
|
153
|
+
if config.current is not None or name not in config.envs:
|
|
154
|
+
return # a choice already made, or a one-off environment from <CLI>_URL
|
|
155
|
+
config.current = name
|
|
156
|
+
with state.guard():
|
|
157
|
+
save_config(state.cli, config)
|
|
158
|
+
except CliError as exc:
|
|
159
|
+
click.echo(f"warning: {name} was not made the current environment: {exc}", err=True)
|
|
160
|
+
return
|
|
161
|
+
click.echo(f"current environment: {name}", err=True)
|
|
115
162
|
|
|
116
163
|
|
|
117
164
|
@click.command("logout", help="Remove the stored token for the selected environment.")
|
|
@@ -0,0 +1,222 @@
|
|
|
1
|
+
"""RFC 8628 browser device-approval login flow for the project CLI."""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
import socket
|
|
6
|
+
import time
|
|
7
|
+
import webbrowser
|
|
8
|
+
from collections.abc import Callable
|
|
9
|
+
from typing import Any
|
|
10
|
+
from urllib.parse import urlencode, urlsplit
|
|
11
|
+
|
|
12
|
+
import click
|
|
13
|
+
|
|
14
|
+
from simple_module_remote.commands.runtime import AppState, CliError
|
|
15
|
+
from simple_module_remote.config.credentials import validate_token
|
|
16
|
+
from simple_module_remote.config.environments import Environment, normalize_origin
|
|
17
|
+
from simple_module_remote.http.errors import REDIRECT_MIN, ApiError, exit_code_for
|
|
18
|
+
from simple_module_remote.output.sanitize import sanitize
|
|
19
|
+
|
|
20
|
+
__all__ = ["DEVICE_START_PATH", "DEVICE_TOKEN_PATH", "run_device_login"]
|
|
21
|
+
|
|
22
|
+
DEVICE_START_PATH = "/api/api_tokens/device/start"
|
|
23
|
+
DEVICE_TOKEN_PATH = "/api/api_tokens/device/token"
|
|
24
|
+
_DEFAULT_EXPIRES_IN = 600
|
|
25
|
+
_DEFAULT_INTERVAL = 5
|
|
26
|
+
_SLOW_DOWN_STEP = 5
|
|
27
|
+
_HTTP_OK = 200
|
|
28
|
+
_HTTP_BAD_REQUEST = 400
|
|
29
|
+
_HTTP_NOT_FOUND = 404
|
|
30
|
+
_HTTP_TOO_MANY = 429
|
|
31
|
+
|
|
32
|
+
|
|
33
|
+
def _sleep(seconds: float) -> None:
|
|
34
|
+
time.sleep(seconds)
|
|
35
|
+
|
|
36
|
+
|
|
37
|
+
def _open_browser(url: str) -> bool:
|
|
38
|
+
try:
|
|
39
|
+
return bool(webbrowser.open(url))
|
|
40
|
+
except Exception:
|
|
41
|
+
return False
|
|
42
|
+
|
|
43
|
+
|
|
44
|
+
def _validated_verification_uri(raw: object, env: Environment) -> str:
|
|
45
|
+
"""Refuse a verification URI that points outside *env*'s origin or uses a bad scheme."""
|
|
46
|
+
if not isinstance(raw, str) or not raw.strip():
|
|
47
|
+
raise CliError("device login failed: server returned an invalid verification_uri")
|
|
48
|
+
parts = urlsplit(raw)
|
|
49
|
+
if parts.scheme not in ("http", "https") or not parts.netloc:
|
|
50
|
+
raise CliError("device login failed: server returned an unsafe verification_uri")
|
|
51
|
+
try:
|
|
52
|
+
origin = normalize_origin(raw)
|
|
53
|
+
except Exception:
|
|
54
|
+
raise CliError("device login failed: server returned an invalid verification_uri") from None
|
|
55
|
+
if origin != env.origin:
|
|
56
|
+
raise CliError(
|
|
57
|
+
"device login failed: verification_uri origin does not match the environment URL"
|
|
58
|
+
)
|
|
59
|
+
return raw
|
|
60
|
+
|
|
61
|
+
|
|
62
|
+
def _parse_json_object(response: Any, what: str) -> dict[str, Any]:
|
|
63
|
+
try:
|
|
64
|
+
data = response.json()
|
|
65
|
+
except ValueError:
|
|
66
|
+
raise CliError(
|
|
67
|
+
f"{what}: server did not return JSON", exit_code_for(response.status_code)
|
|
68
|
+
) from None
|
|
69
|
+
if not isinstance(data, dict):
|
|
70
|
+
raise CliError(
|
|
71
|
+
f"{what}: server did not return a JSON object", exit_code_for(response.status_code)
|
|
72
|
+
)
|
|
73
|
+
return data
|
|
74
|
+
|
|
75
|
+
|
|
76
|
+
def _start_device_flow(state: AppState, env: Environment, tenant: str | None) -> dict[str, Any]:
|
|
77
|
+
body: dict[str, Any] = {
|
|
78
|
+
"client_name": state.cli,
|
|
79
|
+
"hostname": socket.gethostname() or "unknown",
|
|
80
|
+
}
|
|
81
|
+
if tenant:
|
|
82
|
+
body["tenant"] = tenant
|
|
83
|
+
try:
|
|
84
|
+
with state.client(env, None) as client:
|
|
85
|
+
resp = client.request("POST", DEVICE_START_PATH, json=body, follow=False)
|
|
86
|
+
except ApiError as exc:
|
|
87
|
+
if exc.status == 0:
|
|
88
|
+
raise CliError(
|
|
89
|
+
f"cannot reach {env.name} ({env.url}): {exc.message}", exit_code_for(0)
|
|
90
|
+
) from None
|
|
91
|
+
raise CliError(f"device login failed: {exc.message}", exit_code_for(exc.status)) from None
|
|
92
|
+
|
|
93
|
+
if resp.status_code == _HTTP_NOT_FOUND:
|
|
94
|
+
raise CliError(
|
|
95
|
+
f"{env.url} does not support browser login ({DEVICE_START_PATH} not found): "
|
|
96
|
+
"use --token or --token-stdin instead",
|
|
97
|
+
exit_code_for(_HTTP_NOT_FOUND),
|
|
98
|
+
)
|
|
99
|
+
if resp.status_code >= REDIRECT_MIN or resp.status_code != _HTTP_OK:
|
|
100
|
+
raise CliError(
|
|
101
|
+
f"device login failed: HTTP {resp.status_code}",
|
|
102
|
+
exit_code_for(resp.status_code),
|
|
103
|
+
)
|
|
104
|
+
data = _parse_json_object(resp, "device login failed")
|
|
105
|
+
device_code = data.get("device_code")
|
|
106
|
+
user_code = data.get("user_code")
|
|
107
|
+
if (
|
|
108
|
+
not isinstance(device_code, str)
|
|
109
|
+
or not device_code
|
|
110
|
+
or not isinstance(user_code, str)
|
|
111
|
+
or not user_code
|
|
112
|
+
):
|
|
113
|
+
raise CliError("device login failed: incomplete response from server")
|
|
114
|
+
verification_uri = _validated_verification_uri(data.get("verification_uri"), env)
|
|
115
|
+
expires_in = data.get("expires_in", _DEFAULT_EXPIRES_IN)
|
|
116
|
+
interval = data.get("interval", _DEFAULT_INTERVAL)
|
|
117
|
+
return {
|
|
118
|
+
"device_code": device_code,
|
|
119
|
+
"user_code": user_code,
|
|
120
|
+
"verification_uri": verification_uri,
|
|
121
|
+
"expires_in": int(expires_in)
|
|
122
|
+
if isinstance(expires_in, int) and expires_in > 0
|
|
123
|
+
else _DEFAULT_EXPIRES_IN,
|
|
124
|
+
"interval": int(interval)
|
|
125
|
+
if isinstance(interval, int) and interval > 0
|
|
126
|
+
else _DEFAULT_INTERVAL,
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
|
|
130
|
+
def _poll_for_token(
|
|
131
|
+
state: AppState,
|
|
132
|
+
env: Environment,
|
|
133
|
+
device_code: str,
|
|
134
|
+
*,
|
|
135
|
+
expires_in: int,
|
|
136
|
+
interval: int,
|
|
137
|
+
sleep: Callable[[float], None] | None = None,
|
|
138
|
+
monotonic: Callable[[], float] = time.monotonic,
|
|
139
|
+
) -> str:
|
|
140
|
+
wait = sleep or _sleep
|
|
141
|
+
deadline = monotonic() + expires_in
|
|
142
|
+
wait_seconds = float(interval)
|
|
143
|
+
with state.client(env, None) as client:
|
|
144
|
+
while True:
|
|
145
|
+
remaining = deadline - monotonic()
|
|
146
|
+
if remaining <= 0:
|
|
147
|
+
raise CliError("login code expired; run login again")
|
|
148
|
+
wait(min(wait_seconds, remaining))
|
|
149
|
+
try:
|
|
150
|
+
resp = client.request(
|
|
151
|
+
"POST",
|
|
152
|
+
DEVICE_TOKEN_PATH,
|
|
153
|
+
json={"device_code": device_code},
|
|
154
|
+
follow=False,
|
|
155
|
+
)
|
|
156
|
+
except ApiError as exc:
|
|
157
|
+
raise CliError(
|
|
158
|
+
f"device login failed while polling: {exc.message}",
|
|
159
|
+
exit_code_for(exc.status),
|
|
160
|
+
) from None
|
|
161
|
+
|
|
162
|
+
if resp.status_code == _HTTP_OK:
|
|
163
|
+
data = _parse_json_object(resp, "device login failed")
|
|
164
|
+
token = data.get("access_token")
|
|
165
|
+
if not isinstance(token, str) or not token:
|
|
166
|
+
raise CliError("device login failed: server did not return an access_token")
|
|
167
|
+
with state.guard():
|
|
168
|
+
validate_token(token, source="the token returned by the server")
|
|
169
|
+
return token
|
|
170
|
+
|
|
171
|
+
if resp.status_code == _HTTP_TOO_MANY:
|
|
172
|
+
wait_seconds += _SLOW_DOWN_STEP
|
|
173
|
+
continue
|
|
174
|
+
|
|
175
|
+
if resp.status_code == _HTTP_BAD_REQUEST:
|
|
176
|
+
data = _parse_json_object(resp, "device login failed")
|
|
177
|
+
err = data.get("error")
|
|
178
|
+
if err == "authorization_pending":
|
|
179
|
+
continue
|
|
180
|
+
if err == "slow_down":
|
|
181
|
+
server_interval = data.get("interval")
|
|
182
|
+
if isinstance(server_interval, int) and server_interval > wait_seconds:
|
|
183
|
+
wait_seconds = float(server_interval)
|
|
184
|
+
else:
|
|
185
|
+
wait_seconds += _SLOW_DOWN_STEP
|
|
186
|
+
continue
|
|
187
|
+
if err == "access_denied":
|
|
188
|
+
raise CliError("login was denied in the browser")
|
|
189
|
+
if err == "expired_token":
|
|
190
|
+
raise CliError("login code expired; run login again")
|
|
191
|
+
desc = sanitize(str(data.get("error_description") or err or "unknown error"))
|
|
192
|
+
raise CliError(f"device login failed: {desc}")
|
|
193
|
+
|
|
194
|
+
raise CliError(
|
|
195
|
+
f"device login failed: HTTP {resp.status_code}",
|
|
196
|
+
exit_code_for(resp.status_code),
|
|
197
|
+
)
|
|
198
|
+
|
|
199
|
+
|
|
200
|
+
def run_device_login(
|
|
201
|
+
state: AppState,
|
|
202
|
+
env: Environment,
|
|
203
|
+
*,
|
|
204
|
+
no_browser: bool = False,
|
|
205
|
+
) -> str:
|
|
206
|
+
"""Execute the RFC 8628 device flow and return the newly issued PAT."""
|
|
207
|
+
started = _start_device_flow(state, env, state.tenant(env))
|
|
208
|
+
user_code = sanitize(started["user_code"])
|
|
209
|
+
query = urlencode({"code": started["user_code"]})
|
|
210
|
+
open_url = f"{started['verification_uri']}?{query}"
|
|
211
|
+
click.echo(f"verification code: {user_code}", err=True)
|
|
212
|
+
click.echo(f"open in browser: {sanitize(open_url)}", err=True)
|
|
213
|
+
if not no_browser and not _open_browser(open_url):
|
|
214
|
+
click.echo("could not open browser automatically; open the URL above", err=True)
|
|
215
|
+
click.echo("waiting for approval in browser...", err=True)
|
|
216
|
+
return _poll_for_token(
|
|
217
|
+
state,
|
|
218
|
+
env,
|
|
219
|
+
started["device_code"],
|
|
220
|
+
expires_in=started["expires_in"],
|
|
221
|
+
interval=started["interval"],
|
|
222
|
+
)
|
|
@@ -35,6 +35,9 @@ class _Report:
|
|
|
35
35
|
def ok(self, name: str, detail: str = "") -> None:
|
|
36
36
|
click.echo(f"ok {name}" + (f": {sanitize(detail)}" if detail else ""))
|
|
37
37
|
|
|
38
|
+
def note(self, name: str, detail: str) -> None:
|
|
39
|
+
click.echo(f"note {name}: {sanitize(detail)}")
|
|
40
|
+
|
|
38
41
|
def fail(self, name: str, detail: str, fix: str) -> None:
|
|
39
42
|
self.failed = True
|
|
40
43
|
click.echo(f"FAIL {name}: {sanitize(detail)}")
|
|
@@ -153,5 +156,7 @@ def doctor(ctx: click.Context) -> None:
|
|
|
153
156
|
f"{state.schema_source} {state.schema_path} (version {schema_info(state.root)})"
|
|
154
157
|
+ (f"; live: {state.schema_note}" if state.schema_note else ""),
|
|
155
158
|
)
|
|
159
|
+
for hidden in state.hidden_providers:
|
|
160
|
+
report.note(f"curated {hidden.name} (hidden)", hidden.reason)
|
|
156
161
|
if report.failed:
|
|
157
162
|
ctx.exit(1)
|
{simple_module_remote-0.0.50 → simple_module_remote-0.0.51}/simple_module_remote/commands/env_cmd.py
RENAMED
|
@@ -57,7 +57,10 @@ def list_envs(ctx: click.Context) -> None:
|
|
|
57
57
|
default=None,
|
|
58
58
|
help="Base URL of the app, e.g. https://app.example.com (required for a new environment).",
|
|
59
59
|
)
|
|
60
|
-
@click.option(
|
|
60
|
+
@click.option(
|
|
61
|
+
"--tenant", default=None, help="Default tenant (kept when omitted; pass '' to clear)."
|
|
62
|
+
)
|
|
63
|
+
@click.option("--clear-tenant", is_flag=True, help="Clear the stored default tenant.")
|
|
61
64
|
@click.option(
|
|
62
65
|
"--protected/--no-protected",
|
|
63
66
|
default=None,
|
|
@@ -65,9 +68,17 @@ def list_envs(ctx: click.Context) -> None:
|
|
|
65
68
|
)
|
|
66
69
|
@click.pass_context
|
|
67
70
|
def add_env(
|
|
68
|
-
ctx: click.Context,
|
|
71
|
+
ctx: click.Context,
|
|
72
|
+
name: str,
|
|
73
|
+
url: str | None,
|
|
74
|
+
tenant: str | None,
|
|
75
|
+
clear_tenant: bool,
|
|
76
|
+
protected: bool | None,
|
|
69
77
|
) -> None:
|
|
70
78
|
state = state_of(ctx)
|
|
79
|
+
if clear_tenant and tenant is not None:
|
|
80
|
+
raise CliError("cannot combine --tenant and --clear-tenant")
|
|
81
|
+
clearing_tenant = clear_tenant or tenant == ""
|
|
71
82
|
with state.guard():
|
|
72
83
|
validate_env_name(name)
|
|
73
84
|
if url is not None:
|
|
@@ -81,21 +92,29 @@ def add_env(
|
|
|
81
92
|
if existing is None:
|
|
82
93
|
raise CliError(f"--url is required to add the new environment {name!r}")
|
|
83
94
|
url = existing.url
|
|
84
|
-
|
|
85
|
-
|
|
95
|
+
new_tenant = (
|
|
96
|
+
None
|
|
97
|
+
if clearing_tenant
|
|
98
|
+
else (tenant if tenant is not None else (existing.tenant if existing else None))
|
|
86
99
|
)
|
|
100
|
+
changed = existing is not None and (url != existing.url or new_tenant != existing.tenant)
|
|
87
101
|
# Only what was passed changes; the rest comes from the existing (or default) environment.
|
|
88
102
|
overrides = dict(config.overrides.get(name, {}))
|
|
89
103
|
if url_given or existing is None: # an inherited url stays inherited, not copied
|
|
90
104
|
overrides["url"] = url
|
|
91
|
-
if
|
|
105
|
+
if clearing_tenant:
|
|
106
|
+
if name in config.default_tenants:
|
|
107
|
+
overrides["tenant"] = ""
|
|
108
|
+
else:
|
|
109
|
+
overrides.pop("tenant", None)
|
|
110
|
+
elif tenant is not None:
|
|
92
111
|
overrides["tenant"] = tenant
|
|
93
112
|
if protected is not None:
|
|
94
113
|
overrides["protected"] = protected
|
|
95
114
|
config.envs[name] = Environment(
|
|
96
115
|
name=name,
|
|
97
116
|
url=url,
|
|
98
|
-
tenant=
|
|
117
|
+
tenant=new_tenant,
|
|
99
118
|
protected=protected
|
|
100
119
|
if protected is not None
|
|
101
120
|
else (existing.protected if existing else False),
|
|
@@ -7,6 +7,7 @@ from typing import Any
|
|
|
7
7
|
import click
|
|
8
8
|
|
|
9
9
|
from simple_module_remote.commands.runtime import state_of
|
|
10
|
+
from simple_module_remote.generate.body_help import body_field_summary, set_addressable
|
|
10
11
|
from simple_module_remote.generate.operations import Operation
|
|
11
12
|
from simple_module_remote.generate.pagination import pagination_style
|
|
12
13
|
from simple_module_remote.generate.params import (
|
|
@@ -20,6 +21,24 @@ from simple_module_remote.output.sanitize import sanitize
|
|
|
20
21
|
__all__ = ["operation_command"]
|
|
21
22
|
|
|
22
23
|
|
|
24
|
+
def _fields_help(op: Operation, root: dict) -> str:
|
|
25
|
+
fields, more = body_field_summary(op.body_schema, root)
|
|
26
|
+
if not fields:
|
|
27
|
+
return ""
|
|
28
|
+
# ascii() shows a name exactly where sanitize would drop control characters from it.
|
|
29
|
+
names = [f.name if f.name.isprintable() else ascii(f.name) for f in fields]
|
|
30
|
+
listed = ", ".join(
|
|
31
|
+
f"{name}{'*' if f.required else ''} ({sanitize(f.kind)})"
|
|
32
|
+
for name, f in zip(names, fields, strict=True)
|
|
33
|
+
)
|
|
34
|
+
text = f"\n\nBody fields for --set (* required): {listed}"
|
|
35
|
+
if more:
|
|
36
|
+
text += f", and {more} more (see the schema)"
|
|
37
|
+
if not all(set_addressable(f.name) for f in fields):
|
|
38
|
+
text += ". Empty names and names with . or = cannot be set with --set: use --json or --file"
|
|
39
|
+
return text
|
|
40
|
+
|
|
41
|
+
|
|
23
42
|
def operation_command(op: Operation, root: dict) -> click.Command:
|
|
24
43
|
pageable = (
|
|
25
44
|
returns_list(op, root) and pagination_style(op, json_response_schema(op, root)) is not None
|
|
@@ -39,6 +58,8 @@ def operation_command(op: Operation, root: dict) -> click.Command:
|
|
|
39
58
|
route = sanitize(f"{op.method} {op.path}")
|
|
40
59
|
summary = sanitize(op.summary)
|
|
41
60
|
text = sanitize(op.description) or summary
|
|
61
|
+
if op.body_kind == "json":
|
|
62
|
+
text += _fields_help(op, root)
|
|
42
63
|
if not success_is_json(op, root):
|
|
43
64
|
text += "\n\nThe response is not JSON: redirect stdout or use --out FILE."
|
|
44
65
|
return click.Command(
|
{simple_module_remote-0.0.50 → simple_module_remote-0.0.51}/simple_module_remote/commands/root.py
RENAMED
|
@@ -25,6 +25,12 @@ from simple_module_remote.commands.schema_source import (
|
|
|
25
25
|
peek_root_flags,
|
|
26
26
|
)
|
|
27
27
|
from simple_module_remote.config.credentials import KeyringBackend
|
|
28
|
+
from simple_module_remote.curated.loader import (
|
|
29
|
+
apply_curated_providers,
|
|
30
|
+
builtin_providers,
|
|
31
|
+
load_providers,
|
|
32
|
+
)
|
|
33
|
+
from simple_module_remote.curated.provider import CuratedError, CuratedProvider
|
|
28
34
|
from simple_module_remote.generate.tree import build_groups
|
|
29
35
|
from simple_module_remote.schema.loader import load_schema
|
|
30
36
|
|
|
@@ -41,18 +47,22 @@ class _RootGroup(click.Group):
|
|
|
41
47
|
"""Reports every usage error with exit code 1; installs the generated groups per run."""
|
|
42
48
|
|
|
43
49
|
bundled: SchemaChoice
|
|
50
|
+
providers: tuple[CuratedProvider, ...] = ()
|
|
44
51
|
_generated: tuple[str, ...] = ()
|
|
45
52
|
|
|
46
|
-
def install(self, groups: list[click.Group]) -> None:
|
|
47
|
-
"""Replace the generated groups (top level
|
|
53
|
+
def install(self, groups: list[click.Group], schema: dict, state: AppState) -> None:
|
|
54
|
+
"""Replace the generated groups (top level with curated overlays, pure under ``raw``)."""
|
|
48
55
|
for name in self._generated:
|
|
49
56
|
self.commands.pop(name, None)
|
|
57
|
+
top_groups, hidden = apply_curated_providers(groups, schema, self.providers, state)
|
|
58
|
+
state.hidden_providers = hidden
|
|
50
59
|
raw = click.Group(RAW_GROUP, help="Generated commands, mirrored under raw.")
|
|
51
|
-
for group in
|
|
60
|
+
for group in top_groups:
|
|
52
61
|
self.add_command(group)
|
|
62
|
+
for group in groups:
|
|
53
63
|
raw.add_command(group)
|
|
54
64
|
self.add_command(raw)
|
|
55
|
-
self._generated = (*(g.name for g in
|
|
65
|
+
self._generated = (*(g.name for g in top_groups if g.name), RAW_GROUP)
|
|
56
66
|
|
|
57
67
|
def parse_args(self, ctx: click.Context, args: list[str]) -> list[str]:
|
|
58
68
|
state = ctx.obj
|
|
@@ -70,7 +80,10 @@ class _RootGroup(click.Group):
|
|
|
70
80
|
state.preselected = (
|
|
71
81
|
(flags.env, *choice.selected) if choice.selected is not None else None
|
|
72
82
|
)
|
|
73
|
-
|
|
83
|
+
try:
|
|
84
|
+
self.install(choice.groups, choice.root, state)
|
|
85
|
+
except CuratedError as exc:
|
|
86
|
+
raise CliError(str(exc)) from None
|
|
74
87
|
builtin = flags.command in {cmd.name for cmd in BUILTINS}
|
|
75
88
|
if choice.error and flags.command is not None and not builtin:
|
|
76
89
|
raise CliError(choice.error)
|
|
@@ -141,6 +154,7 @@ def build_cli(
|
|
|
141
154
|
"""
|
|
142
155
|
schema = load_schema(schema_path)
|
|
143
156
|
groups = build_groups(schema, operation_command)
|
|
157
|
+
providers = tuple(load_providers(defaults_path, builtins=builtin_providers()))
|
|
144
158
|
state = AppState(
|
|
145
159
|
cli=name,
|
|
146
160
|
version=version,
|
|
@@ -180,7 +194,8 @@ def build_cli(
|
|
|
180
194
|
)
|
|
181
195
|
root.context_settings = {"obj": state}
|
|
182
196
|
root.bundled = SchemaChoice(SCHEMA_BUNDLED, schema_path, schema, groups)
|
|
197
|
+
root.providers = providers
|
|
183
198
|
for builtin in BUILTINS:
|
|
184
199
|
root.add_command(builtin)
|
|
185
|
-
root.install(groups)
|
|
200
|
+
root.install(groups, schema, state)
|
|
186
201
|
return root
|
{simple_module_remote-0.0.50 → simple_module_remote-0.0.51}/simple_module_remote/commands/runtime.py
RENAMED
|
@@ -8,7 +8,7 @@ from collections.abc import Generator, Mapping
|
|
|
8
8
|
from contextlib import contextmanager
|
|
9
9
|
from dataclasses import dataclass, field
|
|
10
10
|
from pathlib import Path
|
|
11
|
-
from typing import Any
|
|
11
|
+
from typing import TYPE_CHECKING, Any
|
|
12
12
|
|
|
13
13
|
import click
|
|
14
14
|
import httpx
|
|
@@ -36,6 +36,9 @@ from simple_module_remote.http.client import ApiClient
|
|
|
36
36
|
from simple_module_remote.http.errors import EXIT_USAGE, REDIRECT_MIN, ApiError, UnsafePathError
|
|
37
37
|
from simple_module_remote.schema.cache import CacheMeta
|
|
38
38
|
|
|
39
|
+
if TYPE_CHECKING:
|
|
40
|
+
from simple_module_remote.curated.provider import HiddenProvider
|
|
41
|
+
|
|
39
42
|
__all__ = [
|
|
40
43
|
"SCHEMA_BUNDLED",
|
|
41
44
|
"SCHEMA_LIVE",
|
|
@@ -81,6 +84,7 @@ class AppState:
|
|
|
81
84
|
# schema was chosen for it, so requests in this invocation must use the same one.
|
|
82
85
|
preselected: tuple[str | None, Environment, bool] | None = None
|
|
83
86
|
flag_tenant: str | None = None
|
|
87
|
+
hidden_providers: list[HiddenProvider] = field(default_factory=list)
|
|
84
88
|
_store: CredentialStore | None = None
|
|
85
89
|
_tokens: dict[tuple[str, str | None, str], ResolvedToken] = field(default_factory=dict)
|
|
86
90
|
|
|
@@ -170,6 +174,7 @@ class AppState:
|
|
|
170
174
|
resolved = self._resolved(env, explicit)
|
|
171
175
|
client = self.client(env, resolved.token)
|
|
172
176
|
run_ctx.tenant = resolved.tenant_label # one canonical name
|
|
177
|
+
run_ctx.token_env_var = resolved.source_var
|
|
173
178
|
return client
|
|
174
179
|
|
|
175
180
|
run_ctx = RunContext(
|
|
@@ -189,7 +194,8 @@ class AppState:
|
|
|
189
194
|
return run_ctx
|
|
190
195
|
|
|
191
196
|
def schema_hint(self, env: Environment) -> str:
|
|
192
|
-
"""
|
|
197
|
+
"""The hint for a generated command whose error suggests a stale schema
|
|
198
|
+
(``http.error_kinds.schema_mismatch`` decides when)."""
|
|
193
199
|
if self.schema_source == SCHEMA_LIVE:
|
|
194
200
|
return (
|
|
195
201
|
f"hint: the server may have changed: run `{self.cli} --env {env.name} schema sync`"
|