genalpha_test_cli 0.1.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.
- genalpha_test_cli/__init__.py +1 -0
- genalpha_test_cli/_graph.json +1216 -0
- genalpha_test_cli/cli.py +756 -0
- genalpha_test_cli/client.py +90 -0
- genalpha_test_cli-0.1.0.dist-info/METADATA +8 -0
- genalpha_test_cli-0.1.0.dist-info/RECORD +8 -0
- genalpha_test_cli-0.1.0.dist-info/WHEEL +4 -0
- genalpha_test_cli-0.1.0.dist-info/entry_points.txt +2 -0
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
"""HTTP client for genalpha_test_cli. Auto-generated by genalphacli."""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
import json
|
|
6
|
+
import os
|
|
7
|
+
import sys
|
|
8
|
+
from typing import Any
|
|
9
|
+
|
|
10
|
+
import requests
|
|
11
|
+
|
|
12
|
+
BASE_URL = os.environ.get("GENALPHA_TEST_CLI_BASE_URL", "https://api.example.com")
|
|
13
|
+
AUTH_TYPE = "bearer"
|
|
14
|
+
AUTH_ENV_VAR = "GENALPHA_TEST_CLI_TOKEN"
|
|
15
|
+
TIMEOUT = 30
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
class ApiError(Exception):
|
|
19
|
+
"""Raised when an API call fails."""
|
|
20
|
+
|
|
21
|
+
def __init__(self, status_code: int, message: str, raw_body: str = "") -> None:
|
|
22
|
+
self.status_code = status_code
|
|
23
|
+
self.message = message
|
|
24
|
+
self.raw_body = raw_body
|
|
25
|
+
super().__init__(message)
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
def api_call(
|
|
29
|
+
method: str,
|
|
30
|
+
path: str,
|
|
31
|
+
params: dict[str, Any] | None = None,
|
|
32
|
+
json_data: dict[str, Any] | None = None,
|
|
33
|
+
) -> Any:
|
|
34
|
+
"""Make an HTTP request to the API."""
|
|
35
|
+
url = BASE_URL.rstrip("/") + path
|
|
36
|
+
headers = _build_headers()
|
|
37
|
+
|
|
38
|
+
response = requests.request(
|
|
39
|
+
method,
|
|
40
|
+
url,
|
|
41
|
+
params=params,
|
|
42
|
+
json=json_data,
|
|
43
|
+
headers=headers,
|
|
44
|
+
timeout=TIMEOUT,
|
|
45
|
+
verify=True,
|
|
46
|
+
)
|
|
47
|
+
|
|
48
|
+
if not response.ok:
|
|
49
|
+
_raise_api_error(response)
|
|
50
|
+
|
|
51
|
+
if not response.content:
|
|
52
|
+
return {}
|
|
53
|
+
return response.json()
|
|
54
|
+
|
|
55
|
+
|
|
56
|
+
def _build_headers() -> dict[str, str]:
|
|
57
|
+
"""Build request headers with auth token."""
|
|
58
|
+
headers: dict[str, str] = {}
|
|
59
|
+
token = os.environ.get(AUTH_ENV_VAR, "")
|
|
60
|
+
|
|
61
|
+
if token and ("\r" in token or "\n" in token or "\x00" in token):
|
|
62
|
+
print(f"Error: {AUTH_ENV_VAR} contains invalid characters", file=sys.stderr)
|
|
63
|
+
sys.exit(1)
|
|
64
|
+
|
|
65
|
+
if token:
|
|
66
|
+
if AUTH_TYPE == "bearer":
|
|
67
|
+
headers["Authorization"] = f"Bearer {token}"
|
|
68
|
+
elif AUTH_TYPE == "api_key":
|
|
69
|
+
headers["X-API-Key"] = token
|
|
70
|
+
return headers
|
|
71
|
+
|
|
72
|
+
|
|
73
|
+
def _raise_api_error(response: requests.Response) -> None:
|
|
74
|
+
"""Raise an ApiError with a friendly message."""
|
|
75
|
+
messages = {
|
|
76
|
+
401: f"Authentication failed. Set {AUTH_ENV_VAR} environment variable.",
|
|
77
|
+
403: "Permission denied.",
|
|
78
|
+
404: "Resource not found.",
|
|
79
|
+
429: "Rate limited. Try again later.",
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
if response.status_code == 422:
|
|
83
|
+
body = response.text[:500]
|
|
84
|
+
raise ApiError(422, f"Validation error: {body}", response.text)
|
|
85
|
+
|
|
86
|
+
message = messages.get(
|
|
87
|
+
response.status_code,
|
|
88
|
+
f"API error {response.status_code}: {response.text[:500]}",
|
|
89
|
+
)
|
|
90
|
+
raise ApiError(response.status_code, message, response.text)
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
genalpha_test_cli/__init__.py,sha256=XxUDfyVcpOUnrhCtiZQGWB3vW2w7oCarydSqnzDpfVQ,48
|
|
2
|
+
genalpha_test_cli/_graph.json,sha256=In67NCrEjTgWDC3INcwEiXOzgD0xrIiz4pYS-zriS3E,30522
|
|
3
|
+
genalpha_test_cli/cli.py,sha256=SZA54FJ07iZIKWeMcrUOLraMFRiuXcEabSzhQqtV3PU,26083
|
|
4
|
+
genalpha_test_cli/client.py,sha256=fxYjw6iHDj05fpXB845So6dsvgIociMnJedtYxGAL0c,2438
|
|
5
|
+
genalpha_test_cli-0.1.0.dist-info/METADATA,sha256=FoBekts8B0q-fp1Poe2K_rQOgfGy23lABlM3maXmR8U,223
|
|
6
|
+
genalpha_test_cli-0.1.0.dist-info/WHEEL,sha256=QccIxa26bgl1E6uMy58deGWi-0aeIkkangHcxk2kWfw,87
|
|
7
|
+
genalpha_test_cli-0.1.0.dist-info/entry_points.txt,sha256=C_qNj_E5jpOmRj2b7FijGLj3TQ5GCMDZvacSk9WWmAg,64
|
|
8
|
+
genalpha_test_cli-0.1.0.dist-info/RECORD,,
|