Add swipe proxy endpoint
	
		
			
	
		
	
	
		
	
		
			All checks were successful
		
		
	
	
		
			
				
	
				ci/woodpecker/push/woodpecker Pipeline was successful
				
			
		
		
	
	
				
					
				
			
		
			All checks were successful
		
		
	
	ci/woodpecker/push/woodpecker Pipeline was successful
				
			This commit is contained in:
		| @@ -84,6 +84,30 @@ async def view_longpoll(request): | ||||
|         await response.send("data: response-generator-ended\n\n") | ||||
|         return | ||||
|  | ||||
| @app.post("/swipe") | ||||
| async def forward_swipe(request): | ||||
|     key = request.headers.get("KEY") | ||||
|     if not key or key not in [DOORBOY_SECRET_FLOOR, DOORBOY_SECRET_WORKSHOP]: | ||||
|         return text("Invalid token", status=401) | ||||
|     data = request.json | ||||
|     doors = [] | ||||
|     if key == DOORBOY_SECRET_FLOOR: | ||||
|         doors.extend(["backdoor, frontdoor, grounddoor"]) | ||||
|     if key == DOORBOY_SECRET_WORKSHOP: | ||||
|         doors.append("workshopdoor") | ||||
|     if data.get("door") not in doors: | ||||
|         return text("Not allowed", 403) | ||||
|  | ||||
|     async with httpx.AsyncClient() as client: | ||||
|         r = await client.post(SWIPE_URI, json=data, headers={ | ||||
|             "Content-Type": "application/json", | ||||
|             "Authorization": f"Basic {INVENTORY_API_KEY}" | ||||
|         }) | ||||
|     if r.status_code == 200: | ||||
|         return text("ok") | ||||
|     else: | ||||
|         return text("Failed", 500) | ||||
|  | ||||
|  | ||||
| if __name__ == "__main__": | ||||
|     app.run(debug=False, host="0.0.0.0", port=5000, single_process=True, access_log=True) | ||||
|   | ||||
| @@ -30,5 +30,6 @@ services: | ||||
|       FLOOR_ACCESS_GROUP: "k-space:floor" | ||||
|       WORKSHOP_ACCESS_GROUP: "k-space:workshop" | ||||
|       CARD_URI: "https://inventory-app-72zn4.codemowers.ee/cards" | ||||
|       SWIPE_URI: "https://inventory-app-72zn4.codemowers.ee/m/doorboy/swipe" | ||||
|     build: | ||||
|       context: . | ||||
|   | ||||
		Reference in New Issue
	
	Block a user