Skip to content

Commit

Permalink
external dataservice v1
Browse files Browse the repository at this point in the history
  • Loading branch information
adrian-mih committed Mar 18, 2022
1 parent 5c9cf45 commit 515b814
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 0 deletions.
1 change: 1 addition & 0 deletions licenseware/report_components/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
from .base_report_component import BaseReportComponent
from .external_data_service import ExternalDataService
29 changes: 29 additions & 0 deletions licenseware/report_components/external_data_service.py
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit 515b814

Please sign in to comment.