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

139 remove ipgetter #140

Open
wants to merge 4 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
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
73 changes: 39 additions & 34 deletions jupyterhub_rest_server/jupyterhub_rest_server/handlers.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,42 +4,46 @@
import logging
import tornado.auth
import shutil
import ipgetter

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

so, this is just removing an unused library and formatting changes?

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The ipgetter module no longer exists, so this dependency breaks the build. It is also not used, so removing it does not affect anything.

from . import utilities

from tornado.log import enable_pretty_logging
enable_pretty_logging()


args = [
['husername',
'HydroShare username. This is used to build an isolated userspace on the JupyterHub server',
'Yes',
'Example: TonyCastronova'],
['resourcetype',
'The type of HydroShare resource being sent to JupyterHub. Typically used when launching JupyterHub instances from HydroShare',
'No',
'Example: GenericResource'],
['resourceid',
'The unique id of the a HydroShare resource. Typically used when launching JupyterHub instances from HydroShare',
'No',
'Example: 97add6638f7841278c73519e7192b252'],
['target',
'Target notebook to launch relative to http://[jupyteraddress]/user/[husername]/tree/. This argument is designed to support applications that wish to provide a more customized user experience.',
'No',
'Example: notebooks/Welcome.ipynb'],
['husername',
'HydroShare username. This is used to build an '
'isolated userspace on the JupyterHub server',
'Yes',
'Example: TonyCastronova'],
['resourcetype',
'The type of HydroShare resource being sent to JupyterHub. '
'Typically used when launching JupyterHub instances from HydroShare',
'No',
'Example: GenericResource'],
['resourceid',
'The unique id of the a HydroShare resource. '
'Typically used when launching JupyterHub instances from HydroShare',
'No',
'Example: 97add6638f7841278c73519e7192b252'],
['target',
'Target notebook to launch relative to '
'http://[jupyteraddress]/user/[husername]/tree/. This argument is '
'designed to support applications that wish to provide a '
'more customized user experience.',
'No',
'Example: notebooks/Welcome.ipynb'],
]
header = ['Function', 'Description', 'Required']


class RequestHandler(tornado.web.RequestHandler):
# def __init_(self):
errors = []
# super(RequestHandler, self)

def get_or_error(self, argname, strip=True):
"""
This function gets a REST input argument or returns an error message if the argument is not found
This function gets a REST input argument or returns an error message
if the argument is not found
Arguments:
argname -- the name of the argument to get
strip -- indicates if the whitespace will be stripped from the argument
Expand All @@ -56,20 +60,24 @@ def get_arg_value(self, argname, isrequired, strip=True):
error = 'Could not find required parameter "%s"' % argname
self.errors.append(error)
return arg

def check_for_errors(self):
if len(self.errors) > 0:
self.render("index.html", header=header, args=args, error=self.errors)
self.render("index.html", header=header,
args=args, error=self.errors)
return 1
else:
return 0


class IndexHandler(RequestHandler, tornado.auth.OAuth2Mixin):

def get(self):
self.render("index.html", header=header, args=args)


class JupyterHandler(RequestHandler, tornado.auth.OAuth2Mixin):

def get(self):

# get arguments from the query string.
Expand All @@ -90,43 +98,40 @@ def get(self):
# build userspace
try:
msg = '%s -> building userspace' % husername
print(msg)
utilities.build_userspace(username)
except Exception as e:
print('ERROR %s: %s' % (msg, e))

print('HERE')
try:
msg = '%s -> writing .env' % husername
print(msg)
utilities.set_hydroshare_args(husername, resourceid, resourcetype)
except Exception as e:
print('ERROR %s: %s' % (msg, e), flush=True)

# generate the redirect url
baseurl = os.environ['JUPYTER_HUB_IP']
port = os.environ['JUPYTER_PORT']
# build the redirect url

# build the redirect url
if port == '443':
proto = 'https'
port = ''
else:
proto = 'http'
port = ':'+port

if target is not None:
url = "%s://%s%s/user/%s/tree/%s" % (proto, baseurl, port, username, target)
url = "%s://%s%s/user/%s/tree/%s" % \
(proto, baseurl, port, username, target)
else:
url = "%s://%s%s/user/%s/tree/notebooks/Welcome.ipynb" % (proto, baseurl, port, username)

print("URL:" + url)
url = "%s://%s%s/user/%s/tree/notebooks/Welcome.ipynb" % \
(proto, baseurl, port, username)

# save the next url to ensure that the redirect will work
p = os.path.join(os.environ['HYDROSHARE_REDIRECT_COOKIE_PATH'], '.redirect_%s' % username)
p = os.path.join(os.environ['HYDROSHARE_REDIRECT_COOKIE_PATH'],
'.redirect_%s' % username)
with open(p, 'w') as f:
f.write(url)

# redirect to the desired page
self.redirect(url, status=303)

1 change: 0 additions & 1 deletion jupyterhub_rest_server/requirements.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
appdirs==1.4.2
ipgetter==0.6
packaging==16.8
pkg-resources==0.0.0
pyparsing==2.1.10
Expand Down
1 change: 0 additions & 1 deletion jupyterhub_rest_server/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
packages=['jupyterhub_rest_server'],
install_requires= [
'appdirs==1.4.2',
'ipgetter==0.6',
'pyparsing==2.1.10',
'six==1.10.0',
'tornado==4.4.2'
Expand Down