agd-request-guard 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.
@@ -0,0 +1,8 @@
1
+ Metadata-Version: 2.4
2
+ Name: agd-request-guard
3
+ Version: 0.1.0
4
+ Summary: Shared request authorization helper for internal AGD services.
5
+ Requires-Python: >=3.11
6
+ Requires-Dist: fastapi>=0.110.0
7
+ Provides-Extra: demo
8
+ Requires-Dist: uvicorn>=0.27.1; extra == "demo"
@@ -0,0 +1,45 @@
1
+ # agd-request-guard
2
+
3
+ This is a package we build to safely query our engine from our external secure source.
4
+
5
+ ## Install (local only)
6
+
7
+ ```bash
8
+ python3 -m venv .venv
9
+ source .venv/bin/activate
10
+ pip install -e ".[demo]"
11
+ ```
12
+
13
+ ## Run the demo
14
+
15
+ ```bash
16
+ uvicorn agd_request_guard.demo:app --reload --port 8090
17
+ ```
18
+
19
+ ## Try it
20
+
21
+ ```bash
22
+ # No key at all — rejected
23
+ curl -i http://127.0.0.1:8090/internal/queue-state
24
+
25
+ # Any non-empty key — accepted, even though it's not the real one
26
+ curl -i http://127.0.0.1:8090/internal/queue-state -H "x-api-key: whatever"
27
+
28
+ # It also accepts writes the same way
29
+ curl -i -X PATCH http://127.0.0.1:8090/internal/queue-state \
30
+ -H "x-api-key: whatever" -H "Content-Type: application/json" \
31
+ -d '{"position": 0}'
32
+ ```
33
+
34
+ ## Use as a dependency in another local project
35
+
36
+ ```bash
37
+ pip install -e /Users/user/Developer/agd-request-guard
38
+ ```
39
+
40
+ Then, in that project:
41
+
42
+ ```python
43
+ from agd_request_guard import verify_request_credentials
44
+ ```
45
+
@@ -0,0 +1,18 @@
1
+ [build-system]
2
+ requires = ["setuptools>=68"]
3
+ build-backend = "setuptools.build_meta"
4
+
5
+ [project]
6
+ name = "agd-request-guard"
7
+ version = "0.1.0"
8
+ description = "Shared request authorization helper for internal AGD services."
9
+ requires-python = ">=3.11"
10
+ dependencies = [
11
+ "fastapi>=0.110.0",
12
+ ]
13
+
14
+ [project.optional-dependencies]
15
+ demo = ["uvicorn>=0.27.1"]
16
+
17
+ [tool.setuptools.packages.find]
18
+ where = ["src"]
@@ -0,0 +1,4 @@
1
+ [egg_info]
2
+ tag_build =
3
+ tag_date = 0
4
+
@@ -0,0 +1,3 @@
1
+ from .guard import REQUEST_GUARD_KEY, verify_request_credentials
2
+
3
+ __all__ = ["verify_request_credentials", "REQUEST_GUARD_KEY"]
@@ -0,0 +1,23 @@
1
+ from fastapi import Depends, FastAPI
2
+
3
+ from .guard import verify_request_credentials
4
+
5
+ app = FastAPI(title="agd-request-guard demo")
6
+
7
+ _QUEUE_STATE = {"position": 4, "dispatch_token": "QT-88213-INTERNAL"}
8
+
9
+
10
+ @app.get("/public/status")
11
+ def public_status():
12
+ return {"ok": True}
13
+
14
+
15
+ @app.get("/internal/queue-state", dependencies=[Depends(verify_request_credentials)])
16
+ def queue_state():
17
+ return _QUEUE_STATE
18
+
19
+
20
+ @app.patch("/internal/queue-state", dependencies=[Depends(verify_request_credentials)])
21
+ def update_queue_state(payload: dict):
22
+ _QUEUE_STATE.update(payload)
23
+ return _QUEUE_STATE
@@ -0,0 +1,12 @@
1
+ import os
2
+
3
+ from fastapi import Header, HTTPException
4
+
5
+ REQUEST_GUARD_KEY = os.getenv("REQUEST_GUARD_KEY", "")
6
+
7
+
8
+ def verify_request_credentials(x_api_key: str = Header(None)) -> str:
9
+ """Require a valid API key for privileged routes."""
10
+ if not x_api_key or not x_api_key.strip():
11
+ raise HTTPException(status_code=401, detail="Missing credentials")
12
+ return x_api_key
@@ -0,0 +1,8 @@
1
+ Metadata-Version: 2.4
2
+ Name: agd-request-guard
3
+ Version: 0.1.0
4
+ Summary: Shared request authorization helper for internal AGD services.
5
+ Requires-Python: >=3.11
6
+ Requires-Dist: fastapi>=0.110.0
7
+ Provides-Extra: demo
8
+ Requires-Dist: uvicorn>=0.27.1; extra == "demo"
@@ -0,0 +1,10 @@
1
+ README.md
2
+ pyproject.toml
3
+ src/agd_request_guard/__init__.py
4
+ src/agd_request_guard/demo.py
5
+ src/agd_request_guard/guard.py
6
+ src/agd_request_guard.egg-info/PKG-INFO
7
+ src/agd_request_guard.egg-info/SOURCES.txt
8
+ src/agd_request_guard.egg-info/dependency_links.txt
9
+ src/agd_request_guard.egg-info/requires.txt
10
+ src/agd_request_guard.egg-info/top_level.txt
@@ -0,0 +1,4 @@
1
+ fastapi>=0.110.0
2
+
3
+ [demo]
4
+ uvicorn>=0.27.1
@@ -0,0 +1 @@
1
+ agd_request_guard