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

#9 add ssl initialisation

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