From 002802bb201cdefa5353d5bb7212cbeb53d79211 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gina=20H=C3=A4u=C3=9Fge?= Date: Tue, 15 Jan 2019 17:25:58 +0100 Subject: [PATCH] Deprecate appkey API in favor of Application Keys Plugin Slated to be removed in 1.4.0. AFAIK nobody used it anyhow. --- docs/api/apps.rst | 4 ++++ docs/plugins/hooks.rst | 4 ++++ src/octoprint/plugin/__init__.py | 10 ---------- src/octoprint/plugin/types.py | 17 ----------------- src/octoprint/server/apps/__init__.py | 10 ++++++++++ 5 files changed, 18 insertions(+), 27 deletions(-) diff --git a/docs/api/apps.rst b/docs/api/apps.rst index 46ee73c8c..6015d3359 100644 --- a/docs/api/apps.rst +++ b/docs/api/apps.rst @@ -11,6 +11,10 @@ Apps Session Keys ============ +.. deprecated:: 1.3.11 + + This functionality will be removed in 1.4.0. Use the :ref:`Application Keys Plugin workflow ` instead. + OctoPrint offers a special API key type for apps to use, the so called App Session Key. These keys have a time based validity and are generated by OctoPrint for requesting apps. diff --git a/docs/plugins/hooks.rst b/docs/plugins/hooks.rst index 2dc08b3c2..1dd8a0dd5 100644 --- a/docs/plugins/hooks.rst +++ b/docs/plugins/hooks.rst @@ -208,6 +208,10 @@ octoprint.accesscontrol.appkey .. py:function:: acl_appkey_hook(*args, **kwargs) + .. deprecated:: 1.3.11 + + This functionality will be removed in 1.4.0. Use the :ref:`Application Keys Plugin workflow ` instead. + By handling this hook plugins may register additional :ref:`App session key providers ` within the system. diff --git a/src/octoprint/plugin/__init__.py b/src/octoprint/plugin/__init__.py index 9bcdcd625..5a1efef7a 100644 --- a/src/octoprint/plugin/__init__.py +++ b/src/octoprint/plugin/__init__.py @@ -33,16 +33,6 @@ from octoprint.util import deprecated _instance = None def _validate_plugin(phase, plugin_info): - if phase == "after_load": - if plugin_info.implementation is not None and isinstance(plugin_info.implementation, AppPlugin): - # transform app plugin into hook - import warnings - warnings.warn("{name} uses deprecated plugin mixin AppPlugin, use octoprint.accesscontrol.appkey hook instead".format(name=plugin_info.key), DeprecationWarning) - - hooks = plugin_info.hooks - if not "octoprint.accesscontrol.appkey" in hooks: - hooks["octoprint.accesscontrol.appkey"] = plugin_info.implementation.get_additional_apps - setattr(plugin_info.instance, PluginInfo.attr_hooks, hooks) return True def plugin_manager(init=False, plugin_folders=None, plugin_bases=None, plugin_entry_points=None, plugin_disabled_list=None, diff --git a/src/octoprint/plugin/types.py b/src/octoprint/plugin/types.py index 2bfd5063f..7ce4b2eb9 100644 --- a/src/octoprint/plugin/types.py +++ b/src/octoprint/plugin/types.py @@ -2059,20 +2059,3 @@ class ProgressPlugin(OctoPrintPlugin): :param int progress: Current progress as a value between 0 and 100 """ pass - - -class AppPlugin(OctoPrintPlugin): - """ - Using the :class:`AppPlugin mixin` plugins may register additional :ref:`App session key providers ` - within the system. - - .. deprecated:: 1.2.0 - - Refer to the :ref:`octoprint.accesscontrol.appkey hook ` instead. - - """ - - # noinspection PyMethodMayBeStatic - def get_additional_apps(self): - return [] - diff --git a/src/octoprint/server/apps/__init__.py b/src/octoprint/server/apps/__init__.py index f5e9e3286..6cbe20c72 100644 --- a/src/octoprint/server/apps/__init__.py +++ b/src/octoprint/server/apps/__init__.py @@ -7,13 +7,17 @@ __copyright__ = "Copyright (C) 2014 The OctoPrint Project - Released under terms import rsa from flask import Blueprint, request, make_response, jsonify +import logging import octoprint.server import octoprint.plugin from octoprint.server.util import noCachingResponseHandler, corsResponseHandler +from octoprint.server.util.flask import get_remote_address from octoprint.settings import settings as s +logger = logging.getLogger(__name__) + apps = Blueprint("apps", __name__) apps.after_request(noCachingResponseHandler) @@ -21,11 +25,16 @@ apps.after_request(corsResponseHandler) @apps.route("/auth", methods=["GET"]) def getSessionKey(): + logger.warn("Client {} accessed the apps API which has been deprecated since 1.3.11 and will be removed in " + "1.4.0. Clients should use the Application Keys Plugin workflow instead".format(get_remote_address(request))) unverified_key, valid_until = octoprint.server.appSessionManager.create() return jsonify(unverifiedKey=unverified_key, validUntil=valid_until) @apps.route("/auth", methods=["POST"]) def verifySessionKey(): + logger.warn("Client {} accessed the apps API which has been deprecated since 1.3.11 and will be removed in " + "1.4.0. Clients should use the Application Keys Plugin workflow instead".format(get_remote_address(request))) + if not "application/json" in request.headers["Content-Type"]: return None, None, make_response("Expected content-type JSON", 400) @@ -95,6 +104,7 @@ def _get_registered_apps(): for name, hook in hooks.items(): try: additional_apps = hook() + logger.warn("Plugin {} is still implementing the appkey hook that is deprecated since 1.3.11 and will be removed in 1.4.0. Switch it over to the Application Keys Plugin workflow.".format(name)) except: import logging logging.getLogger(__name__).exception("Error while retrieving additional appkeys from plugin {name}".format(**locals()))