mirror of
https://github.com/jupyterhub/jupyterhub.git
synced 2025-10-08 18:44:10 +00:00
add full URLs to share modes
- full_url for SharedServer - full_accept_url for ShareCode
This commit is contained in:
@@ -1176,8 +1176,16 @@ paths:
|
|||||||
example: abc123
|
example: abc123
|
||||||
accept_url:
|
accept_url:
|
||||||
type: string
|
type: string
|
||||||
description: The URL for accepting the code
|
description: The URL path for accepting the code
|
||||||
example: /hub/accept-share?code=abc123
|
example: /hub/accept-share?code=abc123
|
||||||
|
full_accept_url:
|
||||||
|
type:
|
||||||
|
- string
|
||||||
|
- "null"
|
||||||
|
description: |
|
||||||
|
The full URL for accepting the code,
|
||||||
|
if JupyterHub.public_url configuration is defined.
|
||||||
|
example: https://hub.example.org/hub/accept-share?code=abc123
|
||||||
security:
|
security:
|
||||||
- oauth2:
|
- oauth2:
|
||||||
- shares
|
- shares
|
||||||
@@ -1877,7 +1885,14 @@ components:
|
|||||||
description: the server name. '' for the default server.
|
description: the server name. '' for the default server.
|
||||||
url:
|
url:
|
||||||
type: string
|
type: string
|
||||||
description: the server's URL
|
description: the server's URL (path only when not using subdomains)
|
||||||
|
full_url:
|
||||||
|
type:
|
||||||
|
- string
|
||||||
|
- "null"
|
||||||
|
description: |
|
||||||
|
The full URL of the server (`https://hub.example.org/user/:name/:servername`).
|
||||||
|
`null` unless JupyterHub.public_url or subdomains are configured.
|
||||||
ready:
|
ready:
|
||||||
type: boolean
|
type: boolean
|
||||||
description: whether the server is ready
|
description: whether the server is ready
|
||||||
|
@@ -286,6 +286,7 @@ The response contains the code itself:
|
|||||||
{
|
{
|
||||||
"code": "abc1234....",
|
"code": "abc1234....",
|
||||||
"accept_url": "/hub/accept-share?code=abc1234",
|
"accept_url": "/hub/accept-share?code=abc1234",
|
||||||
|
"full_accept_url": "https://hub.example.org/hub/accept-share?code=abc1234",
|
||||||
"id": "sc_1234",
|
"id": "sc_1234",
|
||||||
"scopes": [...],
|
"scopes": [...],
|
||||||
...
|
...
|
||||||
|
@@ -159,11 +159,14 @@ which will have a JSON response:
|
|||||||
'last_exchanged_at': None,
|
'last_exchanged_at': None,
|
||||||
'code': 'U-eYLFT1lGstEqfMHpAIvTZ1MRjZ1Y1a-loGQ0K86to',
|
'code': 'U-eYLFT1lGstEqfMHpAIvTZ1MRjZ1Y1a-loGQ0K86to',
|
||||||
'accept_url': '/hub/accept-share?code=U-eYLFT1lGstEqfMHpAIvTZ1MRjZ1Y1a-loGQ0K86to',
|
'accept_url': '/hub/accept-share?code=U-eYLFT1lGstEqfMHpAIvTZ1MRjZ1Y1a-loGQ0K86to',
|
||||||
|
'full_accept_url': 'https://hub.example.org/accept-share?code=U-eYLFT1lGstEqfMHpAIvTZ1MRjZ1Y1a-loGQ0K86to',
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
The most relevant fields here are `code`, which contains the code itself, and `accept_url`, which is the URL path for the page another user.
|
The most relevant fields here are `code`, which contains the code itself, and `accept_url`, which is the URL path for the page another user.
|
||||||
Note: it does not contain the _hostname_ of the hub, which JupyterHub often does not know.
|
Note: it does not contain the _hostname_ of the hub, which JupyterHub often does not know.
|
||||||
|
If `public_url` configuration is defined, `full_accept_url` will be the full URL including the host.
|
||||||
|
Otherwise, it will be null.
|
||||||
|
|
||||||
Share codes are guaranteed to be url-safe, so no encoding is required.
|
Share codes are guaranteed to be url-safe, so no encoding is required.
|
||||||
|
|
||||||
|
@@ -5,6 +5,7 @@
|
|||||||
import json
|
import json
|
||||||
import re
|
import re
|
||||||
from typing import List, Optional
|
from typing import List, Optional
|
||||||
|
from urllib.parse import urlunparse
|
||||||
|
|
||||||
from pydantic import (
|
from pydantic import (
|
||||||
BaseModel,
|
BaseModel,
|
||||||
@@ -95,7 +96,7 @@ class _ShareAPIHandler(APIHandler):
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
# subset keys for sharing
|
# subset keys for sharing
|
||||||
for key in ["name", "url", "ready"]:
|
for key in ["name", "url", "full_url", "ready"]:
|
||||||
if key in full_model:
|
if key in full_model:
|
||||||
server_model[key] = full_model[key]
|
server_model[key] = full_model[key]
|
||||||
|
|
||||||
@@ -128,6 +129,12 @@ class _ShareAPIHandler(APIHandler):
|
|||||||
model["accept_url"] = url_concat(
|
model["accept_url"] = url_concat(
|
||||||
self.hub.base_url + "accept-share", {"code": code}
|
self.hub.base_url + "accept-share", {"code": code}
|
||||||
)
|
)
|
||||||
|
model["full_accept_url"] = None
|
||||||
|
public_url = self.settings.get("public_url")
|
||||||
|
if public_url:
|
||||||
|
model["full_accept_url"] = urlunparse(
|
||||||
|
public_url._replace(path=model["accept_url"])
|
||||||
|
)
|
||||||
return model
|
return model
|
||||||
|
|
||||||
def _init_share_query(self, kind="share"):
|
def _init_share_query(self, kind="share"):
|
||||||
|
Reference in New Issue
Block a user