From 77aeb6146e60ddcf34a425f9b3bb544414194d70 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gina=20H=C3=A4u=C3=9Fge?= Date: Wed, 7 Feb 2018 13:24:50 +0100 Subject: [PATCH] Logging: redirects for backwards compatibility --- .../plugins/logging/static/js/logging.js | 6 +++--- src/octoprint/server/__init__.py | 6 +++++- src/octoprint/server/util/tornado.py | 20 +++++++++++++++++++ 3 files changed, 28 insertions(+), 4 deletions(-) diff --git a/src/octoprint/plugins/logging/static/js/logging.js b/src/octoprint/plugins/logging/static/js/logging.js index edc84c327..c4131debb 100644 --- a/src/octoprint/plugins/logging/static/js/logging.js +++ b/src/octoprint/plugins/logging/static/js/logging.js @@ -44,17 +44,17 @@ }; DeprecatedOctoPrintLogsClient.prototype.list = function(opts) { - log.warn("OctoPrintClient.logs.list has been deprecated, use OctoPrintClient.plugins.logging.listLogs instead"); + log.warn("OctoPrintClient.logs.list has been deprecated as of OctoPrint 1.3.7, use OctoPrintClient.plugins.logging.listLogs instead"); return this.wrapped.listLogs(opts); }; DeprecatedOctoPrintLogsClient.prototype.delete = function(file, opts) { - log.warn("OctoPrintClient.logs.delete has been deprecated, use OctoPrintClient.plugins.logging.deleteLog instead"); + log.warn("OctoPrintClient.logs.delete has been deprecated as of OctoPrint 1.3.7, use OctoPrintClient.plugins.logging.deleteLog instead"); return this.wrapped.deleteLog(file, opts); }; DeprecatedOctoPrintLogsClient.prototype.download = function(file, opts) { - log.warn("OctoPrintClient.logs.download has been deprecated, use OctoPrintClient.plugins.logging.downloadLog instead"); + log.warn("OctoPrintClient.logs.download has been deprecated as of OctoPrint 1.3.7, use OctoPrintClient.plugins.logging.downloadLog instead"); return this.wrapped.downloadLog(file, opts); }; diff --git a/src/octoprint/server/__init__.py b/src/octoprint/server/__init__.py index 7bbfa00b9..53a5fc07d 100644 --- a/src/octoprint/server/__init__.py +++ b/src/octoprint/server/__init__.py @@ -527,7 +527,11 @@ class Server(object): # online indicators - text file with "online" as content and a transparent gif (r"/online.txt", util.tornado.StaticDataHandler, dict(data="online\n")), (r"/online.gif", util.tornado.StaticDataHandler, dict(data=bytes(base64.b64decode("R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7")), - content_type="image/gif")) + content_type="image/gif")), + + # deprecated endpoints + (r"/api/logs", util.tornado.DeprecatedEndpointHandler, dict(url="/plugin/logging/logs")), + (r"/api/logs/(.*)", util.tornado.DeprecatedEndpointHandler, dict(url="/plugin/logging/logs/{0}")), ] # fetch additional routes from plugins diff --git a/src/octoprint/server/util/tornado.py b/src/octoprint/server/util/tornado.py index b7610b07b..f63a1c5f6 100644 --- a/src/octoprint/server/util/tornado.py +++ b/src/octoprint/server/util/tornado.py @@ -1075,6 +1075,26 @@ class StaticDataHandler(RequestlessExceptionLoggingMixin, tornado.web.RequestHan self.finish() +class DeprecatedEndpointHandler(tornado.web.RequestHandler): + def initialize(self, url): + self._url = url + self._logger = logging.getLogger(__name__) + + def _handle_method(self, *args, **kwargs): + to_url = self._url.format(*args) + self._logger.info("Redirecting deprecated endpoint {} to {}".format(self.request.path, to_url)) + self.redirect(to_url, permanent=True) + + # make all http methods trigger _handle_method + get = _handle_method + post = _handle_method + put = _handle_method + patch = _handle_method + delete = _handle_method + head = _handle_method + options = _handle_method + + class GlobalHeaderTransform(tornado.web.OutputTransform): HEADERS = dict()