diff --git a/jupyterhub/singleuser.py b/jupyterhub/singleuser.py index fb13f694..6366f700 100755 --- a/jupyterhub/singleuser.py +++ b/jupyterhub/singleuser.py @@ -39,22 +39,26 @@ from jupyterhub import __version__ from .services.auth import HubAuth, HubAuthenticated from .utils import url_path_join + # Authenticate requests with the Hub + class HubAuthenticatedHandler(HubAuthenticated): """Class we are going to patch-in for authentication with the Hub""" @property def hub_auth(self): return self.settings['hub_auth'] + @property def hub_users(self): return { self.settings['user'] } + @property def hub_groups(self): if self.settings['group']: return { self.settings['group'] } return set() - + class JupyterHubLoginHandler(LoginHandler): """LoginHandler that hooks up Hub authentication""" @@ -90,7 +94,7 @@ class JupyterHubLogoutHandler(LogoutHandler): # register new hub related command-line aliases aliases = dict(notebook_aliases) aliases.update({ - 'user' : 'SingleUserNotebookApp.user', + 'user': 'SingleUserNotebookApp.user', 'group': 'SingleUserNotebookApp.group', 'cookie-name': 'HubAuth.cookie_name', 'hub-prefix': 'SingleUserNotebookApp.hub_prefix', @@ -124,6 +128,7 @@ Control Panel {% endblock logo %} """ + def _exclude_home(path_list): """Filter out any entries in a path list that are in my home directory. @@ -139,10 +144,10 @@ class SingleUserNotebookApp(NotebookApp): """A Subclass of the regular NotebookApp that is aware of the parent multiuser context.""" description = dedent(""" Single-user server for JupyterHub. Extends the Jupyter Notebook server. - + Meant to be invoked by JupyterHub Spawners, and not directly. """) - + examples = "" subcommands = {} version = __version__ @@ -150,6 +155,7 @@ class SingleUserNotebookApp(NotebookApp): user = CUnicode().tag(config=True) group = CUnicode().tag(config=True) + @observe('user') def _user_changed(self, change): self.log.name = change.new @@ -157,12 +163,14 @@ class SingleUserNotebookApp(NotebookApp): hub_host = Unicode().tag(config=True) hub_prefix = Unicode('/hub/').tag(config=True) + @default('hub_prefix') def _hub_prefix_default(self): base_url = os.environ.get('JUPYTERHUB_BASE_URL') or '/' return base_url + 'hub/' hub_api_url = Unicode().tag(config=True) + @default('hub_api_url') def _hub_api_url_default(self): return os.environ.get('JUPYTERHUB_API_URL') or 'http://127.0.0.1:8081/hub/api' @@ -199,7 +207,7 @@ class SingleUserNotebookApp(NotebookApp): trust_xheaders = True login_handler_class = JupyterHubLoginHandler logout_handler_class = JupyterHubLogoutHandler - port_retries = 0 # disable port-retries, since the Spawner will tell us what port to use + port_retries = 0 # disable port-retries, since the Spawner will tell us what port to use disable_user_config = Bool(False, help="""Disable user configuration of single-user server. @@ -280,7 +288,7 @@ class SingleUserNotebookApp(NotebookApp): api_token = os.environ['JPY_API_TOKEN'] if os.getenv('JUPYTERHUB_API_TOKEN'): api_token = os.environ['JUPYTERHUB_API_TOKEN'] - + if not api_token: self.exit("JUPYTERHUB_API_TOKEN env is required to run jupyterhub-singleuser. Did you launch it manually?") self.hub_auth = HubAuth(