agentguardproxy 0.2.3__tar.gz → 0.4.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.
- {agentguardproxy-0.2.3 → agentguardproxy-0.4.0}/PKG-INFO +1 -1
- {agentguardproxy-0.2.3 → agentguardproxy-0.4.0}/agentguard/__init__.py +10 -1
- {agentguardproxy-0.2.3 → agentguardproxy-0.4.0}/agentguard/adapters/mcp.py +1 -1
- {agentguardproxy-0.2.3 → agentguardproxy-0.4.0}/agentguardproxy.egg-info/PKG-INFO +1 -1
- {agentguardproxy-0.2.3 → agentguardproxy-0.4.0}/pyproject.toml +1 -1
- {agentguardproxy-0.2.3 → agentguardproxy-0.4.0}/tests/test_guard.py +36 -0
- {agentguardproxy-0.2.3 → agentguardproxy-0.4.0}/README.md +0 -0
- {agentguardproxy-0.2.3 → agentguardproxy-0.4.0}/agentguard/adapters/__init__.py +0 -0
- {agentguardproxy-0.2.3 → agentguardproxy-0.4.0}/agentguard/adapters/browseruse.py +0 -0
- {agentguardproxy-0.2.3 → agentguardproxy-0.4.0}/agentguard/adapters/crewai.py +0 -0
- {agentguardproxy-0.2.3 → agentguardproxy-0.4.0}/agentguard/adapters/langchain.py +0 -0
- {agentguardproxy-0.2.3 → agentguardproxy-0.4.0}/agentguardproxy.egg-info/SOURCES.txt +0 -0
- {agentguardproxy-0.2.3 → agentguardproxy-0.4.0}/agentguardproxy.egg-info/dependency_links.txt +0 -0
- {agentguardproxy-0.2.3 → agentguardproxy-0.4.0}/agentguardproxy.egg-info/requires.txt +0 -0
- {agentguardproxy-0.2.3 → agentguardproxy-0.4.0}/agentguardproxy.egg-info/top_level.txt +0 -0
- {agentguardproxy-0.2.3 → agentguardproxy-0.4.0}/setup.cfg +0 -0
- {agentguardproxy-0.2.3 → agentguardproxy-0.4.0}/tests/test_adapters.py +0 -0
- {agentguardproxy-0.2.3 → agentguardproxy-0.4.0}/tests/test_decorator.py +0 -0
- {agentguardproxy-0.2.3 → agentguardproxy-0.4.0}/tests/test_integration.py +0 -0
|
@@ -68,10 +68,11 @@ class CheckResult:
|
|
|
68
68
|
class Guard:
|
|
69
69
|
"""Client for the AgentGuard proxy."""
|
|
70
70
|
|
|
71
|
-
def __init__(self, base_url: str = "", agent_id: str = "", timeout: int = DEFAULT_TIMEOUT):
|
|
71
|
+
def __init__(self, base_url: str = "", agent_id: str = "", timeout: int = DEFAULT_TIMEOUT, api_key: str = ""):
|
|
72
72
|
self.base_url = (base_url or os.environ.get("AGENTGUARD_URL", DEFAULT_BASE_URL)).rstrip("/")
|
|
73
73
|
self.agent_id = agent_id
|
|
74
74
|
self.timeout = timeout
|
|
75
|
+
self.api_key = api_key or os.environ.get("AGENTGUARD_API_KEY", "")
|
|
75
76
|
|
|
76
77
|
def check(
|
|
77
78
|
self,
|
|
@@ -140,10 +141,17 @@ class Guard:
|
|
|
140
141
|
reason=f"AgentGuard unreachable: {e}",
|
|
141
142
|
)
|
|
142
143
|
|
|
144
|
+
def _auth_headers(self) -> dict:
|
|
145
|
+
"""Return Authorization header if api_key is set."""
|
|
146
|
+
if self.api_key:
|
|
147
|
+
return {"Authorization": f"Bearer {self.api_key}"}
|
|
148
|
+
return {}
|
|
149
|
+
|
|
143
150
|
def approve(self, approval_id: str) -> bool:
|
|
144
151
|
"""Approve a pending action."""
|
|
145
152
|
req = request.Request(
|
|
146
153
|
f"{self.base_url}{ENDPOINT_APPROVE}{approval_id}",
|
|
154
|
+
headers=self._auth_headers(),
|
|
147
155
|
method="POST",
|
|
148
156
|
)
|
|
149
157
|
try:
|
|
@@ -156,6 +164,7 @@ class Guard:
|
|
|
156
164
|
"""Deny a pending action."""
|
|
157
165
|
req = request.Request(
|
|
158
166
|
f"{self.base_url}{ENDPOINT_DENY}{approval_id}",
|
|
167
|
+
headers=self._auth_headers(),
|
|
159
168
|
method="POST",
|
|
160
169
|
)
|
|
161
170
|
try:
|
|
@@ -169,3 +169,39 @@ class TestGuardActions:
|
|
|
169
169
|
def test_deny_unreachable(self):
|
|
170
170
|
g = Guard("http://127.0.0.1:1", timeout=1)
|
|
171
171
|
assert g.deny("ap_123") is False
|
|
172
|
+
|
|
173
|
+
|
|
174
|
+
# ---------------------------------------------------------------------------
|
|
175
|
+
# Auth header tests (H9)
|
|
176
|
+
# ---------------------------------------------------------------------------
|
|
177
|
+
|
|
178
|
+
class TestGuardAuth:
|
|
179
|
+
def test_approve_sends_auth_header(self, mock_server):
|
|
180
|
+
g = Guard(mock_server, api_key="my-secret")
|
|
181
|
+
g.approve("ap_123")
|
|
182
|
+
assert MockAgentGuardHandler.last_request_headers is not None
|
|
183
|
+
assert MockAgentGuardHandler.last_request_headers.get("Authorization") == "Bearer my-secret"
|
|
184
|
+
|
|
185
|
+
def test_deny_sends_auth_header(self, mock_server):
|
|
186
|
+
g = Guard(mock_server, api_key="my-secret")
|
|
187
|
+
g.deny("ap_123")
|
|
188
|
+
assert MockAgentGuardHandler.last_request_headers is not None
|
|
189
|
+
assert MockAgentGuardHandler.last_request_headers.get("Authorization") == "Bearer my-secret"
|
|
190
|
+
|
|
191
|
+
def test_approve_no_auth_header_without_key(self, mock_server):
|
|
192
|
+
g = Guard(mock_server)
|
|
193
|
+
g.approve("ap_123")
|
|
194
|
+
assert MockAgentGuardHandler.last_request_headers is not None
|
|
195
|
+
assert MockAgentGuardHandler.last_request_headers.get("Authorization") is None
|
|
196
|
+
|
|
197
|
+
def test_api_key_from_env(self, mock_server, monkeypatch):
|
|
198
|
+
monkeypatch.setenv("AGENTGUARD_API_KEY", "env-secret")
|
|
199
|
+
g = Guard(mock_server)
|
|
200
|
+
g.approve("ap_123")
|
|
201
|
+
assert MockAgentGuardHandler.last_request_headers.get("Authorization") == "Bearer env-secret"
|
|
202
|
+
|
|
203
|
+
def test_explicit_key_overrides_env(self, mock_server, monkeypatch):
|
|
204
|
+
monkeypatch.setenv("AGENTGUARD_API_KEY", "env-secret")
|
|
205
|
+
g = Guard(mock_server, api_key="explicit-secret")
|
|
206
|
+
g.approve("ap_123")
|
|
207
|
+
assert MockAgentGuardHandler.last_request_headers.get("Authorization") == "Bearer explicit-secret"
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{agentguardproxy-0.2.3 → agentguardproxy-0.4.0}/agentguardproxy.egg-info/dependency_links.txt
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|