From d49cd209e1de2548458435e3d88e7104a7b875bc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gina=20H=C3=A4u=C3=9Fge?= Date: Mon, 29 Sep 2014 22:18:34 +0200 Subject: [PATCH] Enable API by default and automatically generate API key on first server startup --- CHANGELOG.md | 5 +++++ src/octoprint/settings.py | 8 ++++++-- 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 426ab9c7..01ef69c4 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,11 @@ ## 1.1.1 (Unreleased) +### Improvements + +* The API is now enabled by default and the API key -- if not yet set -- will be automatically generated on first + server start and written back into ``config.yaml`` + ### Bug Fixes * [#580](https://github.com/foosel/OctoPrint/issues/580) - Properly unset job data when instructed so by callers diff --git a/src/octoprint/settings.py b/src/octoprint/settings.py index 4a724138..28226c3b 100644 --- a/src/octoprint/settings.py +++ b/src/octoprint/settings.py @@ -129,8 +129,8 @@ default_settings = { "subscriptions": [] }, "api": { - "enabled": False, - "key": ''.join('%02X' % ord(z) for z in uuid.uuid4().bytes) + "enabled": True, + "key": None }, "terminalFilters": [ { "name": "Suppress M105 requests/responses", "regex": "(Send: M105)|(Recv: ok T\d*:)" }, @@ -171,6 +171,10 @@ class Settings(object): self._configfile = os.path.join(self.settings_dir, "config.yaml") self.load(migrate=True) + if self.get(["api", "key"]) is None: + self.set(["api", "key"], ''.join('%02X' % ord(z) for z in uuid.uuid4().bytes)) + self.save(force=True) + def _init_settings_dir(self, basedir): if basedir is not None: self.settings_dir = basedir