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