Skip to content

Commit

Permalink
use type for components & grab component url from registry service
Browse files Browse the repository at this point in the history
  • Loading branch information
adrian-mih committed Mar 21, 2022
1 parent 515b814 commit 73f89f7
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 4 deletions.
2 changes: 1 addition & 1 deletion licenseware/app_builder/app_builder.py
Original file line number Diff line number Diff line change
Expand Up @@ -396,7 +396,7 @@ def register_app(self):
'style_attributes',
'attributes',
'title',
'component_type',
'type',
'filters'
]
}
Expand Down
33 changes: 30 additions & 3 deletions licenseware/report_components/external_data_service.py
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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

0 comments on commit 73f89f7

Please sign in to comment.