app: Add configparser support
Signed-off-by: Eric Callahan <arksine.code@gmail.com>
This commit is contained in:
parent
7a94fb3a6b
commit
de462b1d0f
|
@ -21,7 +21,7 @@ MAX_UPLOAD_SIZE = 200 * 1024 * 1024
|
||||||
# These endpoints are reserved for klippy/server communication only and are
|
# These endpoints are reserved for klippy/server communication only and are
|
||||||
# not exposed via http or the websocket
|
# not exposed via http or the websocket
|
||||||
RESERVED_ENDPOINTS = [
|
RESERVED_ENDPOINTS = [
|
||||||
"list_endpoints", "moonraker/get_configuration"
|
"list_endpoints", "moonraker/check_available"
|
||||||
]
|
]
|
||||||
|
|
||||||
|
|
||||||
|
@ -91,20 +91,23 @@ class APIDefinition:
|
||||||
self.parser = parser
|
self.parser = parser
|
||||||
|
|
||||||
class MoonrakerApp:
|
class MoonrakerApp:
|
||||||
def __init__(self, server, args):
|
def __init__(self, config):
|
||||||
self.server = server
|
self.server = config.get_server()
|
||||||
self.tornado_server = None
|
self.tornado_server = None
|
||||||
self.api_cache = {}
|
self.api_cache = {}
|
||||||
self.registered_base_handlers = []
|
self.registered_base_handlers = []
|
||||||
|
|
||||||
# Set Up Websocket and Authorization Managers
|
# Set Up Websocket and Authorization Managers
|
||||||
self.wsm = WebsocketManager(server)
|
self.wsm = WebsocketManager(self.server)
|
||||||
self.auth = Authorization(args.apikey)
|
self.auth = Authorization(config['authorization'])
|
||||||
|
|
||||||
mimetypes.add_type('text/plain', '.log')
|
mimetypes.add_type('text/plain', '.log')
|
||||||
mimetypes.add_type('text/plain', '.gcode')
|
mimetypes.add_type('text/plain', '.gcode')
|
||||||
mimetypes.add_type('text/plain', '.cfg')
|
mimetypes.add_type('text/plain', '.cfg')
|
||||||
|
|
||||||
|
debug = config.getboolean('enable_debug_logging', True)
|
||||||
|
enable_cors = config.getboolean('enable_cors', False)
|
||||||
|
|
||||||
# Set up HTTP only requests
|
# Set up HTTP only requests
|
||||||
self.mutable_router = MutableRouter(self)
|
self.mutable_router = MutableRouter(self)
|
||||||
app_handlers = [
|
app_handlers = [
|
||||||
|
@ -112,18 +115,19 @@ class MoonrakerApp:
|
||||||
(r"/websocket", WebSocket,
|
(r"/websocket", WebSocket,
|
||||||
{'wsm': self.wsm, 'auth': self.auth}),
|
{'wsm': self.wsm, 'auth': self.auth}),
|
||||||
(r"/api/version", EmulateOctoprintHandler,
|
(r"/api/version", EmulateOctoprintHandler,
|
||||||
{'server': server, 'auth': self.auth})]
|
{'server': self.server, 'auth': self.auth})]
|
||||||
|
|
||||||
self.app = tornado.web.Application(
|
self.app = tornado.web.Application(
|
||||||
app_handlers,
|
app_handlers,
|
||||||
serve_traceback=args.debug,
|
serve_traceback=debug,
|
||||||
websocket_ping_interval=10,
|
websocket_ping_interval=10,
|
||||||
websocket_ping_timeout=30,
|
websocket_ping_timeout=30,
|
||||||
enable_cors=False)
|
enable_cors=enable_cors)
|
||||||
self.get_handler_delegate = self.app.get_handler_delegate
|
self.get_handler_delegate = self.app.get_handler_delegate
|
||||||
|
|
||||||
# Register handlers
|
# Register handlers
|
||||||
self.register_static_file_handler("moonraker.log", args.logfile)
|
logfile = config['cmd_args'].get('logfile')
|
||||||
|
self.register_static_file_handler("moonraker.log", logfile)
|
||||||
self.auth.register_handlers(self)
|
self.auth.register_handlers(self)
|
||||||
|
|
||||||
def listen(self, host, port):
|
def listen(self, host, port):
|
||||||
|
@ -137,11 +141,6 @@ class MoonrakerApp:
|
||||||
await self.wsm.close()
|
await self.wsm.close()
|
||||||
self.auth.close()
|
self.auth.close()
|
||||||
|
|
||||||
def load_config(self, config):
|
|
||||||
if 'enable_cors' in config:
|
|
||||||
self.app.settings['enable_cors'] = config['enable_cors']
|
|
||||||
self.auth.load_config(config)
|
|
||||||
|
|
||||||
def register_remote_handler(self, endpoint):
|
def register_remote_handler(self, endpoint):
|
||||||
if endpoint in RESERVED_ENDPOINTS:
|
if endpoint in RESERVED_ENDPOINTS:
|
||||||
return
|
return
|
||||||
|
@ -195,6 +194,8 @@ class MoonrakerApp:
|
||||||
else:
|
else:
|
||||||
logging.info("Invalid file path: %s" % (file_path))
|
logging.info("Invalid file path: %s" % (file_path))
|
||||||
return
|
return
|
||||||
|
logging.debug("Registering static file: (%s) %s" % (
|
||||||
|
pattern, file_path))
|
||||||
methods = ['GET']
|
methods = ['GET']
|
||||||
if can_delete:
|
if can_delete:
|
||||||
methods.append('DELETE')
|
methods.append('DELETE')
|
||||||
|
|
Loading…
Reference in New Issue