Skip to content

Commit 26e0c6e

Browse files
Add confirm_access method
1 parent 0164323 commit 26e0c6e

File tree

2 files changed

+17
-1
lines changed

2 files changed

+17
-1
lines changed

firefly_client/fc_utils.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,8 +64,8 @@ def ensure3(val, name):
6464
return ret
6565

6666

67-
# actions from Firefly
6867
ACTION_DICT = {
68+
# actions from Firefly JS
6969
'ShowFits': 'ImagePlotCntlr.PlotImage',
7070
'AddExtension': 'ExternalAccessCntlr/extensionAdd',
7171
'FetchTable': 'table.fetch',
@@ -95,6 +95,8 @@ def ensure3(val, name):
9595
'ShowHiPS': 'ImagePlotCntlr.PlotHiPS',
9696
'ShowImageOrHiPS': 'ImagePlotCntlr.plotHiPSOrImage',
9797
'ImagelineBasedFootprint': 'DrawLayerCntlr.ImageLineBasedFP.imagelineBasedFPCreate',
98+
99+
# actions from jupyter_firefly_extensions
98100
'StartLabWindow': 'StartLabWindow',
99101
'StartBrowserTab': 'StartBrowserTab'
100102
}

firefly_client/firefly_client.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -241,6 +241,7 @@ def __init__(self, url, channel, html_file=_def_html_file, token=None, viewer_ov
241241
token and ssl and self.session.headers.update(self.auth_headers)
242242
not ssl and token and warn('token ignored: should be None when url starts with http://')
243243
self.firefly_viewer = FireflyClient.get_viewer_mode(html_file,viewer_override)
244+
FireflyClient.confirm_access(url, token)
244245
debug('new instance: %s' % url)
245246

246247
def _lab_env_tab_start(self, tab_type, html_file):
@@ -273,6 +274,19 @@ def get_viewer_mode(html_file, viewer_override):
273274
return UNKNOWN
274275
else:
275276
return FireflyClient.SLATE_VIEWER if html_file == 'slate.html' else FireflyClient.TRIVIEW_VIEWER
277+
278+
@staticmethod
279+
def confirm_access(url, token):
280+
headers = {'Authorization': f'Bearer {token}'} if token else None
281+
healthz_url = url + ('healthz' if url.endswith('/') else '/healthz')
282+
response = requests.get(healthz_url, headers=headers, allow_redirects=False)
283+
if response.status_code == 200:
284+
return True
285+
else:
286+
raise ValueError(
287+
f"Access to {url} failed with status code {response.status_code}.\n"
288+
f"GET Headers: {response.headers}"
289+
)
276290

277291
def _send_url_as_get(self, url):
278292
return self.call_response(self.session.get(url, headers=self.header_from_ws))

0 commit comments

Comments
 (0)