mirror of
https://github.com/esphome/esphome.git
synced 2024-11-25 16:38:16 +01:00
Add endpoint to fetch secrets keys (#2873)
This commit is contained in:
parent
71fe2f7ed3
commit
55db190875
2 changed files with 28 additions and 4 deletions
|
@ -27,7 +27,7 @@ import tornado.process
|
||||||
import tornado.web
|
import tornado.web
|
||||||
import tornado.websocket
|
import tornado.websocket
|
||||||
|
|
||||||
from esphome import const, platformio_api, util
|
from esphome import const, platformio_api, util, yaml_util
|
||||||
from esphome.helpers import mkdir_p, get_bool_env, run_system_command
|
from esphome.helpers import mkdir_p, get_bool_env, run_system_command
|
||||||
from esphome.storage_json import (
|
from esphome.storage_json import (
|
||||||
EsphomeStorageJSON,
|
EsphomeStorageJSON,
|
||||||
|
@ -836,6 +836,28 @@ class LogoutHandler(BaseHandler):
|
||||||
self.redirect("./login")
|
self.redirect("./login")
|
||||||
|
|
||||||
|
|
||||||
|
class SecretKeysRequestHandler(BaseHandler):
|
||||||
|
@authenticated
|
||||||
|
def get(self):
|
||||||
|
|
||||||
|
filename = None
|
||||||
|
|
||||||
|
for secret_filename in const.SECRETS_FILES:
|
||||||
|
relative_filename = settings.rel_path(secret_filename)
|
||||||
|
if os.path.isfile(relative_filename):
|
||||||
|
filename = relative_filename
|
||||||
|
break
|
||||||
|
|
||||||
|
if filename is None:
|
||||||
|
self.send_error(404)
|
||||||
|
return
|
||||||
|
|
||||||
|
secret_keys = list(yaml_util.load_yaml(filename, clear_secrets=False))
|
||||||
|
|
||||||
|
self.set_header("content-type", "application/json")
|
||||||
|
self.write(json.dumps(secret_keys))
|
||||||
|
|
||||||
|
|
||||||
def get_base_frontend_path():
|
def get_base_frontend_path():
|
||||||
if ENV_DEV not in os.environ:
|
if ENV_DEV not in os.environ:
|
||||||
import esphome_dashboard
|
import esphome_dashboard
|
||||||
|
@ -939,6 +961,7 @@ def make_app(debug=get_bool_env(ENV_DEV)):
|
||||||
(f"{rel}static/(.*)", StaticFileHandler, {"path": get_static_path()}),
|
(f"{rel}static/(.*)", StaticFileHandler, {"path": get_static_path()}),
|
||||||
(f"{rel}devices", ListDevicesHandler),
|
(f"{rel}devices", ListDevicesHandler),
|
||||||
(f"{rel}import", ImportRequestHandler),
|
(f"{rel}import", ImportRequestHandler),
|
||||||
|
(f"{rel}secret_keys", SecretKeysRequestHandler),
|
||||||
],
|
],
|
||||||
**app_settings,
|
**app_settings,
|
||||||
)
|
)
|
||||||
|
|
|
@ -329,9 +329,10 @@ ESPHomeLoader.add_constructor("!lambda", ESPHomeLoader.construct_lambda)
|
||||||
ESPHomeLoader.add_constructor("!force", ESPHomeLoader.construct_force)
|
ESPHomeLoader.add_constructor("!force", ESPHomeLoader.construct_force)
|
||||||
|
|
||||||
|
|
||||||
def load_yaml(fname):
|
def load_yaml(fname, clear_secrets=True):
|
||||||
_SECRET_VALUES.clear()
|
if clear_secrets:
|
||||||
_SECRET_CACHE.clear()
|
_SECRET_VALUES.clear()
|
||||||
|
_SECRET_CACHE.clear()
|
||||||
return _load_yaml_internal(fname)
|
return _load_yaml_internal(fname)
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue