Skip to content

Commit

Permalink
simplified, get Jupyterhub user from environment variable
Browse files Browse the repository at this point in the history
  • Loading branch information
zonca committed Sep 19, 2017
1 parent 3256d58 commit 10be8f4
Showing 1 changed file with 7 additions and 15 deletions.
22 changes: 7 additions & 15 deletions nbgrader/exchange/exchange.py
Original file line number Diff line number Diff line change
Expand Up @@ -133,27 +133,19 @@ def get_current_user_courses(self):

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 nbgrader. Did you launch it manually?")
else:
self.exit("JUPYTERHUB_API_TOKEN env is required to run the exchange features of nbgrader.")
hub_api_url = os.environ.get('JUPYTERHUB_API_URL') or 'http://127.0.0.1:8081/hub/api'
base_url = os.environ.get('JUPYTERHUB_SERVICE_PREFIX') or '/'
hub_prefix = base_url + "hub/"
self.hub_auth = HubOAuth(
parent=self,
api_token=api_token,
api_url=hub_api_url,
hub_prefix=hub_prefix,
base_url=base_url,
)
if os.getenv('JUPYTERHUB_USER'):
user = os.environ['JUPYTERHUB_USER']
else:
self.exit("JUPYTERHUB_USER env is required to run the exchange features of nbgrader.")
import json
# smoke check
if not self.hub_auth.oauth_client_id:
raise ValueError("Missing OAuth client ID")
auth_header = {
'Authorization': 'token %s' % api_token
}
client = HTTPClient()
req = HTTPRequest(url=hub_api_url + '/users/%s' % self.hub_auth.oauth_client_id.replace('user-', ''),
req = HTTPRequest(url=hub_api_url + '/users/%s' % user,
method='GET',
headers=auth_header,
)
Expand Down

0 comments on commit 10be8f4

Please sign in to comment.