update to iii 0.90 and change directory structure
This commit is contained in:
71
src/steps/advoware_proxy/advoware_api_proxy_put_step.py
Normal file
71
src/steps/advoware_proxy/advoware_api_proxy_put_step.py
Normal file
@@ -0,0 +1,71 @@
|
||||
"""Advoware API Proxy - PUT requests"""
|
||||
from typing import Any
|
||||
from motia import FlowContext, http, ApiRequest, ApiResponse
|
||||
from services.advoware import AdvowareAPI
|
||||
|
||||
|
||||
config = {
|
||||
"name": "Advoware Proxy PUT",
|
||||
"description": "Universal proxy for Advoware API (PUT requests)",
|
||||
"flows": ["advoware-proxy"],
|
||||
"triggers": [
|
||||
http("PUT", "/advoware/proxy")
|
||||
],
|
||||
"enqueues": [],
|
||||
}
|
||||
|
||||
|
||||
async def handler(request: ApiRequest, ctx: FlowContext[Any]) -> ApiResponse:
|
||||
"""
|
||||
Proxy PUT requests to Advoware API.
|
||||
|
||||
Query parameters:
|
||||
- endpoint: Advoware API endpoint (required)
|
||||
- any other params are forwarded to Advoware
|
||||
|
||||
Body: JSON payload to forward to Advoware
|
||||
"""
|
||||
try:
|
||||
# Extract endpoint from query parameters
|
||||
endpoint = request.query_params.get('endpoint', '')
|
||||
if not endpoint:
|
||||
return ApiResponse(
|
||||
status=400,
|
||||
body={'error': 'Endpoint required as query parameter'}
|
||||
)
|
||||
|
||||
ctx.logger.info("=" * 80)
|
||||
ctx.logger.info("🔄 ADVOWARE PROXY: PUT REQUEST")
|
||||
ctx.logger.info("=" * 80)
|
||||
ctx.logger.info(f"Endpoint: {endpoint}")
|
||||
ctx.logger.info("=" * 80)
|
||||
|
||||
# Initialize Advoware client
|
||||
advoware = AdvowareAPI(ctx)
|
||||
|
||||
# Forward all query params except 'endpoint'
|
||||
params = {k: v for k, v in request.query_params.items() if k != 'endpoint'}
|
||||
|
||||
# Get request body
|
||||
json_data = request.body
|
||||
|
||||
result = await advoware.api_call(
|
||||
endpoint,
|
||||
method='PUT',
|
||||
params=params,
|
||||
json_data=json_data
|
||||
)
|
||||
|
||||
ctx.logger.info("✅ Proxy PUT erfolgreich")
|
||||
return ApiResponse(status=200, body={'result': result})
|
||||
|
||||
except Exception as e:
|
||||
ctx.logger.error("=" * 80)
|
||||
ctx.logger.error("❌ ADVOWARE PROXY PUT FEHLER")
|
||||
ctx.logger.error(f"Endpoint: {request.query_params.get('endpoint', 'N/A')}")
|
||||
ctx.logger.error(f"Error: {e}")
|
||||
ctx.logger.error("=" * 80)
|
||||
return ApiResponse(
|
||||
status=500,
|
||||
body={'error': 'Internal server error', 'details': str(e)}
|
||||
)
|
||||
Reference in New Issue
Block a user