Commit 08d6bd43 authored by Celine Noirot's avatar Celine Noirot
Browse files

#9 add ssl initialisation

parent 2d5ecc28
#
# Copyright (C) 2015 INRA
#
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
......@@ -128,18 +128,19 @@ class JFlowServer (object):
def get_browse_root_dir():
jflowconf = JFlowConfigReader()
return jflowconf.get_browse_root_dir()
@staticmethod
def quickstart(server_class, config=None, daemon=False):
# daemonize the server if asked to
if daemon:
from cherrypy.process.plugins import Daemonizer
Daemonizer(cherrypy.engine).subscribe()
# define the socket host and port
jflowconf = JFlowConfigReader()
socket_opts = jflowconf.get_socket_options()
ssl_opts = jflowconf.get_ssl_files()
# add the result directory
if config is None or not '/' in config:
......@@ -148,21 +149,21 @@ class JFlowServer (object):
link = os.path.join(config['/']['tools.staticdir.root'], "data")
if not os.path.islink(link):
os.symlink(jflowconf.get_work_directory(), link)
config[os.path.join('/', JFlowServer.JFLOW_WDATA)] = {'tools.staticdir.on' : True,
'tools.staticdir.dir' : jflowconf.get_work_directory()}
# remove any limit on the request body size; cherrypy's default is 100MB
# (maybe we should just increase it ?)
cherrypy.server.max_request_body_size = 0
# increase server socket timeout to 60s; we are more tolerant of bad
# quality client-server connections (cherrypy's default is 10s)
cherrypy.server.socket_timeout = 60
cherrypy.config.update({'server.socket_host': socket_opts[0],
'server.socket_port': socket_opts[1]})
if len(ssl_opts)==3:
cherrypy.config.update({'server.ssl_module': 'builtin',
'server.ssl_certificate': ssl_opts[0],
......@@ -170,7 +171,7 @@ class JFlowServer (object):
'server.ssl_private_key': ssl_opts[2]})
# start the server
cherrypy.quickstart(server_class(), config=config)
def jsonify(func):
'''JSON and JSONP decorator for CherryPy'''
@wraps(func)
......@@ -178,7 +179,7 @@ class JFlowServer (object):
value = func(*args, **kw)
cherrypy.response.headers["Content-Type"] = "application/json"
# if JSONP request
if "callback" in kw:
if "callback" in kw:
return ('%s(%s)' % (kw["callback"], json.dumps(value, cls=JFlowJSONEncoder))).encode('utf8')
# else return the JSON
else: return json.dumps(value, cls=JFlowJSONEncoder).encode('utf8')
......@@ -476,7 +477,7 @@ class JFlowServer (object):
elif Workflow.INPUTFILES_GRAPH_LABEL in g.node_attributes(node):
nodes.append({"name": node, "display_name": g.node_attributes(node)[1], "type": "inputfiles"})
elif Workflow.INPUTDIRECTORY_GRAPH_LABEL in g.node_attributes(node):
nodes.append({"name": node, "display_name": g.node_attributes(node)[1], "type": "inputdirectory"})
nodes.append({"name": node, "display_name": g.node_attributes(node)[1], "type": "inputdirectory"})
elif Workflow.COMPONENT_GRAPH_LABEL in g.node_attributes(node):
nodes.append({"name": node, "display_name": g.node_attributes(node)[1], "type": "component"})
status["nodes"] = nodes
......@@ -485,7 +486,7 @@ class JFlowServer (object):
def __update_kwargs(self, kwargs):
kwargs_modified = {}
# handle MultiParameterList
multi_sub_params = {}
for key in list(kwargs.keys()):
......@@ -522,7 +523,7 @@ class JFlowServer (object):
kwargs_modified[param].append(multi_sub_params[param][sub_param])
return kwargs_modified
def _webify_outputs(self, web_path, path):
work_dir = self.jflow_config_reader.get_work_directory()
......@@ -556,7 +557,7 @@ class JFlowServer (object):
try:
value_key = None
for key in list(kwargs.keys()):
if key != "type" and key != "callback" and key != "_" and key != "action":
if key != "type" and key != "callback" and key != "_" and key != "action":
value_key = key
break
# if it's an append parameter, let's check each value
......@@ -602,4 +603,3 @@ class JFlowServer (object):
r.append('Could not load directory: %s' % str(e))
r.append('</ul>')
return ''.join(r)
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment