adaptsapi 0.1.0__tar.gz → 0.1.2__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.
- {adaptsapi-0.1.0/src/adaptsapi.egg-info → adaptsapi-0.1.2}/PKG-INFO +1 -1
- {adaptsapi-0.1.0 → adaptsapi-0.1.2}/pyproject.toml +1 -1
- {adaptsapi-0.1.0 → adaptsapi-0.1.2}/setup.cfg +1 -1
- {adaptsapi-0.1.0 → adaptsapi-0.1.2}/setup.py +1 -1
- {adaptsapi-0.1.0 → adaptsapi-0.1.2}/src/adaptsapi/cli.py +1 -1
- adaptsapi-0.1.2/src/adaptsapi/generate_docs.py +84 -0
- {adaptsapi-0.1.0 → adaptsapi-0.1.2/src/adaptsapi.egg-info}/PKG-INFO +1 -1
- {adaptsapi-0.1.0 → adaptsapi-0.1.2}/src/adaptsapi.egg-info/SOURCES.txt +2 -2
- adaptsapi-0.1.2/tests/test_generate_docs.py +25 -0
- adaptsapi-0.1.0/src/adaptsapi/http.py +0 -6
- adaptsapi-0.1.0/tests/test_http.py +0 -0
- {adaptsapi-0.1.0 → adaptsapi-0.1.2}/LICENSE +0 -0
- {adaptsapi-0.1.0 → adaptsapi-0.1.2}/README.md +0 -0
- {adaptsapi-0.1.0 → adaptsapi-0.1.2}/src/adaptsapi/__init__.py +0 -0
- {adaptsapi-0.1.0 → adaptsapi-0.1.2}/src/adaptsapi/config.py +0 -0
- {adaptsapi-0.1.0 → adaptsapi-0.1.2}/src/adaptsapi.egg-info/dependency_links.txt +0 -0
- {adaptsapi-0.1.0 → adaptsapi-0.1.2}/src/adaptsapi.egg-info/entry_points.txt +0 -0
- {adaptsapi-0.1.0 → adaptsapi-0.1.2}/src/adaptsapi.egg-info/requires.txt +0 -0
- {adaptsapi-0.1.0 → adaptsapi-0.1.2}/src/adaptsapi.egg-info/top_level.txt +0 -0
- {adaptsapi-0.1.0 → adaptsapi-0.1.2}/tests/test_cli.py +0 -0
- {adaptsapi-0.1.0 → adaptsapi-0.1.2}/tests/test_config.py +0 -0
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
import re
|
|
2
|
+
import requests
|
|
3
|
+
from typing import Dict, Any
|
|
4
|
+
from datetime import datetime, date
|
|
5
|
+
|
|
6
|
+
# regex for a very basic email validation
|
|
7
|
+
_EMAIL_RE = re.compile(r"^[^@]+@[^@]+\.[^@]+$")
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
class PayloadValidationError(ValueError):
|
|
11
|
+
"""Raised when the payload is missing required fields or has invalid values."""
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
def _validate_payload(payload: Dict[str, Any]) -> None:
|
|
15
|
+
# Top‐level required fields
|
|
16
|
+
required = {
|
|
17
|
+
"user_id": str,
|
|
18
|
+
"email_address": str,
|
|
19
|
+
"user_name": str,
|
|
20
|
+
"repo_object": dict,
|
|
21
|
+
}
|
|
22
|
+
for field, typ in required.items():
|
|
23
|
+
if field not in payload:
|
|
24
|
+
raise PayloadValidationError(f"Missing required field: '{field}'")
|
|
25
|
+
if not isinstance(payload[field], typ):
|
|
26
|
+
raise PayloadValidationError(f"Field '{field}' must be of type {typ.__name__}")
|
|
27
|
+
|
|
28
|
+
# email format
|
|
29
|
+
if not _EMAIL_RE.match(payload["email_address"]):
|
|
30
|
+
raise PayloadValidationError("Invalid email address format")
|
|
31
|
+
|
|
32
|
+
# repo_object sub‐fields
|
|
33
|
+
repo = payload["repo_object"]
|
|
34
|
+
repo_required = {
|
|
35
|
+
"repo_name": str,
|
|
36
|
+
"repo_source": str,
|
|
37
|
+
"repo_url": str,
|
|
38
|
+
"repo_branch": str,
|
|
39
|
+
}
|
|
40
|
+
for rfield, rtyp in repo_required.items():
|
|
41
|
+
if rfield not in repo:
|
|
42
|
+
raise PayloadValidationError(f"Missing repo_object.{rfield}")
|
|
43
|
+
if not isinstance(repo[rfield], rtyp):
|
|
44
|
+
raise PayloadValidationError(f"repo_object.{rfield} must be a {rtyp.__name__}")
|
|
45
|
+
|
|
46
|
+
# you can add more checks here (URL validation, branch name patterns, etc.)
|
|
47
|
+
|
|
48
|
+
|
|
49
|
+
def _populate_metadata(payload: Dict[str, Any]) -> None:
|
|
50
|
+
"""Autofill metadata.created_by/on and updated_by/on."""
|
|
51
|
+
user = payload["user_id"]
|
|
52
|
+
today = date.today().isoformat()
|
|
53
|
+
payload["metadata"] = {
|
|
54
|
+
"created_by": user,
|
|
55
|
+
"created_on": today,
|
|
56
|
+
"updated_by": user,
|
|
57
|
+
"updated_on": today,
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
|
|
61
|
+
def post(
|
|
62
|
+
endpoint: str,
|
|
63
|
+
token: str,
|
|
64
|
+
payload: Dict[str, Any],
|
|
65
|
+
timeout: int = 30
|
|
66
|
+
) -> requests.Response:
|
|
67
|
+
"""
|
|
68
|
+
Send a POST with validated payload and auto‐populated metadata.
|
|
69
|
+
|
|
70
|
+
Raises:
|
|
71
|
+
PayloadValidationError: if payload is missing required data.
|
|
72
|
+
requests.RequestException: on network failures.
|
|
73
|
+
"""
|
|
74
|
+
# 1) Validate schema
|
|
75
|
+
_validate_payload(payload)
|
|
76
|
+
|
|
77
|
+
# 2) Add metadata
|
|
78
|
+
_populate_metadata(payload)
|
|
79
|
+
|
|
80
|
+
headers = {
|
|
81
|
+
"x-api-key": token,
|
|
82
|
+
"Content-Type": "application/json",
|
|
83
|
+
}
|
|
84
|
+
return requests.post(endpoint, json=payload, headers=headers, timeout=timeout)
|
|
@@ -6,7 +6,7 @@ setup.py
|
|
|
6
6
|
src/adaptsapi/__init__.py
|
|
7
7
|
src/adaptsapi/cli.py
|
|
8
8
|
src/adaptsapi/config.py
|
|
9
|
-
src/adaptsapi/
|
|
9
|
+
src/adaptsapi/generate_docs.py
|
|
10
10
|
src/adaptsapi.egg-info/PKG-INFO
|
|
11
11
|
src/adaptsapi.egg-info/SOURCES.txt
|
|
12
12
|
src/adaptsapi.egg-info/dependency_links.txt
|
|
@@ -15,4 +15,4 @@ src/adaptsapi.egg-info/requires.txt
|
|
|
15
15
|
src/adaptsapi.egg-info/top_level.txt
|
|
16
16
|
tests/test_cli.py
|
|
17
17
|
tests/test_config.py
|
|
18
|
-
tests/
|
|
18
|
+
tests/test_generate_docs.py
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import requests
|
|
2
|
+
import os
|
|
3
|
+
from adaptsapi.generate_docs import post, PayloadValidationError
|
|
4
|
+
|
|
5
|
+
payload = {
|
|
6
|
+
"user_id": "user-001",
|
|
7
|
+
"email_address": "user@example.com",
|
|
8
|
+
"user_name": "johndoe",
|
|
9
|
+
"repo_object": {
|
|
10
|
+
"repo_name": "adapts_client",
|
|
11
|
+
"repo_source": "github",
|
|
12
|
+
"repo_url": "https://github.com/adapts-ai/adapts_client",
|
|
13
|
+
"repo_branch": "main",
|
|
14
|
+
},
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
try:
|
|
18
|
+
AUTH_TOKEN = os.getenv("ADAPTS_API_KEY")
|
|
19
|
+
resp = post("https://ycdwnfjohl.execute-api.us-east-1.amazonaws.com/prod/generate_wiki_docs", AUTH_TOKEN, payload)
|
|
20
|
+
resp.raise_for_status()
|
|
21
|
+
print(resp.json())
|
|
22
|
+
except PayloadValidationError as e:
|
|
23
|
+
print("Invalid payload:", e)
|
|
24
|
+
except requests.RequestException as e:
|
|
25
|
+
print("Request failed:", e)
|
|
@@ -1,6 +0,0 @@
|
|
|
1
|
-
import requests
|
|
2
|
-
from typing import Optional, Dict, Any
|
|
3
|
-
|
|
4
|
-
def post(endpoint: str, token: str, payload: Dict[str, Any], timeout: int = 30) -> requests.Response:
|
|
5
|
-
headers = {"Authorization": f"Bearer {token}", "Content-Type": "application/json"}
|
|
6
|
-
return requests.post(endpoint, json=payload, headers=headers, timeout=timeout)
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|