-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
5c9cf45
commit 515b814
Showing
2 changed files
with
30 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |