mirror of
https://github.com/Threnklyn/esphome-dev.git
synced 2026-06-04 20:09:35 +02:00
Change most references from hassio to ha-addon (#3178)
This commit is contained in:
@@ -55,13 +55,13 @@ class DashboardSettings:
|
||||
self.password_hash = ""
|
||||
self.username = ""
|
||||
self.using_password = False
|
||||
self.on_hassio = False
|
||||
self.on_ha_addon = False
|
||||
self.cookie_secret = None
|
||||
|
||||
def parse_args(self, args):
|
||||
self.on_hassio = args.hassio
|
||||
self.on_ha_addon = args.ha_addon
|
||||
password = args.password or os.getenv("PASSWORD", "")
|
||||
if not self.on_hassio:
|
||||
if not self.on_ha_addon:
|
||||
self.username = args.username or os.getenv("USERNAME", "")
|
||||
self.using_password = bool(password)
|
||||
if self.using_password:
|
||||
@@ -77,14 +77,14 @@ class DashboardSettings:
|
||||
return get_bool_env("ESPHOME_DASHBOARD_USE_PING")
|
||||
|
||||
@property
|
||||
def using_hassio_auth(self):
|
||||
if not self.on_hassio:
|
||||
def using_ha_addon_auth(self):
|
||||
if not self.on_ha_addon:
|
||||
return False
|
||||
return not get_bool_env("DISABLE_HA_AUTHENTICATION")
|
||||
|
||||
@property
|
||||
def using_auth(self):
|
||||
return self.using_password or self.using_hassio_auth
|
||||
return self.using_password or self.using_ha_addon_auth
|
||||
|
||||
def check_password(self, username, password):
|
||||
if not self.using_auth:
|
||||
@@ -138,10 +138,10 @@ def authenticated(func):
|
||||
|
||||
|
||||
def is_authenticated(request_handler):
|
||||
if settings.on_hassio:
|
||||
if settings.on_ha_addon:
|
||||
# Handle ingress - disable auth on ingress port
|
||||
# X-Hassio-Ingress is automatically stripped on the non-ingress server in nginx
|
||||
header = request_handler.request.headers.get("X-Hassio-Ingress", "NO")
|
||||
# X-HA-Ingress is automatically stripped on the non-ingress server in nginx
|
||||
header = request_handler.request.headers.get("X-HA-Ingress", "NO")
|
||||
if str(header) == "YES":
|
||||
return True
|
||||
if settings.using_auth:
|
||||
@@ -792,23 +792,23 @@ class LoginHandler(BaseHandler):
|
||||
self.render(
|
||||
"login.template.html",
|
||||
error=error,
|
||||
hassio=settings.using_hassio_auth,
|
||||
ha_addon=settings.using_ha_addon_auth,
|
||||
has_username=bool(settings.username),
|
||||
**template_args(),
|
||||
)
|
||||
|
||||
def post_hassio_login(self):
|
||||
def post_ha_addon_login(self):
|
||||
import requests
|
||||
|
||||
headers = {
|
||||
"X-HASSIO-KEY": os.getenv("HASSIO_TOKEN"),
|
||||
"Authentication": f"Bearer {os.getenv('SUPERVISOR_TOKEN')}",
|
||||
}
|
||||
data = {
|
||||
"username": self.get_argument("username", ""),
|
||||
"password": self.get_argument("password", ""),
|
||||
}
|
||||
try:
|
||||
req = requests.post("http://hassio/auth", headers=headers, data=data)
|
||||
req = requests.post("http://supervisor/auth", headers=headers, data=data)
|
||||
if req.status_code == 200:
|
||||
self.set_secure_cookie("authenticated", cookie_authenticated_yes)
|
||||
self.redirect("/")
|
||||
@@ -835,8 +835,8 @@ class LoginHandler(BaseHandler):
|
||||
self.render_login_page(error=error_str)
|
||||
|
||||
def post(self):
|
||||
if settings.using_hassio_auth:
|
||||
self.post_hassio_login()
|
||||
if settings.using_ha_addon_auth:
|
||||
self.post_ha_addon_login()
|
||||
else:
|
||||
self.post_native_login()
|
||||
|
||||
|
||||
Reference in New Issue
Block a user