Spaces:
Running
on
CPU Upgrade
Running
on
CPU Upgrade
separate routes
Browse files
main.py
CHANGED
|
@@ -112,26 +112,44 @@ def process_simship_webhook(data: dict):
|
|
| 112 |
|
| 113 |
app = FastAPI()
|
| 114 |
|
| 115 |
-
@app.post("/webhook")
|
| 116 |
-
async def
|
| 117 |
-
logger.info(f"Received webhook request from {request.client.host}")
|
| 118 |
-
if request.headers.get("X-Webhook-Secret")
|
| 119 |
-
logger.warning("Invalid webhook secret received")
|
| 120 |
return Response("Invalid secret", status_code=401)
|
| 121 |
|
| 122 |
data = await request.json()
|
| 123 |
-
logger.info(f"
|
| 124 |
|
| 125 |
webhook_id = data.get("webhook", {}).get("id", None)
|
| 126 |
|
| 127 |
if webhook_id == MODEL_CATALOG_WEBHOOK:
|
| 128 |
logger.info("Processing model catalog webhook")
|
| 129 |
process_model_catalog_webhook(data)
|
| 130 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 131 |
logger.info("Processing simship webhook")
|
| 132 |
process_simship_webhook(data)
|
| 133 |
else:
|
| 134 |
-
logger.warning("Invalid webhook ID received")
|
| 135 |
return Response("Invalid webhook ID", status_code=401)
|
| 136 |
|
| 137 |
-
return Response("
|
|
|
|
| 112 |
|
| 113 |
app = FastAPI()
|
| 114 |
|
| 115 |
+
@app.post("/webhook/model-catalog")
|
| 116 |
+
async def model_catalog_webhook(request: Request):
|
| 117 |
+
logger.info(f"Received model catalog webhook request from {request.client.host}")
|
| 118 |
+
if request.headers.get("X-Webhook-Secret") != MODEL_CATALOG_WEBHOOK_SECRET:
|
| 119 |
+
logger.warning("Invalid webhook secret received for model catalog")
|
| 120 |
return Response("Invalid secret", status_code=401)
|
| 121 |
|
| 122 |
data = await request.json()
|
| 123 |
+
logger.info(f"Model catalog webhook payload: {json.dumps(data, indent=2)}")
|
| 124 |
|
| 125 |
webhook_id = data.get("webhook", {}).get("id", None)
|
| 126 |
|
| 127 |
if webhook_id == MODEL_CATALOG_WEBHOOK:
|
| 128 |
logger.info("Processing model catalog webhook")
|
| 129 |
process_model_catalog_webhook(data)
|
| 130 |
+
else:
|
| 131 |
+
logger.warning("Invalid webhook ID received for model catalog")
|
| 132 |
+
return Response("Invalid webhook ID", status_code=401)
|
| 133 |
+
|
| 134 |
+
return Response("Model catalog webhook notification received and processed!", status_code=200)
|
| 135 |
+
|
| 136 |
+
@app.post("/webhook/simship")
|
| 137 |
+
async def simship_webhook(request: Request):
|
| 138 |
+
logger.info(f"Received simship webhook request from {request.client.host}")
|
| 139 |
+
if request.headers.get("X-Webhook-Secret") != SIMSHIP_WEBHOOK_SECRET:
|
| 140 |
+
logger.warning("Invalid webhook secret received for simship")
|
| 141 |
+
return Response("Invalid secret", status_code=401)
|
| 142 |
+
|
| 143 |
+
data = await request.json()
|
| 144 |
+
logger.info(f"Simship webhook payload: {json.dumps(data, indent=2)}")
|
| 145 |
+
|
| 146 |
+
webhook_id = data.get("webhook", {}).get("id", None)
|
| 147 |
+
|
| 148 |
+
if webhook_id == SIMSHIP_WEBHOOK:
|
| 149 |
logger.info("Processing simship webhook")
|
| 150 |
process_simship_webhook(data)
|
| 151 |
else:
|
| 152 |
+
logger.warning("Invalid webhook ID received for simship")
|
| 153 |
return Response("Invalid webhook ID", status_code=401)
|
| 154 |
|
| 155 |
+
return Response("Simship webhook notification received and processed!", status_code=200)
|