Clean up Advoware proxy steps: remove redundant /api/ from paths, simplify method-specific code, and fix DELETE json_data
This commit is contained in:
@@ -1,31 +0,0 @@
|
|||||||
from services.advoware import AdvowareAPI
|
|
||||||
|
|
||||||
config = {
|
|
||||||
'type': 'api',
|
|
||||||
'name': 'Advoware Proxy',
|
|
||||||
'description': 'Universal proxy for Advoware API',
|
|
||||||
'path': '/api/advoware/proxy',
|
|
||||||
'method': 'GET',
|
|
||||||
'emits': [],
|
|
||||||
'flows': ['advoware']
|
|
||||||
}
|
|
||||||
|
|
||||||
async def handler(req, context):
|
|
||||||
try:
|
|
||||||
# Endpoint aus Query-Parametern
|
|
||||||
endpoint = req.get('queryParams', {}).get('endpoint', '')
|
|
||||||
if not endpoint:
|
|
||||||
return {'status': 400, 'body': {'error': 'Endpoint required as query param'}}
|
|
||||||
|
|
||||||
advoware = AdvowareAPI(context)
|
|
||||||
method = req.get('method', 'GET')
|
|
||||||
params = {k: v for k, v in req.get('queryParams', {}).items() if k != 'endpoint'}
|
|
||||||
json_data = req.get('body') if method in ['POST', 'PUT', 'PATCH'] else None
|
|
||||||
|
|
||||||
context.logger.info(f"Proxying request to Advoware: {method} {endpoint}")
|
|
||||||
result = await advoware.api_call(endpoint, method=method, params=params, json_data=json_data)
|
|
||||||
|
|
||||||
return {'status': 200, 'body': {'result': result}}
|
|
||||||
except Exception as e:
|
|
||||||
context.logger.error(f"Proxy error: {e}")
|
|
||||||
return {'status': 500, 'body': {'error': 'Internal server error', 'details': str(e)}}
|
|
||||||
@@ -4,7 +4,7 @@ config = {
|
|||||||
'type': 'api',
|
'type': 'api',
|
||||||
'name': 'Advoware Proxy DELETE',
|
'name': 'Advoware Proxy DELETE',
|
||||||
'description': 'Universal proxy for Advoware API (DELETE)',
|
'description': 'Universal proxy for Advoware API (DELETE)',
|
||||||
'path': '/api/advoware/proxy/delete',
|
'path': '/advoware/proxy',
|
||||||
'method': 'DELETE',
|
'method': 'DELETE',
|
||||||
'emits': [],
|
'emits': [],
|
||||||
'flows': ['advoware']
|
'flows': ['advoware']
|
||||||
@@ -20,7 +20,7 @@ async def handler(req, context):
|
|||||||
advoware = AdvowareAPI(context)
|
advoware = AdvowareAPI(context)
|
||||||
method = 'DELETE' # Feste Methode für diesen Step
|
method = 'DELETE' # Feste Methode für diesen Step
|
||||||
params = {k: v for k, v in req.get('queryParams', {}).items() if k != 'endpoint'}
|
params = {k: v for k, v in req.get('queryParams', {}).items() if k != 'endpoint'}
|
||||||
json_data = req.get('body')
|
json_data = None
|
||||||
|
|
||||||
context.logger.info(f"Proxying request to Advoware: {method} {endpoint}")
|
context.logger.info(f"Proxying request to Advoware: {method} {endpoint}")
|
||||||
result = await advoware.api_call(endpoint, method=method, params=params, json_data=json_data)
|
result = await advoware.api_call(endpoint, method=method, params=params, json_data=json_data)
|
||||||
|
|||||||
@@ -4,7 +4,7 @@ config = {
|
|||||||
'type': 'api',
|
'type': 'api',
|
||||||
'name': 'Advoware Proxy GET',
|
'name': 'Advoware Proxy GET',
|
||||||
'description': 'Universal proxy for Advoware API (GET)',
|
'description': 'Universal proxy for Advoware API (GET)',
|
||||||
'path': '/api/advoware/proxy',
|
'path': '/advoware/proxy',
|
||||||
'method': 'GET',
|
'method': 'GET',
|
||||||
'emits': [],
|
'emits': [],
|
||||||
'flows': ['advoware']
|
'flows': ['advoware']
|
||||||
@@ -18,9 +18,9 @@ async def handler(req, context):
|
|||||||
return {'status': 400, 'body': {'error': 'Endpoint required as query param'}}
|
return {'status': 400, 'body': {'error': 'Endpoint required as query param'}}
|
||||||
|
|
||||||
advoware = AdvowareAPI(context)
|
advoware = AdvowareAPI(context)
|
||||||
method = req.get('method', 'GET')
|
method = 'GET'
|
||||||
params = {k: v for k, v in req.get('queryParams', {}).items() if k != 'endpoint'}
|
params = {k: v for k, v in req.get('queryParams', {}).items() if k != 'endpoint'}
|
||||||
json_data = req.get('body') if method in ['POST', 'PUT', 'PATCH'] else None
|
json_data = None
|
||||||
|
|
||||||
context.logger.info(f"Proxying request to Advoware: {method} {endpoint}")
|
context.logger.info(f"Proxying request to Advoware: {method} {endpoint}")
|
||||||
result = await advoware.api_call(endpoint, method=method, params=params, json_data=json_data)
|
result = await advoware.api_call(endpoint, method=method, params=params, json_data=json_data)
|
||||||
@@ -28,4 +28,4 @@ async def handler(req, context):
|
|||||||
return {'status': 200, 'body': {'result': result}}
|
return {'status': 200, 'body': {'result': result}}
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
context.logger.error(f"Proxy error: {e}")
|
context.logger.error(f"Proxy error: {e}")
|
||||||
return {'status': 500, 'body': {'error': 'Internal server error', 'details': str(e)}}
|
return {'status': 500, 'body': {'error': 'Internal server error', 'details': str(e)}}
|
||||||
|
|||||||
@@ -4,7 +4,7 @@ config = {
|
|||||||
'type': 'api',
|
'type': 'api',
|
||||||
'name': 'Advoware Proxy POST',
|
'name': 'Advoware Proxy POST',
|
||||||
'description': 'Universal proxy for Advoware API (POST)',
|
'description': 'Universal proxy for Advoware API (POST)',
|
||||||
'path': '/api/advoware/proxy/post',
|
'path': '/advoware/proxy',
|
||||||
'method': 'POST',
|
'method': 'POST',
|
||||||
'emits': [],
|
'emits': [],
|
||||||
'flows': ['advoware']
|
'flows': ['advoware']
|
||||||
|
|||||||
@@ -4,7 +4,7 @@ config = {
|
|||||||
'type': 'api',
|
'type': 'api',
|
||||||
'name': 'Advoware Proxy PUT',
|
'name': 'Advoware Proxy PUT',
|
||||||
'description': 'Universal proxy for Advoware API (PUT)',
|
'description': 'Universal proxy for Advoware API (PUT)',
|
||||||
'path': '/api/advoware/proxy/put',
|
'path': '/advoware/proxy',
|
||||||
'method': 'PUT',
|
'method': 'PUT',
|
||||||
'emits': [],
|
'emits': [],
|
||||||
'flows': ['advoware']
|
'flows': ['advoware']
|
||||||
|
|||||||
Reference in New Issue
Block a user