From 76f48b3b137691679efdeb88d6d38aed34a1647f Mon Sep 17 00:00:00 2001 From: tedder Date: Thu, 8 Nov 2018 01:29:15 +0000 Subject: [PATCH] PR feedback: throttle state and uuid - add a way to get the raw value only from throttle state (glad I already plumbed it into the object!) - add warning about not sending uuid, modify the log entry too --- src/octoprint/plugins/pi_support/__init__.py | 8 ++++++-- src/octoprint/plugins/tracking/__init__.py | 7 +++++-- 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/src/octoprint/plugins/pi_support/__init__.py b/src/octoprint/plugins/pi_support/__init__.py index 04f85ea29..69c3a9448 100644 --- a/src/octoprint/plugins/pi_support/__init__.py +++ b/src/octoprint/plugins/pi_support/__init__.py @@ -244,8 +244,12 @@ class PiSupportPlugin(octoprint.plugin.EnvironmentDetectionPlugin, def _check_throttled_state_condition(self): return self._throttle_functional - def get_throttle_state(self, run_now=False): - '''public method to pass around in plugin_helpers''' + def get_throttle_state(self, raw_value_only=False, run_now=False): + '''public method to pass around in plugin_helpers.''' + + # Not using the `run_now` yet, but leaving it as a placeholder. + + if raw_value_only: return self._throttle_state._raw_value return self._throttle_state.as_dict() def _check_throttled_state(self): diff --git a/src/octoprint/plugins/tracking/__init__.py b/src/octoprint/plugins/tracking/__init__.py index 30e65d46b..fbe7561a4 100644 --- a/src/octoprint/plugins/tracking/__init__.py +++ b/src/octoprint/plugins/tracking/__init__.py @@ -169,7 +169,7 @@ class TrackingPlugin(octoprint.plugin.SettingsPlugin, ram=self._environment[b"hardware"][b"ram"]) if self._helpers_get_throttle_state: - payload[b"throttle_state"] = self._helpers_get_throttle_state() + payload[b"throttle_state"] = self._helpers_get_throttle_state(raw_value_only=True) if b"plugins" in self._environment and b"pi_support" in self._environment[b"plugins"]: payload[b"pi_model"] = self._environment[b"plugins"][b"pi_support"][b"model"] @@ -263,15 +263,18 @@ class TrackingPlugin(octoprint.plugin.SettingsPlugin, server = self._settings.get([b"server"]) url = server.format(id=self._settings.get([b"unique_id"]), event=event) + # don't print the URL or uuid! That would expose the uuid in forums if pasted. + # (it's okay for the user to know their uuid, but it shouldn't be shared) headers = {"User-Agent": "OctoPrint/{}".format(get_octoprint_version_string())} try: params = urlencode(kwargs, doseq=True).replace("+", "%20") + requests.get(url, params=params, timeout=3.1, headers=headers) - self._logger.info("Sent tracking event to {}, params: {}".format(url, kwargs)) + self._logger.info("Sent tracking event to /{}, params: {}".format(event, kwargs)) except: if self._logger.isEnabledFor(logging.DEBUG): self._logger.exception("Error while sending event to anonymous usage tracking".format(url))