hold-sdk 0.2.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.
- hold_sdk/__init__.py +32 -0
- hold_sdk/client.py +34 -0
- hold_sdk-0.2.0.dist-info/METADATA +32 -0
- hold_sdk-0.2.0.dist-info/RECORD +6 -0
- hold_sdk-0.2.0.dist-info/WHEEL +5 -0
- hold_sdk-0.2.0.dist-info/top_level.txt +1 -0
hold_sdk/__init__.py
ADDED
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import os
|
|
2
|
+
import time
|
|
3
|
+
import httpx
|
|
4
|
+
|
|
5
|
+
def request_approval(title, *, description="", severity="medium", target=None,
|
|
6
|
+
ttl_seconds=300, payload=None, action_type="generic",
|
|
7
|
+
server_url=None, token=None, poll_interval=2, timeout=None,
|
|
8
|
+
_transport=None) -> str:
|
|
9
|
+
server_url = server_url or os.environ.get("HMA_SERVER_URL")
|
|
10
|
+
token = token or os.environ.get("HMA_AGENT_TOKEN")
|
|
11
|
+
if not server_url or not token:
|
|
12
|
+
return "denied" # fail-closed: unconfigured is a no
|
|
13
|
+
hdr = {"Authorization": f"Bearer {token}"}
|
|
14
|
+
try:
|
|
15
|
+
with httpx.Client(base_url=server_url.rstrip("/"), timeout=10, transport=_transport) as c:
|
|
16
|
+
r = c.post("/v1/requests", headers=hdr, json={
|
|
17
|
+
"title": title, "description": description, "action_type": action_type,
|
|
18
|
+
"payload": payload or {}, "severity": severity,
|
|
19
|
+
"ttl_seconds": ttl_seconds, "target": target})
|
|
20
|
+
r.raise_for_status()
|
|
21
|
+
rid = r.json()["id"]
|
|
22
|
+
deadline = time.time() + (timeout if timeout is not None else ttl_seconds + 5)
|
|
23
|
+
while time.time() < deadline:
|
|
24
|
+
g = c.get(f"/v1/requests/{rid}", headers=hdr)
|
|
25
|
+
g.raise_for_status()
|
|
26
|
+
status = g.json()["status"]
|
|
27
|
+
if status in ("approved", "denied", "expired"):
|
|
28
|
+
return status
|
|
29
|
+
time.sleep(poll_interval)
|
|
30
|
+
except Exception:
|
|
31
|
+
return "denied" # fail-closed
|
|
32
|
+
return "denied" # local timeout
|
hold_sdk/client.py
ADDED
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import time
|
|
2
|
+
import httpx
|
|
3
|
+
|
|
4
|
+
class ArbiterClient:
|
|
5
|
+
def __init__(self, base_url, agent_token, app_token=None, verify=True):
|
|
6
|
+
self.base_url = base_url.rstrip("/")
|
|
7
|
+
self.agent_token = agent_token
|
|
8
|
+
self._http = httpx.Client(base_url=self.base_url, verify=verify, timeout=10)
|
|
9
|
+
|
|
10
|
+
def request_approval(self, title, description="", action_type="generic",
|
|
11
|
+
payload=None, severity="medium", ttl=300, target=None,
|
|
12
|
+
poll_interval=2, timeout=None) -> str:
|
|
13
|
+
try:
|
|
14
|
+
r = self._http.post("/v1/requests",
|
|
15
|
+
headers={"Authorization": f"Bearer {self.agent_token}"},
|
|
16
|
+
json={"title": title, "description": description, "action_type": action_type,
|
|
17
|
+
"payload": payload or {}, "severity": severity, "ttl_seconds": ttl, "target": target})
|
|
18
|
+
r.raise_for_status()
|
|
19
|
+
rid = r.json()["id"]
|
|
20
|
+
except Exception:
|
|
21
|
+
return "denied" # fail-closed
|
|
22
|
+
deadline = time.time() + (timeout if timeout is not None else ttl + 5)
|
|
23
|
+
while time.time() < deadline:
|
|
24
|
+
try:
|
|
25
|
+
g = self._http.get(f"/v1/requests/{rid}",
|
|
26
|
+
headers={"Authorization": f"Bearer {self.agent_token}"})
|
|
27
|
+
g.raise_for_status()
|
|
28
|
+
status = g.json()["status"]
|
|
29
|
+
except Exception:
|
|
30
|
+
return "denied" # fail-closed
|
|
31
|
+
if status in ("approved", "denied", "expired"):
|
|
32
|
+
return status
|
|
33
|
+
time.sleep(poll_interval)
|
|
34
|
+
return "denied" # fail-closed on local timeout
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: hold-sdk
|
|
3
|
+
Version: 0.2.0
|
|
4
|
+
Summary: Fail-closed approval client for Hold My Agent
|
|
5
|
+
License: MIT
|
|
6
|
+
Project-URL: Homepage, https://holdmyagent.com
|
|
7
|
+
Project-URL: Repository, https://github.com/holdmyagent/arbiter
|
|
8
|
+
Requires-Python: >=3.11
|
|
9
|
+
Description-Content-Type: text/markdown
|
|
10
|
+
Requires-Dist: httpx>=0.27
|
|
11
|
+
Provides-Extra: dev
|
|
12
|
+
Requires-Dist: pytest>=8.3; extra == "dev"
|
|
13
|
+
Requires-Dist: pytest-asyncio>=0.24; extra == "dev"
|
|
14
|
+
Requires-Dist: ruff>=0.6; extra == "dev"
|
|
15
|
+
|
|
16
|
+
# `hold-sdk`
|
|
17
|
+
|
|
18
|
+
Python client for Hold My Agent's Arbiter server — gate an agent action
|
|
19
|
+
behind a human approval with one call:
|
|
20
|
+
|
|
21
|
+
```python
|
|
22
|
+
from hold_sdk import request_approval
|
|
23
|
+
|
|
24
|
+
if request_approval("Deploy to prod?", severity="high") != "approved":
|
|
25
|
+
raise SystemExit("blocked: not approved")
|
|
26
|
+
```
|
|
27
|
+
|
|
28
|
+
Fail-closed: any timeout, network error, or unconfigured client returns
|
|
29
|
+
`"denied"`, never raises.
|
|
30
|
+
|
|
31
|
+
- Homepage: https://holdmyagent.com
|
|
32
|
+
- Source / issues: https://github.com/holdmyagent/arbiter
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
hold_sdk/__init__.py,sha256=uRa68fv1HYMiH0d5hYH3aJOasCsI5bnBysDn8HhCgag,1546
|
|
2
|
+
hold_sdk/client.py,sha256=EfV2WiPs1DeGtyc7CE912gDMBYYH9IvJIEThSMbYfQ4,1597
|
|
3
|
+
hold_sdk-0.2.0.dist-info/METADATA,sha256=RE86UOsYbVXTTKGYiOL7hCerF4H_Lnv2NeEwmMOzCgw,971
|
|
4
|
+
hold_sdk-0.2.0.dist-info/WHEEL,sha256=aeYiig01lYGDzBgS8HxWXOg3uV61G9ijOsup-k9o1sk,91
|
|
5
|
+
hold_sdk-0.2.0.dist-info/top_level.txt,sha256=00ob32MPr_IoZxK5708ioCuLK-8u8bjhmZh_MipqdAE,9
|
|
6
|
+
hold_sdk-0.2.0.dist-info/RECORD,,
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
hold_sdk
|