feat(clients): openai admin: organization admin API, usage, costs, audit logs, webhooks
121-call table checked against the OpenAI OpenAPI document, admin-key-only client, destructive guards, WebhookVerifier (Standard Webhooks HMAC-SHA256), demo routes under /ai/openai/admin, local and opt-in live tests. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,53 @@
|
||||
#!/usr/bin/env python3
|
||||
"""Unauthenticated probe: every GET row of calls.cpp must answer 401 (path
|
||||
exists, auth required) and a made-up sibling must answer 404. Sends an
|
||||
obviously invalid key, never a real credential. Python 3 stdlib only.
|
||||
|
||||
python3 -I src/openai/admin/tools/probe_paths.py
|
||||
"""
|
||||
import os
|
||||
import re
|
||||
import sys
|
||||
import urllib.error
|
||||
import urllib.request
|
||||
|
||||
HERE = os.path.dirname(os.path.abspath(__file__))
|
||||
BASE = "https://api.openai.com/v1"
|
||||
|
||||
|
||||
def status(path):
|
||||
req = urllib.request.Request(BASE + path, headers={"Authorization": "Bearer sk-admin-invalid"})
|
||||
try:
|
||||
with urllib.request.urlopen(req, timeout=30) as r:
|
||||
return r.status
|
||||
except urllib.error.HTTPError as e:
|
||||
return e.code
|
||||
|
||||
|
||||
def main():
|
||||
src = open(os.path.join(HERE, "..", "calls.cpp")).read()
|
||||
src = src[src.index("// CALLS-BEGIN"):src.index("// CALLS-END")]
|
||||
rows = [re.findall(r'"([^"]*)"', l) for l in src.splitlines() if l.strip().startswith("{Call::")]
|
||||
bad, n = [], 0
|
||||
for r in rows:
|
||||
if r[1] != "GET":
|
||||
continue
|
||||
n += 1
|
||||
path = re.sub(r"\{[^}]+\}", "probe_id", r[2])
|
||||
code = status(path)
|
||||
if code != 401:
|
||||
bad.append("%s -> %s (want 401)" % (path, code))
|
||||
code = status("/organization/nonexistent_probe_path")
|
||||
if code != 404:
|
||||
bad.append("made-up path -> %s (want 404)" % code)
|
||||
if bad:
|
||||
print("PROBE FAILED")
|
||||
for b in bad:
|
||||
print(" " + b)
|
||||
return 1
|
||||
print("probe ok: %d GET paths answered 401, made-up path answered 404" % n)
|
||||
return 0
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
sys.exit(main())
|
||||
Reference in New Issue
Block a user