From 73f89f708f401725b1b0f65e39c3a522eb898d2b Mon Sep 17 00:00:00 2001 From: Adrian Mihalache Date: Mon, 21 Mar 2022 16:36:13 +0200 Subject: [PATCH] use type for components & grab component url from registry service --- licenseware/app_builder/app_builder.py | 2 +- .../external_data_service.py | 33 +++++++++++++++++-- 2 files changed, 31 insertions(+), 4 deletions(-) diff --git a/licenseware/app_builder/app_builder.py b/licenseware/app_builder/app_builder.py index e11ef275..b9d5a890 100644 --- a/licenseware/app_builder/app_builder.py +++ b/licenseware/app_builder/app_builder.py @@ -396,7 +396,7 @@ def register_app(self): 'style_attributes', 'attributes', 'title', - 'component_type', + 'type', 'filters' ] } diff --git a/licenseware/report_components/external_data_service.py b/licenseware/report_components/external_data_service.py index f6ab4ba5..9299de3c 100644 --- a/licenseware/report_components/external_data_service.py +++ b/licenseware/report_components/external_data_service.py @@ -1,16 +1,43 @@ import requests +import traceback +import os + from licenseware.utils.logger import log class ExternalDataService: + @staticmethod + def _get_all_components(headers): + registry_service_url = os.get("REGISTRY_SERVICE_URL") + try: + comp_data = requests.get( + url=f"{registry_service_url}/components" + ) + return comp_data.json() + except Exception: + log.error(traceback.format_exc()) + + + @staticmethod + def _get_component_url(components, app_id, component_id): + return [d['url'] for d in components if d['app_id'] == app_id and d['component_id'] == component_id][0] + + @staticmethod def get_data(_request, app_id, component_id, filter_payload=None): try: - service_url = f"http://kong/{app_id}/report-components/{component_id}" headers = { "TenantId": _request.headers.get("TenantId"), "Authorization": _request.headers.get("Authorization"), } + + registry_service_components = ExternalDataService._get_all_components(headers) + service_url = ExternalDataService._get_component_url( + components=registry_service_components, + app_id=app_id, + component_id=component_id + ) + if filter_payload: data = requests.post( url=service_url, headers=headers, json=filter_payload @@ -24,6 +51,6 @@ def get_data(_request, app_id, component_id, filter_payload=None): log.warning(f"Could not retrieve data for {component_id} from {app_id}") log.warning(f"GET {service_url} {data.status_code}") return [] - except Exception as e: - log.exception(str(e)) + except Exception: + log.error(traceback.format_exc()) return False \ No newline at end of file