How to access the jupyterhub config in a custom authenticator

201 views
Skip to first unread message

Ted Liefeld

unread,
Aug 5, 2016, 5:41:31 PM8/5/16
to Project Jupyter
I have created a custom authenticator and I would like to paramaterize a few bits of it but I am struggling to understand how to get a hold of the populated ConfigManager instance from the Jupyterhub.

I tried adding
     from notebook.services.config import ConfigManager
and then
    cm = ConfigManager()
    print("Config is " , cm.get("JupyterHub"))

thinking this would get me the values for the "JupyterHub" section which I know has entries that are being used.  This is always coming back empty though.  I figure I need to get the populated instance from the JupyterHub application but I can't quite figure out how to get my hands on it.

I also looked at the OAuth authenticator thinking it did the same thing, but it only ever does things like this
    os.getenv('OAUTH_CALLBACK_URL', '')
which is surprising since from the docs it looks like it puts params in the file


Ted Liefeld

unread,
Aug 5, 2016, 6:08:12 PM8/5/16
to Project Jupyter
Answering myself again (to put this in the record for the next person)...

This seems to work

from jupyterhub.app import JupyterHub
                hub = JupyterHub(parent=self)
                hub.load_config_file(hub.config_file)
                print("Config is " , hub.config)

MinRK

unread,
Aug 8, 2016, 8:50:44 AM8/8/16
to Project Jupyter

There is no ConfigManager in JupyterHub. That’s strictly for client-side nbextensions in the single-user server.

Once your Authenticator is instantiated, the config is loaded as self.config. That said, you shouldn’t ever need to access the config object directly. Configuration is done through traitlets. Once you have declared the configurable traits with .tag(config=True), you can set them in your config file and instantiation takes care of the rest:

from traitlets import Unicode
from jupyterhub.auth import Authenticator

class MyAuthenticator(Authenticator):
    thing = Unicode('default', help='helpful info').tag(config=True)

then in your jupyterhub_config.py, set this value:

c.MyAuthenticator.thing = 'not the default'

-MinRK


--
You received this message because you are subscribed to the Google Groups "Project Jupyter" group.
To unsubscribe from this group and stop receiving emails from it, send an email to jupyter+unsubscribe@googlegroups.com.
To post to this group, send email to jup...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/jupyter/44d3543d-816a-4e6a-a9b8-94a06ba5045f%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Ted Liefeld

unread,
Aug 8, 2016, 5:22:32 PM8/8/16
to Project Jupyter
Thanks, that did the trick...

Ted


On Monday, August 8, 2016 at 5:50:44 AM UTC-7, Min RK wrote:

There is no ConfigManager in JupyterHub. That’s strictly for client-side nbextensions in the single-user server.

Once your Authenticator is instantiated, the config is loaded as self.config. That said, you shouldn’t ever need to access the config object directly. Configuration is done through traitlets. Once you have declared the configurable traits with .tag(config=True), you can set them in your config file and instantiation takes care of the rest:

from traitlets import Unicode
from jupyterhub.auth import Authenticator

class MyAuthenticator(Authenticator):
    thing = Unicode('default', help='helpful info').tag(config=True)

then in your jupyterhub_config.py, set this value:

c.MyAuthenticator.thing = 'not the default'

-MinRK

On Fri, Aug 5, 2016 at 11:41 PM, Ted Liefeld <lie...@broadinstitute.org> wrote:
I have created a custom authenticator and I would like to paramaterize a few bits of it but I am struggling to understand how to get a hold of the populated ConfigManager instance from the Jupyterhub.

I tried adding
     from notebook.services.config import ConfigManager
and then
    cm = ConfigManager()
    print("Config is " , cm.get("JupyterHub"))

thinking this would get me the values for the "JupyterHub" section which I know has entries that are being used.  This is always coming back empty though.  I figure I need to get the populated instance from the JupyterHub application but I can't quite figure out how to get my hands on it.

I also looked at the OAuth authenticator thinking it did the same thing, but it only ever does things like this
    os.getenv('OAUTH_CALLBACK_URL', '')
which is surprising since from the docs it looks like it puts params in the file


--
You received this message because you are subscribed to the Google Groups "Project Jupyter" group.
To unsubscribe from this group and stop receiving emails from it, send an email to jupyter+u...@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages