vayu-cli 0.1.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.
- vayu_cli-0.1.0/.gitignore +31 -0
- vayu_cli-0.1.0/PKG-INFO +57 -0
- vayu_cli-0.1.0/README.md +47 -0
- vayu_cli-0.1.0/pyproject.toml +21 -0
- vayu_cli-0.1.0/src/vayu_cli/__init__.py +3 -0
- vayu_cli-0.1.0/src/vayu_cli/api.py +157 -0
- vayu_cli-0.1.0/src/vayu_cli/credentials.py +85 -0
- vayu_cli-0.1.0/src/vayu_cli/main.py +207 -0
- vayu_cli-0.1.0/src/vayu_cli/redaction.py +36 -0
- vayu_cli-0.1.0/src/vayu_cli/service.py +72 -0
- vayu_cli-0.1.0/tests/test_cli.py +124 -0
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
# Environment
|
|
2
|
+
.env
|
|
3
|
+
*.env
|
|
4
|
+
.env.*
|
|
5
|
+
|
|
6
|
+
# Python
|
|
7
|
+
__pycache__/
|
|
8
|
+
*.pyc
|
|
9
|
+
*.pyo
|
|
10
|
+
venv/
|
|
11
|
+
.venv/
|
|
12
|
+
*.egg-info/
|
|
13
|
+
dist/
|
|
14
|
+
build/
|
|
15
|
+
|
|
16
|
+
# IDE
|
|
17
|
+
.idea/
|
|
18
|
+
.vscode/
|
|
19
|
+
|
|
20
|
+
# Alembic
|
|
21
|
+
alembic/versions/*.pyc
|
|
22
|
+
|
|
23
|
+
# Logs
|
|
24
|
+
*.log
|
|
25
|
+
|
|
26
|
+
# Local HTTP client env
|
|
27
|
+
http-requests/http-client.env.json
|
|
28
|
+
.DS_Store
|
|
29
|
+
*.dump
|
|
30
|
+
*.dump
|
|
31
|
+
*.csv
|
vayu_cli-0.1.0/PKG-INFO
ADDED
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
Metadata-Version: 2.5
|
|
2
|
+
Name: vayu-cli
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: The privacy-conscious command line companion for VAYU
|
|
5
|
+
Author: VAYU
|
|
6
|
+
License: Proprietary
|
|
7
|
+
Requires-Python: >=3.10
|
|
8
|
+
Requires-Dist: keyring<27,>=25.0
|
|
9
|
+
Description-Content-Type: text/markdown
|
|
10
|
+
|
|
11
|
+
# VAYU CLI
|
|
12
|
+
|
|
13
|
+
VAYU CLI is free to install. It provides a local redaction tool and a
|
|
14
|
+
browser-approved route to VAYU's managed diagnosis service.
|
|
15
|
+
|
|
16
|
+
Local commands do not upload content. Managed diagnoses use the same VAYU
|
|
17
|
+
account allowance as the web workspace; the CLI is never an unmetered route
|
|
18
|
+
around a plan.
|
|
19
|
+
|
|
20
|
+
## Install
|
|
21
|
+
|
|
22
|
+
Released versions are installed with [pipx](https://pipx.pypa.io/):
|
|
23
|
+
|
|
24
|
+
```bash
|
|
25
|
+
pipx install vayu-cli
|
|
26
|
+
vayu --help
|
|
27
|
+
```
|
|
28
|
+
|
|
29
|
+
`vayu-cli` is not published until its release workflow has completed. Until
|
|
30
|
+
then, use the source install below for development and controlled testing.
|
|
31
|
+
|
|
32
|
+
## Development install
|
|
33
|
+
|
|
34
|
+
```bash
|
|
35
|
+
python -m pip install ./cli
|
|
36
|
+
vayu --help
|
|
37
|
+
```
|
|
38
|
+
|
|
39
|
+
## Commands
|
|
40
|
+
|
|
41
|
+
```bash
|
|
42
|
+
vayu login
|
|
43
|
+
vayu redact pipeline.log > pipeline.redacted.log
|
|
44
|
+
vayu diagnose --stack airflow --logs-file pipeline.redacted.log
|
|
45
|
+
vayu logout
|
|
46
|
+
```
|
|
47
|
+
|
|
48
|
+
`vayu login` opens a VAYU browser page and shows a short confirmation code.
|
|
49
|
+
The password and browser session stay in the browser. The terminal stores only
|
|
50
|
+
an opaque, rotating refresh token in the operating system credential store;
|
|
51
|
+
VAYU CLI refuses to fall back to a plaintext token file.
|
|
52
|
+
|
|
53
|
+
## Service rollout
|
|
54
|
+
|
|
55
|
+
The API surface is disabled by default. A deployment must set
|
|
56
|
+
`CLI_ENABLED=true` only after the migration, browser approval flow, and a
|
|
57
|
+
production smoke test have passed.
|
vayu_cli-0.1.0/README.md
ADDED
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
# VAYU CLI
|
|
2
|
+
|
|
3
|
+
VAYU CLI is free to install. It provides a local redaction tool and a
|
|
4
|
+
browser-approved route to VAYU's managed diagnosis service.
|
|
5
|
+
|
|
6
|
+
Local commands do not upload content. Managed diagnoses use the same VAYU
|
|
7
|
+
account allowance as the web workspace; the CLI is never an unmetered route
|
|
8
|
+
around a plan.
|
|
9
|
+
|
|
10
|
+
## Install
|
|
11
|
+
|
|
12
|
+
Released versions are installed with [pipx](https://pipx.pypa.io/):
|
|
13
|
+
|
|
14
|
+
```bash
|
|
15
|
+
pipx install vayu-cli
|
|
16
|
+
vayu --help
|
|
17
|
+
```
|
|
18
|
+
|
|
19
|
+
`vayu-cli` is not published until its release workflow has completed. Until
|
|
20
|
+
then, use the source install below for development and controlled testing.
|
|
21
|
+
|
|
22
|
+
## Development install
|
|
23
|
+
|
|
24
|
+
```bash
|
|
25
|
+
python -m pip install ./cli
|
|
26
|
+
vayu --help
|
|
27
|
+
```
|
|
28
|
+
|
|
29
|
+
## Commands
|
|
30
|
+
|
|
31
|
+
```bash
|
|
32
|
+
vayu login
|
|
33
|
+
vayu redact pipeline.log > pipeline.redacted.log
|
|
34
|
+
vayu diagnose --stack airflow --logs-file pipeline.redacted.log
|
|
35
|
+
vayu logout
|
|
36
|
+
```
|
|
37
|
+
|
|
38
|
+
`vayu login` opens a VAYU browser page and shows a short confirmation code.
|
|
39
|
+
The password and browser session stay in the browser. The terminal stores only
|
|
40
|
+
an opaque, rotating refresh token in the operating system credential store;
|
|
41
|
+
VAYU CLI refuses to fall back to a plaintext token file.
|
|
42
|
+
|
|
43
|
+
## Service rollout
|
|
44
|
+
|
|
45
|
+
The API surface is disabled by default. A deployment must set
|
|
46
|
+
`CLI_ENABLED=true` only after the migration, browser approval flow, and a
|
|
47
|
+
production smoke test have passed.
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
[build-system]
|
|
2
|
+
requires = ["hatchling>=1.25"]
|
|
3
|
+
build-backend = "hatchling.build"
|
|
4
|
+
|
|
5
|
+
[project]
|
|
6
|
+
name = "vayu-cli"
|
|
7
|
+
version = "0.1.0"
|
|
8
|
+
description = "The privacy-conscious command line companion for VAYU"
|
|
9
|
+
readme = "README.md"
|
|
10
|
+
requires-python = ">=3.10"
|
|
11
|
+
license = {text = "Proprietary"}
|
|
12
|
+
authors = [{name = "VAYU"}]
|
|
13
|
+
dependencies = [
|
|
14
|
+
"keyring>=25.0,<27",
|
|
15
|
+
]
|
|
16
|
+
|
|
17
|
+
[project.scripts]
|
|
18
|
+
vayu = "vayu_cli.main:main"
|
|
19
|
+
|
|
20
|
+
[tool.hatch.build.targets.wheel]
|
|
21
|
+
packages = ["src/vayu_cli"]
|
|
@@ -0,0 +1,157 @@
|
|
|
1
|
+
"""Small, dependency-free HTTPS client for the VAYU CLI API."""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
import json
|
|
6
|
+
from dataclasses import dataclass
|
|
7
|
+
from typing import Any
|
|
8
|
+
from urllib.error import HTTPError, URLError
|
|
9
|
+
from urllib.parse import parse_qs, urlparse
|
|
10
|
+
from urllib.request import HTTPRedirectHandler, Request, build_opener
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
DEFAULT_API_URL = "https://api.vayufix.com"
|
|
14
|
+
REQUEST_TIMEOUT_SECONDS = 30
|
|
15
|
+
OFFICIAL_API_ORIGINS = {
|
|
16
|
+
"https://api.vayufix.com": "https://vayufix.com",
|
|
17
|
+
"https://api-staging.vayufix.com": "https://staging.vayufix.com",
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
class _RejectRedirects(HTTPRedirectHandler):
|
|
22
|
+
"""Never replay logs or bearer credentials at a redirect destination."""
|
|
23
|
+
|
|
24
|
+
def redirect_request(self, req, fp, code, msg, headers, newurl): # noqa: ANN001
|
|
25
|
+
return None
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
# ``urlopen`` follows HTTP redirects by default. That is unsafe for a client
|
|
29
|
+
# carrying diagnostic input or a CLI bearer token: an API redirect must be
|
|
30
|
+
# treated as a failed request, never as authority to contact another origin.
|
|
31
|
+
_NO_REDIRECT_OPENER = build_opener(_RejectRedirects())
|
|
32
|
+
|
|
33
|
+
|
|
34
|
+
@dataclass
|
|
35
|
+
class ApiError(Exception):
|
|
36
|
+
"""A deliberately small, non-reflective API error for terminal output."""
|
|
37
|
+
|
|
38
|
+
status_code: int | None
|
|
39
|
+
error_code: str | None
|
|
40
|
+
message: str
|
|
41
|
+
|
|
42
|
+
def __str__(self) -> str:
|
|
43
|
+
return self.message
|
|
44
|
+
|
|
45
|
+
|
|
46
|
+
def normalize_api_url(value: str) -> str:
|
|
47
|
+
"""Accept only an official VAYU API or a loopback development API."""
|
|
48
|
+
raw = (value or "").strip().rstrip("/")
|
|
49
|
+
parsed = urlparse(raw)
|
|
50
|
+
hostname = (parsed.hostname or "").lower()
|
|
51
|
+
if not raw or parsed.scheme not in {"https", "http"} or not hostname:
|
|
52
|
+
raise ValueError("API URL must be an absolute HTTPS URL")
|
|
53
|
+
if parsed.username or parsed.password or parsed.params or parsed.query or parsed.fragment:
|
|
54
|
+
raise ValueError("API URL cannot contain credentials, query parameters, or fragments")
|
|
55
|
+
if parsed.path not in {"", "/"}:
|
|
56
|
+
raise ValueError("API URL must not include a path")
|
|
57
|
+
normalized = f"{parsed.scheme}://{parsed.netloc.lower()}"
|
|
58
|
+
if normalized in OFFICIAL_API_ORIGINS:
|
|
59
|
+
return normalized
|
|
60
|
+
if hostname in {"localhost", "127.0.0.1", "::1"}:
|
|
61
|
+
return normalized
|
|
62
|
+
raise ValueError("API URL must be VAYU production, VAYU staging, or a loopback development URL")
|
|
63
|
+
|
|
64
|
+
|
|
65
|
+
def validate_verification_uri(api_url: str, value: str) -> str:
|
|
66
|
+
"""Prevent a hostile API override from turning device login into phishing."""
|
|
67
|
+
normalized_api_url = normalize_api_url(api_url)
|
|
68
|
+
parsed = urlparse(value)
|
|
69
|
+
if parsed.username or parsed.password or parsed.fragment or parsed.path != "/cli/activate":
|
|
70
|
+
raise ValueError("VAYU returned an invalid terminal approval URL")
|
|
71
|
+
code = parse_qs(parsed.query).get("code", [""])[0]
|
|
72
|
+
if not isinstance(code, str) or not 4 <= len(code) <= 32:
|
|
73
|
+
raise ValueError("VAYU returned an invalid terminal approval URL")
|
|
74
|
+
|
|
75
|
+
expected_origin = OFFICIAL_API_ORIGINS.get(normalized_api_url)
|
|
76
|
+
received_origin = f"{parsed.scheme}://{parsed.netloc.lower()}"
|
|
77
|
+
if expected_origin:
|
|
78
|
+
if received_origin != expected_origin:
|
|
79
|
+
raise ValueError("VAYU returned an unexpected terminal approval URL")
|
|
80
|
+
elif parsed.hostname not in {"localhost", "127.0.0.1", "::1"}:
|
|
81
|
+
raise ValueError("A local VAYU API must return a loopback terminal approval URL")
|
|
82
|
+
return value
|
|
83
|
+
|
|
84
|
+
|
|
85
|
+
def _safe_error(status_code: int, payload: object) -> tuple[str | None, str]:
|
|
86
|
+
"""Use protocol codes, not arbitrary server text, in terminal errors."""
|
|
87
|
+
error_code = None
|
|
88
|
+
if isinstance(payload, dict):
|
|
89
|
+
detail = payload.get("detail")
|
|
90
|
+
if isinstance(detail, dict) and isinstance(detail.get("error"), str):
|
|
91
|
+
error_code = detail["error"]
|
|
92
|
+
|
|
93
|
+
if error_code == "authorization_pending":
|
|
94
|
+
return error_code, "Approval is still pending."
|
|
95
|
+
if error_code == "slow_down":
|
|
96
|
+
return error_code, "Waiting before checking authorization again."
|
|
97
|
+
if error_code == "invalid_or_expired_code":
|
|
98
|
+
return error_code, "The terminal code is invalid or expired. Start login again."
|
|
99
|
+
if error_code == "invalid_grant":
|
|
100
|
+
return error_code, "Your CLI session is invalid or expired. Sign in again."
|
|
101
|
+
if error_code == "redaction_required":
|
|
102
|
+
return error_code, "Sensitive credential-shaped content was found. Remove it before diagnosing."
|
|
103
|
+
if error_code == "duplicate_analysis_in_progress":
|
|
104
|
+
return error_code, "This exact diagnosis is already running. Wait for it to finish."
|
|
105
|
+
if status_code == 401:
|
|
106
|
+
return error_code, "Your CLI session is no longer valid. Sign in again."
|
|
107
|
+
if status_code == 403:
|
|
108
|
+
return error_code, "This account cannot use that VAYU action. Check your verification and plan."
|
|
109
|
+
if status_code == 429:
|
|
110
|
+
return error_code, "Your VAYU allowance is exhausted. Review plans or wait for the next billing period."
|
|
111
|
+
if status_code == 409:
|
|
112
|
+
return error_code, "VAYU is already processing this request. Try again shortly."
|
|
113
|
+
if status_code >= 500:
|
|
114
|
+
return error_code, "VAYU is temporarily unavailable. Try again shortly."
|
|
115
|
+
return error_code, "VAYU could not process this request. Check the command and try again."
|
|
116
|
+
|
|
117
|
+
|
|
118
|
+
def post_json(
|
|
119
|
+
api_url: str,
|
|
120
|
+
path: str,
|
|
121
|
+
body: dict[str, Any],
|
|
122
|
+
*,
|
|
123
|
+
bearer_token: str | None = None,
|
|
124
|
+
) -> dict[str, Any]:
|
|
125
|
+
"""Make one JSON request without emitting a bearer credential or payload."""
|
|
126
|
+
base_url = normalize_api_url(api_url)
|
|
127
|
+
headers = {
|
|
128
|
+
"Accept": "application/json",
|
|
129
|
+
"Content-Type": "application/json",
|
|
130
|
+
"User-Agent": "vayu-cli/0.1",
|
|
131
|
+
}
|
|
132
|
+
if bearer_token:
|
|
133
|
+
headers["Authorization"] = f"Bearer {bearer_token}"
|
|
134
|
+
request = Request(
|
|
135
|
+
f"{base_url}{path}",
|
|
136
|
+
data=json.dumps(body).encode("utf-8"),
|
|
137
|
+
headers=headers,
|
|
138
|
+
method="POST",
|
|
139
|
+
)
|
|
140
|
+
try:
|
|
141
|
+
with _NO_REDIRECT_OPENER.open(request, timeout=REQUEST_TIMEOUT_SECONDS) as response:
|
|
142
|
+
decoded = json.loads(response.read().decode("utf-8"))
|
|
143
|
+
except HTTPError as error:
|
|
144
|
+
try:
|
|
145
|
+
decoded = json.loads(error.read().decode("utf-8"))
|
|
146
|
+
except (UnicodeDecodeError, json.JSONDecodeError):
|
|
147
|
+
decoded = None
|
|
148
|
+
error_code, message = _safe_error(error.code, decoded)
|
|
149
|
+
raise ApiError(error.code, error_code, message) from None
|
|
150
|
+
except (URLError, TimeoutError, OSError):
|
|
151
|
+
raise ApiError(None, None, "Could not reach VAYU. Check your connection and API URL.") from None
|
|
152
|
+
except (UnicodeDecodeError, json.JSONDecodeError):
|
|
153
|
+
raise ApiError(None, None, "VAYU returned an invalid response. Try again shortly.") from None
|
|
154
|
+
|
|
155
|
+
if not isinstance(decoded, dict):
|
|
156
|
+
raise ApiError(None, None, "VAYU returned an invalid response. Try again shortly.")
|
|
157
|
+
return decoded
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
"""Credential storage that refuses plaintext fallbacks."""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
import json
|
|
6
|
+
from dataclasses import dataclass
|
|
7
|
+
|
|
8
|
+
from .api import normalize_api_url
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
SERVICE_NAME = "com.vayufix.cli"
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
class CredentialStoreError(RuntimeError):
|
|
15
|
+
pass
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
@dataclass(frozen=True)
|
|
19
|
+
class Credentials:
|
|
20
|
+
api_url: str
|
|
21
|
+
refresh_token: str
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
class KeyringCredentialStore:
|
|
25
|
+
"""Use the operating system credential store; never write token files."""
|
|
26
|
+
|
|
27
|
+
@staticmethod
|
|
28
|
+
def _keyring():
|
|
29
|
+
try:
|
|
30
|
+
import keyring
|
|
31
|
+
from keyring.errors import KeyringError
|
|
32
|
+
except ImportError as error:
|
|
33
|
+
raise CredentialStoreError(
|
|
34
|
+
"Secure credential storage is unavailable. Reinstall VAYU CLI with its keyring dependency."
|
|
35
|
+
) from error
|
|
36
|
+
return keyring, KeyringError
|
|
37
|
+
|
|
38
|
+
@staticmethod
|
|
39
|
+
def _account(api_url: str) -> str:
|
|
40
|
+
return f"profile:{normalize_api_url(api_url)}"
|
|
41
|
+
|
|
42
|
+
def save(self, credentials: Credentials) -> None:
|
|
43
|
+
keyring, keyring_error = self._keyring()
|
|
44
|
+
try:
|
|
45
|
+
keyring.set_password(
|
|
46
|
+
SERVICE_NAME,
|
|
47
|
+
self._account(credentials.api_url),
|
|
48
|
+
json.dumps({"refresh_token": credentials.refresh_token}),
|
|
49
|
+
)
|
|
50
|
+
except keyring_error as error:
|
|
51
|
+
raise CredentialStoreError(
|
|
52
|
+
"VAYU CLI could not store its session in the operating system credential store."
|
|
53
|
+
) from error
|
|
54
|
+
|
|
55
|
+
def load(self, api_url: str) -> Credentials | None:
|
|
56
|
+
keyring, keyring_error = self._keyring()
|
|
57
|
+
normalized = normalize_api_url(api_url)
|
|
58
|
+
try:
|
|
59
|
+
raw = keyring.get_password(SERVICE_NAME, self._account(normalized))
|
|
60
|
+
except keyring_error as error:
|
|
61
|
+
raise CredentialStoreError(
|
|
62
|
+
"VAYU CLI could not read the operating system credential store."
|
|
63
|
+
) from error
|
|
64
|
+
if not raw:
|
|
65
|
+
return None
|
|
66
|
+
try:
|
|
67
|
+
value = json.loads(raw)
|
|
68
|
+
refresh_token = value["refresh_token"]
|
|
69
|
+
except (KeyError, TypeError, json.JSONDecodeError):
|
|
70
|
+
raise CredentialStoreError("The stored VAYU CLI session is invalid. Run `vayu logout` and sign in again.")
|
|
71
|
+
if not isinstance(refresh_token, str) or len(refresh_token) < 32:
|
|
72
|
+
raise CredentialStoreError("The stored VAYU CLI session is invalid. Run `vayu logout` and sign in again.")
|
|
73
|
+
return Credentials(api_url=normalized, refresh_token=refresh_token)
|
|
74
|
+
|
|
75
|
+
def clear(self, api_url: str) -> None:
|
|
76
|
+
keyring, keyring_error = self._keyring()
|
|
77
|
+
try:
|
|
78
|
+
keyring.delete_password(SERVICE_NAME, self._account(api_url))
|
|
79
|
+
except keyring_error as error:
|
|
80
|
+
# A missing entry is already logged out. Keyring backends vary in
|
|
81
|
+
# their exception hierarchy, so avoid depending on one backend.
|
|
82
|
+
if "not found" not in str(error).lower():
|
|
83
|
+
raise CredentialStoreError(
|
|
84
|
+
"VAYU CLI could not remove the local session from the operating system credential store."
|
|
85
|
+
) from error
|
|
@@ -0,0 +1,207 @@
|
|
|
1
|
+
"""Command entry point for the installable VAYU CLI."""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
import argparse
|
|
6
|
+
import json
|
|
7
|
+
import sys
|
|
8
|
+
import webbrowser
|
|
9
|
+
from pathlib import Path
|
|
10
|
+
from typing import Sequence
|
|
11
|
+
|
|
12
|
+
from .api import ApiError, DEFAULT_API_URL, normalize_api_url, validate_verification_uri
|
|
13
|
+
from .credentials import CredentialStoreError, Credentials, KeyringCredentialStore
|
|
14
|
+
from .redaction import redact
|
|
15
|
+
from .service import begin_login, diagnose, finish_login, refresh_access_token, revoke
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
VALID_STACKS = ("airflow", "spark", "pyspark", "kafka", "sql", "postgresql", "redshift", "python")
|
|
19
|
+
MAX_INPUT_CHARS = 50_000
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
def _api_url(args: argparse.Namespace) -> str:
|
|
23
|
+
return normalize_api_url(args.api_url)
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
def _read_text(value: str | None, path: str | None, label: str) -> str:
|
|
27
|
+
if bool(value) == bool(path):
|
|
28
|
+
raise ValueError(f"provide exactly one of --{label} or --{label}-file")
|
|
29
|
+
if path:
|
|
30
|
+
try:
|
|
31
|
+
result = Path(path).read_text(encoding="utf-8")
|
|
32
|
+
except (OSError, UnicodeDecodeError) as error:
|
|
33
|
+
raise ValueError(f"could not read {label} file") from error
|
|
34
|
+
else:
|
|
35
|
+
result = value or ""
|
|
36
|
+
if len(result) > MAX_INPUT_CHARS:
|
|
37
|
+
raise ValueError(f"{label} is longer than {MAX_INPUT_CHARS:,} characters")
|
|
38
|
+
return result
|
|
39
|
+
|
|
40
|
+
|
|
41
|
+
def _load_session(store: KeyringCredentialStore, api_url: str) -> Credentials:
|
|
42
|
+
credentials = store.load(api_url)
|
|
43
|
+
if not credentials:
|
|
44
|
+
raise CredentialStoreError("You are not signed in. Run `vayu login` first.")
|
|
45
|
+
return credentials
|
|
46
|
+
|
|
47
|
+
|
|
48
|
+
def command_login(args: argparse.Namespace) -> int:
|
|
49
|
+
api_url = _api_url(args)
|
|
50
|
+
authorization = begin_login(api_url)
|
|
51
|
+
device_code = authorization.get("device_code")
|
|
52
|
+
user_code = authorization.get("user_code")
|
|
53
|
+
verification_uri = authorization.get("verification_uri_complete")
|
|
54
|
+
expires_in = authorization.get("expires_in")
|
|
55
|
+
interval = authorization.get("interval")
|
|
56
|
+
if not all(isinstance(value, str) for value in (device_code, user_code, verification_uri)) or not isinstance(expires_in, int) or not isinstance(interval, int):
|
|
57
|
+
raise ApiError(None, None, "VAYU returned an invalid sign-in response. Try again.")
|
|
58
|
+
|
|
59
|
+
try:
|
|
60
|
+
verification_uri = validate_verification_uri(api_url, verification_uri if isinstance(verification_uri, str) else "")
|
|
61
|
+
except ValueError as error:
|
|
62
|
+
raise ApiError(None, None, str(error)) from None
|
|
63
|
+
|
|
64
|
+
print("Open this page to approve the terminal:")
|
|
65
|
+
print(verification_uri)
|
|
66
|
+
print(f"Terminal code: {user_code}")
|
|
67
|
+
print("Your password and browser session stay in the browser.")
|
|
68
|
+
if not args.no_browser:
|
|
69
|
+
webbrowser.open(verification_uri, new=2)
|
|
70
|
+
|
|
71
|
+
credentials = finish_login(api_url, device_code, interval, expires_in)
|
|
72
|
+
KeyringCredentialStore().save(credentials)
|
|
73
|
+
print("VAYU CLI is connected securely.")
|
|
74
|
+
return 0
|
|
75
|
+
|
|
76
|
+
|
|
77
|
+
def command_logout(args: argparse.Namespace) -> int:
|
|
78
|
+
api_url = _api_url(args)
|
|
79
|
+
store = KeyringCredentialStore()
|
|
80
|
+
credentials = store.load(api_url)
|
|
81
|
+
if not credentials:
|
|
82
|
+
print("VAYU CLI is already signed out.")
|
|
83
|
+
return 0
|
|
84
|
+
remote_error: ApiError | None = None
|
|
85
|
+
try:
|
|
86
|
+
revoke(credentials)
|
|
87
|
+
except ApiError as error:
|
|
88
|
+
remote_error = error
|
|
89
|
+
finally:
|
|
90
|
+
# Delete local authority even if the network is unavailable.
|
|
91
|
+
store.clear(api_url)
|
|
92
|
+
if remote_error:
|
|
93
|
+
print("Local session removed. VAYU could not confirm remote revocation; it will expire automatically.", file=sys.stderr)
|
|
94
|
+
return 1
|
|
95
|
+
print("VAYU CLI is signed out and the terminal session was revoked.")
|
|
96
|
+
return 0
|
|
97
|
+
|
|
98
|
+
|
|
99
|
+
def command_redact(args: argparse.Namespace) -> int:
|
|
100
|
+
try:
|
|
101
|
+
input_text = Path(args.input).read_text(encoding="utf-8")
|
|
102
|
+
except (OSError, UnicodeDecodeError):
|
|
103
|
+
print("Could not read the input file as UTF-8 text.", file=sys.stderr)
|
|
104
|
+
return 2
|
|
105
|
+
safe_text, kinds = redact(input_text)
|
|
106
|
+
if args.output:
|
|
107
|
+
output = Path(args.output)
|
|
108
|
+
if output.resolve() == Path(args.input).resolve():
|
|
109
|
+
print("Choose a different output file; VAYU CLI never overwrites raw input.", file=sys.stderr)
|
|
110
|
+
return 2
|
|
111
|
+
try:
|
|
112
|
+
output.write_text(safe_text, encoding="utf-8")
|
|
113
|
+
except OSError:
|
|
114
|
+
print("Could not write the redacted output file.", file=sys.stderr)
|
|
115
|
+
return 2
|
|
116
|
+
print("Redacted copy written locally" + (f" ({', '.join(kinds)})." if kinds else "."))
|
|
117
|
+
else:
|
|
118
|
+
sys.stdout.write(safe_text)
|
|
119
|
+
if safe_text and not safe_text.endswith("\n"):
|
|
120
|
+
sys.stdout.write("\n")
|
|
121
|
+
return 0
|
|
122
|
+
|
|
123
|
+
|
|
124
|
+
def command_diagnose(args: argparse.Namespace) -> int:
|
|
125
|
+
logs = _read_text(args.logs, args.logs_file, "logs")
|
|
126
|
+
code = _read_text(args.code, args.code_file, "code") if args.code or args.code_file else ""
|
|
127
|
+
if not logs.strip():
|
|
128
|
+
raise ValueError("logs must not be empty")
|
|
129
|
+
|
|
130
|
+
_, secret_kinds = redact(f"{code}\n{logs}")
|
|
131
|
+
if secret_kinds:
|
|
132
|
+
print(
|
|
133
|
+
"Sensitive credential-shaped content was found locally. Run `vayu redact INPUT --output SAFE_COPY` first; nothing was uploaded.",
|
|
134
|
+
file=sys.stderr,
|
|
135
|
+
)
|
|
136
|
+
return 2
|
|
137
|
+
|
|
138
|
+
api_url = _api_url(args)
|
|
139
|
+
store = KeyringCredentialStore()
|
|
140
|
+
credentials = _load_session(store, api_url)
|
|
141
|
+
access_token, rotated = refresh_access_token(credentials)
|
|
142
|
+
store.save(rotated)
|
|
143
|
+
response = diagnose(
|
|
144
|
+
rotated,
|
|
145
|
+
access_token,
|
|
146
|
+
{"code": code, "logs": logs, "stack": args.stack, "version": args.version},
|
|
147
|
+
)
|
|
148
|
+
if args.json:
|
|
149
|
+
print(json.dumps(response, indent=2, ensure_ascii=False))
|
|
150
|
+
return 0
|
|
151
|
+
print("VAYU diagnosis\n")
|
|
152
|
+
for label, field in (
|
|
153
|
+
("Likely root cause", "root_cause"),
|
|
154
|
+
("Why it failed", "why"),
|
|
155
|
+
("Suggested change", "fix_after"),
|
|
156
|
+
("Prevention", "prevention"),
|
|
157
|
+
):
|
|
158
|
+
value = response.get(field)
|
|
159
|
+
if isinstance(value, str) and value.strip():
|
|
160
|
+
print(f"{label}:\n{value.strip()}\n")
|
|
161
|
+
return 0
|
|
162
|
+
|
|
163
|
+
|
|
164
|
+
def build_parser() -> argparse.ArgumentParser:
|
|
165
|
+
parser = argparse.ArgumentParser(
|
|
166
|
+
prog="vayu",
|
|
167
|
+
description="VAYU CLI: local privacy tools and account-backed diagnoses.",
|
|
168
|
+
)
|
|
169
|
+
parser.add_argument("--api-url", default=DEFAULT_API_URL, help="VAYU API URL (HTTPS; loopback HTTP is allowed for local development)")
|
|
170
|
+
subcommands = parser.add_subparsers(dest="command", required=True)
|
|
171
|
+
|
|
172
|
+
login = subcommands.add_parser("login", help="Connect this terminal through your browser")
|
|
173
|
+
login.add_argument("--no-browser", action="store_true", help="Print the approval URL without opening a browser")
|
|
174
|
+
login.set_defaults(handler=command_login)
|
|
175
|
+
|
|
176
|
+
logout = subcommands.add_parser("logout", help="Remove and revoke this terminal session")
|
|
177
|
+
logout.set_defaults(handler=command_logout)
|
|
178
|
+
|
|
179
|
+
redact_command = subcommands.add_parser("redact", help="Mask high-confidence secret shapes locally")
|
|
180
|
+
redact_command.add_argument("input", help="UTF-8 text file to redact")
|
|
181
|
+
redact_command.add_argument("--output", help="write a redacted copy instead of stdout")
|
|
182
|
+
redact_command.set_defaults(handler=command_redact)
|
|
183
|
+
|
|
184
|
+
diagnose_command = subcommands.add_parser("diagnose", help="Run an account-backed VAYU diagnosis")
|
|
185
|
+
diagnose_command.add_argument("--stack", choices=VALID_STACKS, required=True)
|
|
186
|
+
diagnose_command.add_argument("--logs", help="error log text")
|
|
187
|
+
diagnose_command.add_argument("--logs-file", help="UTF-8 file containing error logs")
|
|
188
|
+
diagnose_command.add_argument("--code", help="relevant source code")
|
|
189
|
+
diagnose_command.add_argument("--code-file", help="UTF-8 file containing relevant source code")
|
|
190
|
+
diagnose_command.add_argument("--version", help="optional stack version")
|
|
191
|
+
diagnose_command.add_argument("--json", action="store_true", help="print the full structured diagnosis")
|
|
192
|
+
diagnose_command.set_defaults(handler=command_diagnose)
|
|
193
|
+
return parser
|
|
194
|
+
|
|
195
|
+
|
|
196
|
+
def main(argv: Sequence[str] | None = None) -> int:
|
|
197
|
+
parser = build_parser()
|
|
198
|
+
args = parser.parse_args(argv)
|
|
199
|
+
try:
|
|
200
|
+
return args.handler(args)
|
|
201
|
+
except (ApiError, CredentialStoreError, ValueError) as error:
|
|
202
|
+
print(str(error), file=sys.stderr)
|
|
203
|
+
return 2
|
|
204
|
+
|
|
205
|
+
|
|
206
|
+
if __name__ == "__main__":
|
|
207
|
+
raise SystemExit(main())
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
"""A local, conservative credential mask used before any VAYU upload."""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
import re
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
# These high-confidence shapes intentionally mirror VAYU's server-side
|
|
9
|
+
# protection. The server remains authoritative and runs its own scan again.
|
|
10
|
+
HIGH_CONFIDENCE_PATTERNS: dict[str, tuple[str, ...]] = {
|
|
11
|
+
"aws_access_key_id": (r"AKIA[0-9A-Z]{16}", r"\bASIA[0-9A-Z]{16}\b"),
|
|
12
|
+
"aws_secret_access_key": (r"(?i)aws_secret_access_key\s*[=:]\s*['\"]?[A-Za-z0-9/+=]{40}['\"]?",),
|
|
13
|
+
"private_key_block": (r"-----BEGIN\s+(RSA|EC|DSA|OPENSSH|ENCRYPTED|)\s*PRIVATE KEY-----",),
|
|
14
|
+
"bearer_token": (r"Bearer\s+[A-Za-z0-9\-_\.]{20,}",),
|
|
15
|
+
"jwt_token": (r"eyJ[A-Za-z0-9_-]+\.[A-Za-z0-9_-]+\.[A-Za-z0-9_-]+",),
|
|
16
|
+
"db_connection_string_with_credentials": (r"(postgres(?:ql)?|mysql|mongodb(?:\+srv)?|redis)://[^:\s]+:[^@\s]+@[^\s'\"]+",),
|
|
17
|
+
"github_token": (r"\bgh[pousr]_[A-Za-z0-9]{36,}\b",),
|
|
18
|
+
"slack_token": (r"\bxox[abprs]-[A-Za-z0-9-]{10,}",),
|
|
19
|
+
"sk_style_api_key": (r"(?<![A-Za-z0-9_-])sk-(?=[A-Za-z0-9_-]*\d)[A-Za-z0-9_-]{32,}",),
|
|
20
|
+
"stripe_live_secret_key": (r"(?<![A-Za-z0-9_-])sk_live_[A-Za-z0-9]{24,}\b",),
|
|
21
|
+
"google_api_key": (r"\bAIza[0-9A-Za-z_-]{35}\b",),
|
|
22
|
+
"twilio_api_key": (r"\bSK[0-9a-fA-F]{32}\b",),
|
|
23
|
+
"twilio_auth_token": (r"(?i)twilio(?:_|\s+)?auth(?:_|\s+)?token\s*[=:]\s*['\"]?[0-9a-f]{32}['\"]?",),
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
def redact(text: str) -> tuple[str, list[str]]:
|
|
28
|
+
"""Mask high-confidence credential values without a network request."""
|
|
29
|
+
result = text
|
|
30
|
+
kinds: list[str] = []
|
|
31
|
+
for kind, patterns in HIGH_CONFIDENCE_PATTERNS.items():
|
|
32
|
+
for pattern in patterns:
|
|
33
|
+
result, count = re.subn(pattern, f"[REDACTED:{kind}]", result)
|
|
34
|
+
if count and kind not in kinds:
|
|
35
|
+
kinds.append(kind)
|
|
36
|
+
return result, kinds
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
"""Protocol implementation for browser login and managed diagnosis."""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
import time
|
|
6
|
+
from collections.abc import Callable
|
|
7
|
+
from typing import Any
|
|
8
|
+
|
|
9
|
+
from .api import ApiError, post_json
|
|
10
|
+
from .credentials import Credentials
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
def begin_login(api_url: str) -> dict[str, Any]:
|
|
14
|
+
return post_json(api_url, "/api/v1/cli/device/authorize", {})
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
def finish_login(
|
|
18
|
+
api_url: str,
|
|
19
|
+
device_code: str,
|
|
20
|
+
interval_seconds: int,
|
|
21
|
+
expires_in_seconds: int,
|
|
22
|
+
*,
|
|
23
|
+
sleep: Callable[[float], None] = time.sleep,
|
|
24
|
+
monotonic: Callable[[], float] = time.monotonic,
|
|
25
|
+
) -> Credentials:
|
|
26
|
+
"""Poll only at the server-specified cadence and consume a code once."""
|
|
27
|
+
deadline = monotonic() + expires_in_seconds
|
|
28
|
+
interval = max(1, interval_seconds)
|
|
29
|
+
while monotonic() < deadline:
|
|
30
|
+
try:
|
|
31
|
+
token = post_json(api_url, "/api/v1/cli/device/token", {"device_code": device_code})
|
|
32
|
+
refresh_token = token.get("refresh_token")
|
|
33
|
+
if not isinstance(refresh_token, str) or len(refresh_token) < 32:
|
|
34
|
+
raise ApiError(None, None, "VAYU returned an invalid sign-in response. Start login again.")
|
|
35
|
+
return Credentials(api_url=api_url, refresh_token=refresh_token)
|
|
36
|
+
except ApiError as error:
|
|
37
|
+
if error.error_code == "authorization_pending":
|
|
38
|
+
sleep(interval)
|
|
39
|
+
continue
|
|
40
|
+
if error.error_code == "slow_down":
|
|
41
|
+
interval = min(interval + 2, 30)
|
|
42
|
+
sleep(interval)
|
|
43
|
+
continue
|
|
44
|
+
raise
|
|
45
|
+
raise ApiError(None, "expired", "The terminal code expired. Start login again.")
|
|
46
|
+
|
|
47
|
+
|
|
48
|
+
def refresh_access_token(credentials: Credentials) -> tuple[str, Credentials]:
|
|
49
|
+
"""Rotate the stored refresh token before every managed command."""
|
|
50
|
+
token = post_json(
|
|
51
|
+
credentials.api_url,
|
|
52
|
+
"/api/v1/cli/token/refresh",
|
|
53
|
+
{"refresh_token": credentials.refresh_token},
|
|
54
|
+
)
|
|
55
|
+
access_token = token.get("access_token")
|
|
56
|
+
refresh_token = token.get("refresh_token")
|
|
57
|
+
if not isinstance(access_token, str) or not isinstance(refresh_token, str):
|
|
58
|
+
raise ApiError(None, None, "VAYU returned an invalid session response. Sign in again.")
|
|
59
|
+
return access_token, Credentials(api_url=credentials.api_url, refresh_token=refresh_token)
|
|
60
|
+
|
|
61
|
+
|
|
62
|
+
def revoke(credentials: Credentials) -> None:
|
|
63
|
+
post_json(credentials.api_url, "/api/v1/cli/token/revoke", {"refresh_token": credentials.refresh_token})
|
|
64
|
+
|
|
65
|
+
|
|
66
|
+
def diagnose(credentials: Credentials, access_token: str, payload: dict[str, str | None]) -> dict[str, Any]:
|
|
67
|
+
return post_json(
|
|
68
|
+
credentials.api_url,
|
|
69
|
+
"/api/v1/cli/diagnose",
|
|
70
|
+
payload,
|
|
71
|
+
bearer_token=access_token,
|
|
72
|
+
)
|
|
@@ -0,0 +1,124 @@
|
|
|
1
|
+
import io
|
|
2
|
+
import json
|
|
3
|
+
import unittest
|
|
4
|
+
from contextlib import redirect_stderr, redirect_stdout
|
|
5
|
+
from unittest.mock import patch
|
|
6
|
+
from urllib.request import Request
|
|
7
|
+
|
|
8
|
+
from vayu_cli.api import ApiError, _RejectRedirects, normalize_api_url, validate_verification_uri
|
|
9
|
+
from vayu_cli.credentials import Credentials
|
|
10
|
+
from vayu_cli.main import main
|
|
11
|
+
from vayu_cli.redaction import redact
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
class MemoryStore:
|
|
15
|
+
value = None
|
|
16
|
+
|
|
17
|
+
def save(self, credentials):
|
|
18
|
+
self.value = credentials
|
|
19
|
+
|
|
20
|
+
def load(self, _api_url):
|
|
21
|
+
return self.value
|
|
22
|
+
|
|
23
|
+
def clear(self, _api_url):
|
|
24
|
+
self.value = None
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
class CliTest(unittest.TestCase):
|
|
28
|
+
def test_http_transport_never_follows_redirects(self):
|
|
29
|
+
request = Request("https://api.vayufix.com/api/v1/cli/diagnose")
|
|
30
|
+
redirect = _RejectRedirects()
|
|
31
|
+
self.assertIsNone(
|
|
32
|
+
redirect.redirect_request(
|
|
33
|
+
request,
|
|
34
|
+
None,
|
|
35
|
+
307,
|
|
36
|
+
"Temporary Redirect",
|
|
37
|
+
{},
|
|
38
|
+
"https://attacker.example/collect",
|
|
39
|
+
)
|
|
40
|
+
)
|
|
41
|
+
|
|
42
|
+
def test_external_api_requires_https(self):
|
|
43
|
+
self.assertEqual(normalize_api_url("https://API.VAYUFIX.COM/"), "https://api.vayufix.com")
|
|
44
|
+
with self.assertRaises(ValueError):
|
|
45
|
+
normalize_api_url("http://api.vayufix.com")
|
|
46
|
+
with self.assertRaises(ValueError):
|
|
47
|
+
normalize_api_url("https://api.vayufix.com/not-allowed")
|
|
48
|
+
with self.assertRaises(ValueError):
|
|
49
|
+
normalize_api_url("https://not-vayu.example")
|
|
50
|
+
|
|
51
|
+
def test_browser_approval_url_must_match_the_selected_vayu_environment(self):
|
|
52
|
+
self.assertEqual(
|
|
53
|
+
validate_verification_uri(
|
|
54
|
+
"https://api.vayufix.com", "https://vayufix.com/cli/activate?code=ABCD-EFGH",
|
|
55
|
+
),
|
|
56
|
+
"https://vayufix.com/cli/activate?code=ABCD-EFGH",
|
|
57
|
+
)
|
|
58
|
+
with self.assertRaises(ValueError):
|
|
59
|
+
validate_verification_uri(
|
|
60
|
+
"https://api.vayufix.com", "https://attacker.example/cli/activate?code=ABCD-EFGH",
|
|
61
|
+
)
|
|
62
|
+
|
|
63
|
+
def test_local_redaction_never_contacts_vayu(self):
|
|
64
|
+
value = "token = AKIA1234567890ABCDEF\nhello\n"
|
|
65
|
+
safe, kinds = redact(value)
|
|
66
|
+
self.assertNotIn("AKIA1234567890ABCDEF", safe)
|
|
67
|
+
self.assertIn("aws_access_key_id", kinds)
|
|
68
|
+
|
|
69
|
+
def test_diagnose_blocks_secrets_before_session_or_network_use(self):
|
|
70
|
+
stderr = io.StringIO()
|
|
71
|
+
with patch("vayu_cli.main.KeyringCredentialStore") as store:
|
|
72
|
+
with redirect_stderr(stderr):
|
|
73
|
+
status = main([
|
|
74
|
+
"diagnose", "--stack", "python", "--logs", "AKIA1234567890ABCDEF",
|
|
75
|
+
])
|
|
76
|
+
self.assertEqual(status, 2)
|
|
77
|
+
self.assertIn("nothing was uploaded", stderr.getvalue())
|
|
78
|
+
store.assert_not_called()
|
|
79
|
+
|
|
80
|
+
def test_diagnose_refreshes_rotating_session_and_uses_managed_endpoint(self):
|
|
81
|
+
store = MemoryStore()
|
|
82
|
+
store.save(Credentials("https://api.vayufix.com", "r" * 64))
|
|
83
|
+
response = {"root_cause": "Timeout", "why": "The task ran too long.", "fix_after": "Increase timeout.", "prevention": "Monitor duration."}
|
|
84
|
+
output = io.StringIO()
|
|
85
|
+
with patch("vayu_cli.main.KeyringCredentialStore", return_value=store):
|
|
86
|
+
with patch("vayu_cli.main.refresh_access_token", return_value=("access", Credentials("https://api.vayufix.com", "n" * 64))) as refresh:
|
|
87
|
+
with patch("vayu_cli.main.diagnose", return_value=response) as diagnose:
|
|
88
|
+
with redirect_stdout(output):
|
|
89
|
+
status = main([
|
|
90
|
+
"diagnose", "--stack", "python", "--logs", "TimeoutError: sample",
|
|
91
|
+
])
|
|
92
|
+
self.assertEqual(status, 0)
|
|
93
|
+
refresh.assert_called_once()
|
|
94
|
+
diagnose.assert_called_once()
|
|
95
|
+
self.assertEqual(store.value.refresh_token, "n" * 64)
|
|
96
|
+
self.assertIn("Likely root cause", output.getvalue())
|
|
97
|
+
|
|
98
|
+
def test_logout_deletes_local_session_when_remote_revoke_is_unavailable(self):
|
|
99
|
+
store = MemoryStore()
|
|
100
|
+
store.save(Credentials("https://api.vayufix.com", "r" * 64))
|
|
101
|
+
stderr = io.StringIO()
|
|
102
|
+
with patch("vayu_cli.main.KeyringCredentialStore", return_value=store):
|
|
103
|
+
with patch("vayu_cli.main.revoke", side_effect=ApiError(None, None, "offline")):
|
|
104
|
+
with redirect_stderr(stderr):
|
|
105
|
+
status = main(["logout"])
|
|
106
|
+
self.assertEqual(status, 1)
|
|
107
|
+
self.assertIsNone(store.value)
|
|
108
|
+
self.assertIn("Local session removed", stderr.getvalue())
|
|
109
|
+
|
|
110
|
+
def test_json_output_is_structured(self):
|
|
111
|
+
store = MemoryStore()
|
|
112
|
+
store.save(Credentials("https://api.vayufix.com", "r" * 64))
|
|
113
|
+
output = io.StringIO()
|
|
114
|
+
with patch("vayu_cli.main.KeyringCredentialStore", return_value=store):
|
|
115
|
+
with patch("vayu_cli.main.refresh_access_token", return_value=("access", store.value)):
|
|
116
|
+
with patch("vayu_cli.main.diagnose", return_value={"root_cause": "Timeout"}):
|
|
117
|
+
with redirect_stdout(output):
|
|
118
|
+
status = main(["diagnose", "--stack", "python", "--logs", "TimeoutError", "--json"])
|
|
119
|
+
self.assertEqual(status, 0)
|
|
120
|
+
self.assertEqual(json.loads(output.getvalue())["root_cause"], "Timeout")
|
|
121
|
+
|
|
122
|
+
|
|
123
|
+
if __name__ == "__main__":
|
|
124
|
+
unittest.main()
|