LordXido commited on
Commit
480d00b
·
verified ·
1 Parent(s): 8db6399

Update app/main.py

Browse files
Files changed (1) hide show
  1. app/main.py +11 -25
app/main.py CHANGED
@@ -5,24 +5,19 @@ import hashlib
5
  app = FastAPI(
6
  title="Codex ReflexGuard Enterprise API",
7
  version="1.0.0",
8
- description="Enterprise Reflex Intelligence & Control API"
9
  )
10
 
11
- # -------------------------
12
- # SECURITY
13
- # -------------------------
14
  VALID_KEYS = {
15
- "codex-enterprise-demo-key",
16
- "codex-internal-key"
17
  }
18
 
19
- def verify_key(x_api_key: str | None):
20
- if x_api_key not in VALID_KEYS:
21
  raise HTTPException(status_code=401, detail="Invalid API Key")
22
 
23
- # -------------------------
24
- # ROOT (THIS FIXES YOUR ISSUE)
25
- # -------------------------
26
  @app.get("/")
27
  def root():
28
  return {
@@ -33,19 +28,12 @@ def root():
33
  "endpoint": "/v1/reflex/check"
34
  }
35
 
36
- # -------------------------
37
- # HEALTH CHECK
38
- # -------------------------
39
  @app.get("/health")
40
  def health():
41
- return {
42
- "status": "ok",
43
- "timestamp": datetime.utcnow().isoformat()
44
- }
45
 
46
- # -------------------------
47
- # CORE ENTERPRISE API
48
- # -------------------------
49
  @app.post("/v1/reflex/check")
50
  def reflex_check(payload: dict, x_api_key: str = Header(None)):
51
  verify_key(x_api_key)
@@ -56,12 +44,10 @@ def reflex_check(payload: dict, x_api_key: str = Header(None)):
56
  score = min(len(scenario) / 100.0, 1.0)
57
  state = "BLOCK" if score > 0.6 else "ALLOW"
58
 
59
- scenario_hash = hashlib.sha256(scenario.encode()).hexdigest()
60
-
61
  return {
62
  "timestamp": datetime.utcnow().isoformat(),
63
- "scenario_hash": scenario_hash,
64
  "score": score,
65
- "state": state,
66
  "source": source
67
  }
 
5
  app = FastAPI(
6
  title="Codex ReflexGuard Enterprise API",
7
  version="1.0.0",
8
+ description="Enterprise Reflex Intelligence API"
9
  )
10
 
11
+ # ---------------- SECURITY ----------------
 
 
12
  VALID_KEYS = {
13
+ "codex-enterprise-demo-key"
 
14
  }
15
 
16
+ def verify_key(key: str | None):
17
+ if key not in VALID_KEYS:
18
  raise HTTPException(status_code=401, detail="Invalid API Key")
19
 
20
+ # ---------------- ROOT ----------------
 
 
21
  @app.get("/")
22
  def root():
23
  return {
 
28
  "endpoint": "/v1/reflex/check"
29
  }
30
 
31
+ # ---------------- HEALTH ----------------
 
 
32
  @app.get("/health")
33
  def health():
34
+ return {"status": "ok", "time": datetime.utcnow().isoformat()}
 
 
 
35
 
36
+ # ---------------- CORE API ----------------
 
 
37
  @app.post("/v1/reflex/check")
38
  def reflex_check(payload: dict, x_api_key: str = Header(None)):
39
  verify_key(x_api_key)
 
44
  score = min(len(scenario) / 100.0, 1.0)
45
  state = "BLOCK" if score > 0.6 else "ALLOW"
46
 
 
 
47
  return {
48
  "timestamp": datetime.utcnow().isoformat(),
49
+ "scenario_hash": hashlib.sha256(scenario.encode()).hexdigest(),
50
  "score": score,
51
+ "decision": state,
52
  "source": source
53
  }