-
Notifications
You must be signed in to change notification settings - Fork 20
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #274 from CybercentreCanada/hotfix/discover
Publish discover_url in whoami api
- Loading branch information
Showing
3 changed files
with
58 additions
and
1 deletion.
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
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
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,38 @@ | ||
import logging | ||
import requests | ||
|
||
from assemblyline.common import forge | ||
config = forge.get_config() | ||
logger = logging.getLogger('assemblyline.ui') | ||
|
||
|
||
def get_apps_list(): | ||
apps = {'apps': []} | ||
if config.ui.discover_url: | ||
try: | ||
resp = requests.get(config.ui.discover_url, headers={'accept': 'application/json'}, timeout=5) | ||
if resp.ok: | ||
data = resp.json() | ||
for app in data['applications']['application']: | ||
try: | ||
url = app['instance'][0]['hostName'] | ||
|
||
if config.ui.fqdn not in url: | ||
apps['apps'].append( | ||
{ | ||
"alt": app['instance'][0]['metadata']['alternateText'], | ||
"name": app['name'], | ||
"img_d": app['instance'][0]['metadata']['imageDark'], | ||
"img_l": app['instance'][0]['metadata']['imageLight'], | ||
"route": url, | ||
"classification": app['instance'][0]['metadata']['classification'] | ||
} | ||
) | ||
except Exception: | ||
logger.exception(f'Failed to parse get app: {str(app)}') | ||
else: | ||
logger.warning(f'Invalid response from server for apps discovery: {config.ui.discover_url}') | ||
except Exception: | ||
logger.exception(f'Failed to get apps from discover URL: {config.ui.discover_url}') | ||
|
||
return apps |