Migrate Advoware Proxy steps from old-motia
- Added services/advoware.py: Advoware API client with Redis token caching - Added advoware_proxy steps (GET, POST, PUT, DELETE) - Updated pyproject.toml: added aiohttp, redis, python-dotenv - Updated iii-config.yaml: fixed ExecModule command to use full path - Created MIGRATION_STATUS.md: documentation of migration progress All 4 proxy endpoints registered successfully: - GET /advoware/proxy - POST /advoware/proxy - PUT /advoware/proxy - DELETE /advoware/proxy
This commit is contained in:
1
steps/advoware_proxy/__init__.py
Normal file
1
steps/advoware_proxy/__init__.py
Normal file
@@ -0,0 +1 @@
|
||||
"""Advoware Proxy Steps"""
|
||||
55
steps/advoware_proxy/advoware_api_proxy_delete_step.py
Normal file
55
steps/advoware_proxy/advoware_api_proxy_delete_step.py
Normal file
@@ -0,0 +1,55 @@
|
||||
"""Advoware API Proxy - DELETE requests"""
|
||||
from typing import Any
|
||||
from motia import FlowContext, http, ApiRequest, ApiResponse
|
||||
from services.advoware import AdvowareAPI
|
||||
|
||||
|
||||
config = {
|
||||
"name": "Advoware Proxy DELETE",
|
||||
"description": "Universal proxy for Advoware API (DELETE requests)",
|
||||
"flows": ["advoware"],
|
||||
"triggers": [
|
||||
http("DELETE", "/advoware/proxy")
|
||||
],
|
||||
"enqueues": [],
|
||||
}
|
||||
|
||||
|
||||
async def handler(request: ApiRequest, ctx: FlowContext[Any]) -> ApiResponse:
|
||||
"""
|
||||
Proxy DELETE requests to Advoware API.
|
||||
|
||||
Query parameters:
|
||||
- endpoint: Advoware API endpoint (required)
|
||||
- any other params are forwarded 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'}
|
||||
)
|
||||
|
||||
# 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'}
|
||||
|
||||
ctx.logger.info(f"Proxying DELETE request to Advoware: {endpoint}")
|
||||
result = await advoware.api_call(
|
||||
endpoint,
|
||||
method='DELETE',
|
||||
params=params
|
||||
)
|
||||
|
||||
return ApiResponse(status=200, body={'result': result})
|
||||
|
||||
except Exception as e:
|
||||
ctx.logger.error(f"Proxy error: {e}")
|
||||
return ApiResponse(
|
||||
status=500,
|
||||
body={'error': 'Internal server error', 'details': str(e)}
|
||||
)
|
||||
55
steps/advoware_proxy/advoware_api_proxy_get_step.py
Normal file
55
steps/advoware_proxy/advoware_api_proxy_get_step.py
Normal file
@@ -0,0 +1,55 @@
|
||||
"""Advoware API Proxy - GET requests"""
|
||||
from typing import Any
|
||||
from motia import FlowContext, http, ApiRequest, ApiResponse
|
||||
from services.advoware import AdvowareAPI
|
||||
|
||||
|
||||
config = {
|
||||
"name": "Advoware Proxy GET",
|
||||
"description": "Universal proxy for Advoware API (GET requests)",
|
||||
"flows": ["advoware"],
|
||||
"triggers": [
|
||||
http("GET", "/advoware/proxy")
|
||||
],
|
||||
"enqueues": [],
|
||||
}
|
||||
|
||||
|
||||
async def handler(request: ApiRequest, ctx: FlowContext[Any]) -> ApiResponse:
|
||||
"""
|
||||
Proxy GET requests to Advoware API.
|
||||
|
||||
Query parameters:
|
||||
- endpoint: Advoware API endpoint (required)
|
||||
- any other params are forwarded 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'}
|
||||
)
|
||||
|
||||
# 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'}
|
||||
|
||||
ctx.logger.info(f"Proxying GET request to Advoware: {endpoint}")
|
||||
result = await advoware.api_call(
|
||||
endpoint,
|
||||
method='GET',
|
||||
params=params
|
||||
)
|
||||
|
||||
return ApiResponse(status=200, body={'result': result})
|
||||
|
||||
except Exception as e:
|
||||
ctx.logger.error(f"Proxy error: {e}")
|
||||
return ApiResponse(
|
||||
status=500,
|
||||
body={'error': 'Internal server error', 'details': str(e)}
|
||||
)
|
||||
61
steps/advoware_proxy/advoware_api_proxy_post_step.py
Normal file
61
steps/advoware_proxy/advoware_api_proxy_post_step.py
Normal file
@@ -0,0 +1,61 @@
|
||||
"""Advoware API Proxy - POST requests"""
|
||||
from typing import Any
|
||||
from motia import FlowContext, http, ApiRequest, ApiResponse
|
||||
from services.advoware import AdvowareAPI
|
||||
|
||||
|
||||
config = {
|
||||
"name": "Advoware Proxy POST",
|
||||
"description": "Universal proxy for Advoware API (POST requests)",
|
||||
"flows": ["advoware"],
|
||||
"triggers": [
|
||||
http("POST", "/advoware/proxy")
|
||||
],
|
||||
"enqueues": [],
|
||||
}
|
||||
|
||||
|
||||
async def handler(request: ApiRequest, ctx: FlowContext[Any]) -> ApiResponse:
|
||||
"""
|
||||
Proxy POST 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'}
|
||||
)
|
||||
|
||||
# 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
|
||||
|
||||
ctx.logger.info(f"Proxying POST request to Advoware: {endpoint}")
|
||||
result = await advoware.api_call(
|
||||
endpoint,
|
||||
method='POST',
|
||||
params=params,
|
||||
json_data=json_data
|
||||
)
|
||||
|
||||
return ApiResponse(status=200, body={'result': result})
|
||||
|
||||
except Exception as e:
|
||||
ctx.logger.error(f"Proxy error: {e}")
|
||||
return ApiResponse(
|
||||
status=500,
|
||||
body={'error': 'Internal server error', 'details': str(e)}
|
||||
)
|
||||
61
steps/advoware_proxy/advoware_api_proxy_put_step.py
Normal file
61
steps/advoware_proxy/advoware_api_proxy_put_step.py
Normal file
@@ -0,0 +1,61 @@
|
||||
"""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"],
|
||||
"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'}
|
||||
)
|
||||
|
||||
# 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
|
||||
|
||||
ctx.logger.info(f"Proxying PUT request to Advoware: {endpoint}")
|
||||
result = await advoware.api_call(
|
||||
endpoint,
|
||||
method='PUT',
|
||||
params=params,
|
||||
json_data=json_data
|
||||
)
|
||||
|
||||
return ApiResponse(status=200, body={'result': result})
|
||||
|
||||
except Exception as e:
|
||||
ctx.logger.error(f"Proxy error: {e}")
|
||||
return ApiResponse(
|
||||
status=500,
|
||||
body={'error': 'Internal server error', 'details': str(e)}
|
||||
)
|
||||
Reference in New Issue
Block a user