kamiwaza-cli 2.0.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.
- kamiwaza_cli/__init__.py +27 -0
- kamiwaza_cli/__main__.py +8 -0
- kamiwaza_cli/auth/__init__.py +39 -0
- kamiwaza_cli/auth/client_factory.py +127 -0
- kamiwaza_cli/auth/oidc.py +1074 -0
- kamiwaza_cli/auth/refresh.py +76 -0
- kamiwaza_cli/auth/token_cache.py +206 -0
- kamiwaza_cli/checks/__init__.py +130 -0
- kamiwaza_cli/checks/base.py +216 -0
- kamiwaza_cli/checks/batch_execution.py +99 -0
- kamiwaza_cli/checks/control_plane.py +53 -0
- kamiwaza_cli/checks/data_store.py +99 -0
- kamiwaza_cli/checks/identity.py +170 -0
- kamiwaza_cli/checks/ingress.py +102 -0
- kamiwaza_cli/checks/model_serving.py +326 -0
- kamiwaza_cli/cli.py +344 -0
- kamiwaza_cli/commands/__init__.py +7 -0
- kamiwaza_cli/commands/_common.py +112 -0
- kamiwaza_cli/commands/certs.py +1066 -0
- kamiwaza_cli/commands/context.py +732 -0
- kamiwaza_cli/commands/diagnose.py +289 -0
- kamiwaza_cli/commands/dns.py +261 -0
- kamiwaza_cli/commands/login.py +394 -0
- kamiwaza_cli/commands/logs.py +328 -0
- kamiwaza_cli/commands/models.py +425 -0
- kamiwaza_cli/commands/provider.py +253 -0
- kamiwaza_cli/commands/resources.py +573 -0
- kamiwaza_cli/commands/restart.py +328 -0
- kamiwaza_cli/commands/schema.py +96 -0
- kamiwaza_cli/commands/status.py +200 -0
- kamiwaza_cli/commands/support_bundle.py +910 -0
- kamiwaza_cli/commands/traffic.py +249 -0
- kamiwaza_cli/commands/ui.py +99 -0
- kamiwaza_cli/commands/user.py +900 -0
- kamiwaza_cli/commands/version.py +108 -0
- kamiwaza_cli/components/__init__.py +13 -0
- kamiwaza_cli/components/resolver.py +55 -0
- kamiwaza_cli/components/vocabulary.py +93 -0
- kamiwaza_cli/context/__init__.py +17 -0
- kamiwaza_cli/context/registry.py +267 -0
- kamiwaza_cli/exit_codes.py +81 -0
- kamiwaza_cli/http/__init__.py +9 -0
- kamiwaza_cli/http/tls.py +188 -0
- kamiwaza_cli/ops/__init__.py +16 -0
- kamiwaza_cli/ops/certs.py +1951 -0
- kamiwaza_cli/ops/dns.py +890 -0
- kamiwaza_cli/ops/documents.py +110 -0
- kamiwaza_cli/ops/models.py +171 -0
- kamiwaza_cli/ops/providers.py +424 -0
- kamiwaza_cli/ops/resources.py +151 -0
- kamiwaza_cli/ops/status.py +213 -0
- kamiwaza_cli/ops/traffic.py +954 -0
- kamiwaza_cli/output/__init__.py +19 -0
- kamiwaza_cli/output/errors.py +83 -0
- kamiwaza_cli/output/human.py +95 -0
- kamiwaza_cli/output/structured.py +40 -0
- kamiwaza_cli/substrate/__init__.py +30 -0
- kamiwaza_cli/substrate/_sdk_logging.py +74 -0
- kamiwaza_cli/substrate/base.py +136 -0
- kamiwaza_cli/substrate/detect.py +301 -0
- kamiwaza_cli/substrate/kube.py +79 -0
- kamiwaza_cli/substrate/nonorchestrated.py +381 -0
- kamiwaza_cli/substrate/orchestrated.py +824 -0
- kamiwaza_cli/support_bundle/__init__.py +10 -0
- kamiwaza_cli/support_bundle/analyze.py +371 -0
- kamiwaza_cli/support_bundle/analyzers/__init__.py +3 -0
- kamiwaza_cli/support_bundle/analyzers/_helpers.py +224 -0
- kamiwaza_cli/support_bundle/analyzers/base.py +107 -0
- kamiwaza_cli/support_bundle/analyzers/cert_expiry.py +170 -0
- kamiwaza_cli/support_bundle/analyzers/coredns_health.py +319 -0
- kamiwaza_cli/support_bundle/analyzers/diagnose_status.py +211 -0
- kamiwaza_cli/support_bundle/analyzers/event_reason_scan.py +248 -0
- kamiwaza_cli/support_bundle/analyzers/http_status.py +129 -0
- kamiwaza_cli/support_bundle/analyzers/json_path.py +318 -0
- kamiwaza_cli/support_bundle/analyzers/log_pattern.py +119 -0
- kamiwaza_cli/support_bundle/analyzers/node_pressure.py +163 -0
- kamiwaza_cli/support_bundle/analyzers/present.py +99 -0
- kamiwaza_cli/support_bundle/analyzers/registry.py +120 -0
- kamiwaza_cli/support_bundle/analyzers/restart_count.py +247 -0
- kamiwaza_cli/support_bundle/analyzers/secret_leak.py +107 -0
- kamiwaza_cli/support_bundle/analyzers/statefulset_quorum.py +233 -0
- kamiwaza_cli/support_bundle/analyzers/text_match.py +170 -0
- kamiwaza_cli/support_bundle/analyzers/time_skew.py +121 -0
- kamiwaza_cli/support_bundle/collectors/__init__.py +3 -0
- kamiwaza_cli/support_bundle/collectors/_io.py +201 -0
- kamiwaza_cli/support_bundle/collectors/base.py +181 -0
- kamiwaza_cli/support_bundle/collectors/cluster_info.py +127 -0
- kamiwaza_cli/support_bundle/collectors/cluster_time.py +167 -0
- kamiwaza_cli/support_bundle/collectors/config.py +168 -0
- kamiwaza_cli/support_bundle/collectors/data.py +157 -0
- kamiwaza_cli/support_bundle/collectors/diagnose_snapshot.py +110 -0
- kamiwaza_cli/support_bundle/collectors/events.py +162 -0
- kamiwaza_cli/support_bundle/collectors/host.py +424 -0
- kamiwaza_cli/support_bundle/collectors/host_file.py +587 -0
- kamiwaza_cli/support_bundle/collectors/http.py +246 -0
- kamiwaza_cli/support_bundle/collectors/k8s/__init__.py +59 -0
- kamiwaza_cli/support_bundle/collectors/k8s/_client.py +395 -0
- kamiwaza_cli/support_bundle/collectors/k8s/_common.py +317 -0
- kamiwaza_cli/support_bundle/collectors/k8s/_kubeconfig.py +448 -0
- kamiwaza_cli/support_bundle/collectors/k8s/_kubectl.py +645 -0
- kamiwaza_cli/support_bundle/collectors/k8s/_resolver.py +307 -0
- kamiwaza_cli/support_bundle/collectors/k8s/cert_resources.py +91 -0
- kamiwaza_cli/support_bundle/collectors/k8s/coredns.py +242 -0
- kamiwaza_cli/support_bundle/collectors/k8s/dns_probe.py +879 -0
- kamiwaza_cli/support_bundle/collectors/k8s/events.py +63 -0
- kamiwaza_cli/support_bundle/collectors/k8s/exec.py +313 -0
- kamiwaza_cli/support_bundle/collectors/k8s/image_inventory.py +81 -0
- kamiwaza_cli/support_bundle/collectors/k8s/nodes.py +52 -0
- kamiwaza_cli/support_bundle/collectors/k8s/pod_copy.py +641 -0
- kamiwaza_cli/support_bundle/collectors/k8s/pod_inventory.py +81 -0
- kamiwaza_cli/support_bundle/collectors/k8s/popeye.py +109 -0
- kamiwaza_cli/support_bundle/collectors/k8s/previous_logs.py +110 -0
- kamiwaza_cli/support_bundle/collectors/k8s/ray_status.py +85 -0
- kamiwaza_cli/support_bundle/collectors/k8s/statefulset_health.py +66 -0
- kamiwaza_cli/support_bundle/collectors/logs.py +191 -0
- kamiwaza_cli/support_bundle/collectors/meta.py +112 -0
- kamiwaza_cli/support_bundle/collectors/previous_bundle_diff.py +282 -0
- kamiwaza_cli/support_bundle/collectors/registry.py +186 -0
- kamiwaza_cli/support_bundle/collectors/secrets_inventory.py +217 -0
- kamiwaza_cli/support_bundle/discovery.py +324 -0
- kamiwaza_cli/support_bundle/exceptions.py +94 -0
- kamiwaza_cli/support_bundle/manifest.py +318 -0
- kamiwaza_cli/support_bundle/output.py +291 -0
- kamiwaza_cli/support_bundle/pipeline.py +792 -0
- kamiwaza_cli/support_bundle/redaction_engine.py +177 -0
- kamiwaza_cli/support_bundle/redactors/__init__.py +3 -0
- kamiwaza_cli/support_bundle/redactors/base.py +90 -0
- kamiwaza_cli/support_bundle/redactors/builtin.py +181 -0
- kamiwaza_cli/support_bundle/redactors/operator.py +41 -0
- kamiwaza_cli/support_bundle/redactors/secret_name.py +77 -0
- kamiwaza_cli/support_bundle/spec/README.md +15 -0
- kamiwaza_cli/support_bundle/spec/__init__.py +3 -0
- kamiwaza_cli/support_bundle/spec/bundle-spec.schema.json +898 -0
- kamiwaza_cli/support_bundle/spec/effective.py +178 -0
- kamiwaza_cli/support_bundle/spec/merge.py +116 -0
- kamiwaza_cli/support_bundle/spec/parser.py +779 -0
- kamiwaza_cli/support_bundle/spec/resolver.py +202 -0
- kamiwaza_cli/support_bundle/spec/types.py +760 -0
- kamiwaza_cli/support_bundle/spec/well_known.py +128 -0
- kamiwaza_cli/support_bundle/specs/__init__.py +7 -0
- kamiwaza_cli/support_bundle/specs/default-categories.yaml +46 -0
- kamiwaza_cli/support_bundle/specs/default-with-k8s.yaml +417 -0
- kamiwaza_cli/support_bundle/specs/default.yaml +331 -0
- kamiwaza_cli/support_bundle/synthesizers/__init__.py +25 -0
- kamiwaza_cli/support_bundle/synthesizers/summary_md.py +216 -0
- kamiwaza_cli/support_bundle/synthesizers/timeline_json.py +283 -0
- kamiwaza_cli/support_bundle/tarball.py +100 -0
- kamiwaza_cli/support_bundle/viewer/__init__.py +19 -0
- kamiwaza_cli/support_bundle/viewer/analysis_summary.py +197 -0
- kamiwaza_cli/support_bundle/viewer/assets/__init__.py +8 -0
- kamiwaza_cli/support_bundle/viewer/assets/dashboard.html +3273 -0
- kamiwaza_cli/support_bundle/viewer/loader.py +261 -0
- kamiwaza_cli/support_bundle/viewer/output.py +65 -0
- kamiwaza_cli/support_bundle/viewer/payload.py +58 -0
- kamiwaza_cli/support_bundle/viewer/run.py +105 -0
- kamiwaza_cli/support_bundle/viewer/template.py +104 -0
- kamiwaza_cli/support_bundle/viewer/types.py +103 -0
- kamiwaza_cli/tui/__init__.py +14 -0
- kamiwaza_cli/tui/access_log.py +66 -0
- kamiwaza_cli/tui/actions.py +159 -0
- kamiwaza_cli/tui/app.py +3337 -0
- kamiwaza_cli/tui/bootstrap.py +41 -0
- kamiwaza_cli/tui/bundle.py +171 -0
- kamiwaza_cli/tui/capacity.py +191 -0
- kamiwaza_cli/tui/catalog.py +2908 -0
- kamiwaza_cli/tui/chat.py +72 -0
- kamiwaza_cli/tui/clipboard.py +45 -0
- kamiwaza_cli/tui/context.py +128 -0
- kamiwaza_cli/tui/describe_render.py +244 -0
- kamiwaza_cli/tui/editing.py +337 -0
- kamiwaza_cli/tui/errors.py +195 -0
- kamiwaza_cli/tui/extension_starters.py +179 -0
- kamiwaza_cli/tui/external_editor.py +97 -0
- kamiwaza_cli/tui/health.py +503 -0
- kamiwaza_cli/tui/identity.py +66 -0
- kamiwaza_cli/tui/logstream/__init__.py +12 -0
- kamiwaza_cli/tui/logstream/aggregator.py +206 -0
- kamiwaza_cli/tui/logstream/correlate.py +111 -0
- kamiwaza_cli/tui/logstream/histogram.py +259 -0
- kamiwaza_cli/tui/logstream/normalize.py +356 -0
- kamiwaza_cli/tui/logstream/patterns.py +269 -0
- kamiwaza_cli/tui/logstream/timeindex.py +129 -0
- kamiwaza_cli/tui/masking.py +111 -0
- kamiwaza_cli/tui/notecards.py +646 -0
- kamiwaza_cli/tui/pod_shell.py +188 -0
- kamiwaza_cli/tui/providers/__init__.py +8 -0
- kamiwaza_cli/tui/providers/base.py +175 -0
- kamiwaza_cli/tui/providers/jobs.py +129 -0
- kamiwaza_cli/tui/providers/k8s.py +251 -0
- kamiwaza_cli/tui/providers/kr8s_accessor.py +780 -0
- kamiwaza_cli/tui/providers/sdk.py +558 -0
- kamiwaza_cli/tui/providers/substrate.py +165 -0
- kamiwaza_cli/tui/providers/trust.py +198 -0
- kamiwaza_cli/tui/recommendations.py +194 -0
- kamiwaza_cli/tui/registry.py +176 -0
- kamiwaza_cli/tui/run.py +66 -0
- kamiwaza_cli/tui/scheduler.py +139 -0
- kamiwaza_cli/tui/screens/__init__.py +26 -0
- kamiwaza_cli/tui/screens/access_log.py +129 -0
- kamiwaza_cli/tui/screens/add_context.py +390 -0
- kamiwaza_cli/tui/screens/analytics.py +364 -0
- kamiwaza_cli/tui/screens/chat.py +138 -0
- kamiwaza_cli/tui/screens/choose.py +78 -0
- kamiwaza_cli/tui/screens/confirm.py +133 -0
- kamiwaza_cli/tui/screens/context_switch.py +65 -0
- kamiwaza_cli/tui/screens/describe.py +271 -0
- kamiwaza_cli/tui/screens/detail.py +359 -0
- kamiwaza_cli/tui/screens/diagnostics.py +133 -0
- kamiwaza_cli/tui/screens/dns.py +355 -0
- kamiwaza_cli/tui/screens/framed.py +70 -0
- kamiwaza_cli/tui/screens/list.py +876 -0
- kamiwaza_cli/tui/screens/log_explorer.py +960 -0
- kamiwaza_cli/tui/screens/logs.py +282 -0
- kamiwaza_cli/tui/screens/model_pull.py +405 -0
- kamiwaza_cli/tui/screens/offline.py +96 -0
- kamiwaza_cli/tui/screens/overview.py +1322 -0
- kamiwaza_cli/tui/screens/recommendations.py +168 -0
- kamiwaza_cli/tui/screens/resources.py +115 -0
- kamiwaza_cli/tui/screens/subsystem.py +375 -0
- kamiwaza_cli/tui/screens/swagger.py +536 -0
- kamiwaza_cli/tui/screens/theme_picker.py +109 -0
- kamiwaza_cli/tui/screens/traffic.py +302 -0
- kamiwaza_cli/tui/screens/workroom.py +107 -0
- kamiwaza_cli/tui/serving.py +343 -0
- kamiwaza_cli/tui/state.py +46 -0
- kamiwaza_cli/tui/status.py +62 -0
- kamiwaza_cli/tui/swagger.py +284 -0
- kamiwaza_cli/tui/widgets/__init__.py +5 -0
- kamiwaza_cli/tui/widgets/action_menu.py +46 -0
- kamiwaza_cli/tui/widgets/aggregated_log_pane.py +515 -0
- kamiwaza_cli/tui/widgets/banner.py +54 -0
- kamiwaza_cli/tui/widgets/frame.py +110 -0
- kamiwaza_cli/tui/widgets/history_input.py +100 -0
- kamiwaza_cli/tui/widgets/log_pane.py +243 -0
- kamiwaza_cli/tui/widgets/log_syntax.py +116 -0
- kamiwaza_cli/tui/widgets/nav_option_list.py +74 -0
- kamiwaza_cli/tui/widgets/resource_table.py +196 -0
- kamiwaza_cli/tui/widgets/status_cell.py +44 -0
- kamiwaza_cli/tui/widgets/vim_scroll.py +35 -0
- kamiwaza_cli/tui/workroom.py +94 -0
- kamiwaza_cli-2.0.0.dist-info/METADATA +341 -0
- kamiwaza_cli-2.0.0.dist-info/RECORD +247 -0
- kamiwaza_cli-2.0.0.dist-info/WHEEL +5 -0
- kamiwaza_cli-2.0.0.dist-info/entry_points.txt +2 -0
- kamiwaza_cli-2.0.0.dist-info/licenses/LICENSE +202 -0
- kamiwaza_cli-2.0.0.dist-info/licenses/NOTICE +4 -0
- kamiwaza_cli-2.0.0.dist-info/top_level.txt +1 -0
kamiwaza_cli/__init__.py
ADDED
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
"""Kamiwaza operator CLI.
|
|
2
|
+
|
|
3
|
+
A standalone, cross-substrate operations CLI for Kamiwaza deployments.
|
|
4
|
+
Implementation reuses the ``kamiwaza-sdk`` Python package for all
|
|
5
|
+
client-side platform calls per Constitution Principle II v1.1.0.
|
|
6
|
+
"""
|
|
7
|
+
|
|
8
|
+
from __future__ import annotations
|
|
9
|
+
|
|
10
|
+
import warnings
|
|
11
|
+
from importlib.metadata import PackageNotFoundError, version
|
|
12
|
+
|
|
13
|
+
# Authlib >=1.7 still imports its deprecated ``authlib.jose`` shim at
|
|
14
|
+
# import time; the warning is informational and irrelevant to operators
|
|
15
|
+
# of the CLI. Filter it once, before any submodule pulls authlib in.
|
|
16
|
+
warnings.filterwarnings(
|
|
17
|
+
"ignore",
|
|
18
|
+
message=r".*authlib\.jose module is deprecated.*",
|
|
19
|
+
category=DeprecationWarning,
|
|
20
|
+
)
|
|
21
|
+
|
|
22
|
+
try:
|
|
23
|
+
__version__ = version("kamiwaza-cli")
|
|
24
|
+
except PackageNotFoundError:
|
|
25
|
+
__version__ = "0.0.0"
|
|
26
|
+
|
|
27
|
+
__all__ = ["__version__"]
|
kamiwaza_cli/__main__.py
ADDED
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
"""Authentication subsystem.
|
|
2
|
+
|
|
3
|
+
The CLI's auth boundary on top of ``kamiwaza-sdk``: the OIDC flow
|
|
4
|
+
produces a bearer token; the token cache subclasses
|
|
5
|
+
``kamiwaza_sdk.token_store.FileTokenStore`` for per-context isolation,
|
|
6
|
+
file locking, and mode-0600 enforcement; the client factory hands the
|
|
7
|
+
bearer to ``KamiwazaClient(api_key=...)``.
|
|
8
|
+
|
|
9
|
+
The SDK's ``OAuthAuthenticator`` stub is intentionally not used at first
|
|
10
|
+
release; if upstream implements OIDC there we rebase onto it then.
|
|
11
|
+
"""
|
|
12
|
+
|
|
13
|
+
from .client_factory import build_client, build_client_for_active_context
|
|
14
|
+
from .refresh import refresh_if_needed
|
|
15
|
+
from .token_cache import ExtendedStoredToken, PerContextTokenCache
|
|
16
|
+
|
|
17
|
+
__all__ = [
|
|
18
|
+
"ExtendedStoredToken",
|
|
19
|
+
"OIDCClient",
|
|
20
|
+
"OIDCFlowError",
|
|
21
|
+
"PerContextTokenCache",
|
|
22
|
+
"build_client",
|
|
23
|
+
"build_client_for_active_context",
|
|
24
|
+
"refresh_if_needed",
|
|
25
|
+
]
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
def __getattr__(name: str):
|
|
29
|
+
"""Lazy re-export of OIDC symbols.
|
|
30
|
+
|
|
31
|
+
``OIDCClient``/``OIDCFlowError`` pull in :mod:`authlib`; importing
|
|
32
|
+
them eagerly inflates cold-start for every command (research.md R1).
|
|
33
|
+
"""
|
|
34
|
+
|
|
35
|
+
if name in {"OIDCClient", "OIDCFlowError"}:
|
|
36
|
+
from . import oidc
|
|
37
|
+
|
|
38
|
+
return getattr(oidc, name)
|
|
39
|
+
raise AttributeError(f"module {__name__!r} has no attribute {name!r}")
|
|
@@ -0,0 +1,127 @@
|
|
|
1
|
+
"""Construct configured ``KamiwazaClient`` instances.
|
|
2
|
+
|
|
3
|
+
The single boundary between the CLI's auth layer and every SDK call.
|
|
4
|
+
Per Constitution Principle II v1.1.0 every command obtains its
|
|
5
|
+
``KamiwazaClient`` through this factory; nothing else in the CLI is
|
|
6
|
+
allowed to call ``KamiwazaClient(...)`` directly.
|
|
7
|
+
|
|
8
|
+
Defensive logging note: the bearer token is forwarded into the SDK via
|
|
9
|
+
the ``api_key=`` kwarg and is never logged from this module. The token
|
|
10
|
+
also never appears in the ``KamiwazaClient.__repr__`` (the SDK does not
|
|
11
|
+
override it; the default ``object.__repr__`` shows only the address).
|
|
12
|
+
"""
|
|
13
|
+
|
|
14
|
+
from __future__ import annotations
|
|
15
|
+
|
|
16
|
+
import logging
|
|
17
|
+
from urllib.parse import urlsplit
|
|
18
|
+
|
|
19
|
+
from kamiwaza_sdk import KamiwazaClient
|
|
20
|
+
|
|
21
|
+
from ..context.registry import Context, ContextRegistry
|
|
22
|
+
from ..exit_codes import CONFIG_ERROR, PERMISSION_DENIED
|
|
23
|
+
from ..http.tls import requests_verify_setting, using_context
|
|
24
|
+
from ..output.errors import CliError
|
|
25
|
+
from .refresh import refresh_if_needed
|
|
26
|
+
from .token_cache import ExtendedStoredToken, PerContextTokenCache
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
def _api_base(endpoint: str) -> str:
|
|
30
|
+
"""Derive the SDK data-plane base URL from a context endpoint.
|
|
31
|
+
|
|
32
|
+
Operators register the deployment *root* (e.g. ``https://host``) —
|
|
33
|
+
the same URL that serves the dashboard and the bundled identity
|
|
34
|
+
provider, and the URL that OIDC discovery is built from. Every
|
|
35
|
+
``KamiwazaClient`` data-plane call, though, targets the API mount,
|
|
36
|
+
which Kamiwaza serves under ``/api``. Pointing the SDK at the bare
|
|
37
|
+
root makes it receive the dashboard's HTML and raise
|
|
38
|
+
``NonAPIResponseError``.
|
|
39
|
+
|
|
40
|
+
We append ``/api`` here, at the single point where the SDK client is
|
|
41
|
+
built, so the stored endpoint stays the deployment root (which OIDC
|
|
42
|
+
discovery needs) while the data plane still reaches the right path.
|
|
43
|
+
|
|
44
|
+
The append is conservative and idempotent: it only fires when the
|
|
45
|
+
endpoint carries no path component at all (the common bare-host
|
|
46
|
+
form). An endpoint that already names a path — ``/api`` or anything
|
|
47
|
+
else the operator pinned deliberately — is returned unchanged (minus
|
|
48
|
+
any trailing slash), so we never fight an explicit configuration.
|
|
49
|
+
"""
|
|
50
|
+
base = endpoint.rstrip("/")
|
|
51
|
+
parts = urlsplit(base)
|
|
52
|
+
if parts.scheme and parts.netloc and parts.path == "":
|
|
53
|
+
return base + "/api"
|
|
54
|
+
return base
|
|
55
|
+
|
|
56
|
+
|
|
57
|
+
def build_client(
|
|
58
|
+
context: Context,
|
|
59
|
+
cache: PerContextTokenCache,
|
|
60
|
+
*,
|
|
61
|
+
log_level: int = logging.WARNING,
|
|
62
|
+
) -> KamiwazaClient:
|
|
63
|
+
"""Build a ``KamiwazaClient`` against ``context``.
|
|
64
|
+
|
|
65
|
+
Refreshes the bearer transparently if needed; raises
|
|
66
|
+
:class:`CliError` (exit 77) when no usable token is on disk.
|
|
67
|
+
"""
|
|
68
|
+
with using_context(context, root=cache.path.parents[2]):
|
|
69
|
+
token = refresh_if_needed(context, cache)
|
|
70
|
+
if token is None:
|
|
71
|
+
raise CliError(
|
|
72
|
+
summary=f"No valid credentials for context '{context.name}'",
|
|
73
|
+
next_step=f"run `kamiwaza login --context {context.name}` to authenticate",
|
|
74
|
+
exit_code=PERMISSION_DENIED,
|
|
75
|
+
)
|
|
76
|
+
if not isinstance(token, ExtendedStoredToken):
|
|
77
|
+
token = ExtendedStoredToken(
|
|
78
|
+
access_token=token.access_token,
|
|
79
|
+
refresh_token=token.refresh_token,
|
|
80
|
+
expires_at=token.expires_at,
|
|
81
|
+
)
|
|
82
|
+
client = KamiwazaClient(
|
|
83
|
+
base_url=_api_base(context.endpoint),
|
|
84
|
+
api_key=token.access_token,
|
|
85
|
+
log_level=log_level,
|
|
86
|
+
)
|
|
87
|
+
_apply_tls_posture(client, context)
|
|
88
|
+
return client
|
|
89
|
+
|
|
90
|
+
|
|
91
|
+
def _apply_tls_posture(client: KamiwazaClient, context: Context) -> None:
|
|
92
|
+
"""Apply the selected context's TLS verification policy to the SDK session."""
|
|
93
|
+
verify = requests_verify_setting(context)
|
|
94
|
+
session = getattr(client, "session", None)
|
|
95
|
+
if session is None:
|
|
96
|
+
return
|
|
97
|
+
session.verify = verify
|
|
98
|
+
|
|
99
|
+
|
|
100
|
+
def build_client_for_active_context(
|
|
101
|
+
*,
|
|
102
|
+
registry: ContextRegistry | None = None,
|
|
103
|
+
override_context: str | None = None,
|
|
104
|
+
log_level: int = logging.WARNING,
|
|
105
|
+
) -> tuple[KamiwazaClient, Context]:
|
|
106
|
+
"""Resolve the active context (or ``override_context``) and build a client.
|
|
107
|
+
|
|
108
|
+
Returns ``(client, context)`` so the caller can record telemetry or
|
|
109
|
+
update ``last_used_at`` on the registry.
|
|
110
|
+
"""
|
|
111
|
+
reg = registry or ContextRegistry()
|
|
112
|
+
if override_context:
|
|
113
|
+
ctx = reg.get(override_context)
|
|
114
|
+
else:
|
|
115
|
+
ctx = reg.active()
|
|
116
|
+
if ctx is None:
|
|
117
|
+
raise CliError(
|
|
118
|
+
summary="No active context",
|
|
119
|
+
next_step=(
|
|
120
|
+
"run `kamiwaza context add <name> --endpoint <url>` and "
|
|
121
|
+
"`kamiwaza context use <name>` to set an active context"
|
|
122
|
+
),
|
|
123
|
+
exit_code=CONFIG_ERROR,
|
|
124
|
+
)
|
|
125
|
+
cache = PerContextTokenCache(ctx.name, root=reg.root)
|
|
126
|
+
client = build_client(ctx, cache, log_level=log_level)
|
|
127
|
+
return client, ctx
|