Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Append any URL query args to dashboard URL paths #258

Merged
merged 3 commits into from
Feb 19, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 17 additions & 1 deletion dask_labextension/dashboardhandler.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,14 +29,22 @@ async def get(self, url) -> None:
try:
client = httpclient.AsyncHTTPClient()

# Extract query (if any) from URL, this will then be appended after path.
# This allows using (eg) "?token=[...]" in URL for authentication.
if "?" in url:
pos = url.find("?")
url, query = url[:pos], url[pos:]
else:
query = ""

# First check for the individual-plots endpoint at user-provided url.
# We don't check for the root URL because that can trigger a lot of
# object creation in the bokeh document.
url = _normalize_dashboard_link(parse.unquote(url), self.request)
effective_url = None
individual_plots_url = url_path_join(
url,
"individual-plots.json",
f"individual-plots.json{query}",
)
try:
self.log.debug(
Expand Down Expand Up @@ -73,6 +81,14 @@ async def get(self, url) -> None:

individual_plots = json.loads(individual_plots_response.body)

# If there was query in original URL, append to URLs returned
if query:
for name, plot_url in individual_plots.items():
individual_plots[name] = f"{plot_url}{query}"
url = f"{url}{query}"
if effective_url:
effective_url = f"{effective_url}{query}"

self.set_status(200)
self.finish(
json.dumps(
Expand Down