Enable API by default and automatically generate API key on first server startup

This commit is contained in:
Gina Häußge 2014-09-29 22:18:34 +02:00
parent d60ab8cd9e
commit d49cd209e1
2 changed files with 11 additions and 2 deletions

View file

@ -2,6 +2,11 @@
## 1.1.1 (Unreleased) ## 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 ### Bug Fixes
* [#580](https://github.com/foosel/OctoPrint/issues/580) - Properly unset job data when instructed so by callers * [#580](https://github.com/foosel/OctoPrint/issues/580) - Properly unset job data when instructed so by callers

View file

@ -129,8 +129,8 @@ default_settings = {
"subscriptions": [] "subscriptions": []
}, },
"api": { "api": {
"enabled": False, "enabled": True,
"key": ''.join('%02X' % ord(z) for z in uuid.uuid4().bytes) "key": None
}, },
"terminalFilters": [ "terminalFilters": [
{ "name": "Suppress M105 requests/responses", "regex": "(Send: M105)|(Recv: ok T\d*:)" }, { "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._configfile = os.path.join(self.settings_dir, "config.yaml")
self.load(migrate=True) 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): def _init_settings_dir(self, basedir):
if basedir is not None: if basedir is not None:
self.settings_dir = basedir self.settings_dir = basedir