diff --git a/licenseware/report_components/__init__.py b/licenseware/report_components/__init__.py index 5efa946b..51fb7d4f 100644 --- a/licenseware/report_components/__init__.py +++ b/licenseware/report_components/__init__.py @@ -1 +1,2 @@ from .base_report_component import BaseReportComponent +from .external_data_service import ExternalDataService \ No newline at end of file diff --git a/licenseware/report_components/external_data_service.py b/licenseware/report_components/external_data_service.py new file mode 100644 index 00000000..f6ab4ba5 --- /dev/null +++ b/licenseware/report_components/external_data_service.py @@ -0,0 +1,29 @@ +import requests +from licenseware.utils.logger import log + + +class ExternalDataService: + @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"), + } + if filter_payload: + data = requests.post( + url=service_url, headers=headers, json=filter_payload + ) + else: + data = requests.get(url=service_url, headers=headers) + + if data.status_code == 200: + return data.json() + else: + 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)) + return False \ No newline at end of file