From 5c220651355ca63e4040d80c0aef196093945c4c Mon Sep 17 00:00:00 2001 From: Jesse Hills <3060199+jesserockz@users.noreply.github.com> Date: Wed, 9 Feb 2022 23:46:20 +1300 Subject: [PATCH] Change most references from hassio to ha-addon (#3178) --- .github/workflows/release.yml | 4 +-- docker/Dockerfile | 2 +- .../etc/cont-init.d/10-requirements.sh | 0 .../etc/cont-init.d/20-nginx.sh | 0 .../etc/cont-init.d/30-dirs.sh | 0 .../etc/nginx/includes/mime.types | 0 .../etc/nginx/includes/proxy_params.conf | 0 .../etc/nginx/includes/server_params.conf | 0 .../etc/nginx/includes/ssl_params.conf | 0 .../etc/nginx/nginx.conf | 0 .../etc/nginx/servers/direct-ssl.disabled | 2 +- .../etc/nginx/servers/direct.disabled | 2 +- .../etc/nginx/servers/ingress.conf | 4 +-- .../etc/services.d/esphome/finish | 0 .../etc/services.d/esphome/run | 4 +-- .../etc/services.d/nginx/finish | 0 .../etc/services.d/nginx/run | 0 esphome/__main__.py | 2 +- esphome/core/__init__.py | 6 ++-- esphome/dashboard/dashboard.py | 30 +++++++++---------- esphome/helpers.py | 4 +-- requirements.txt | 2 +- script/ci-custom.py | 8 ++++- tests/unit_tests/test_helpers.py | 8 ++--- 24 files changed, 42 insertions(+), 36 deletions(-) rename docker/{hassio-rootfs => ha-addon-rootfs}/etc/cont-init.d/10-requirements.sh (100%) rename docker/{hassio-rootfs => ha-addon-rootfs}/etc/cont-init.d/20-nginx.sh (100%) rename docker/{hassio-rootfs => ha-addon-rootfs}/etc/cont-init.d/30-dirs.sh (100%) rename docker/{hassio-rootfs => ha-addon-rootfs}/etc/nginx/includes/mime.types (100%) rename docker/{hassio-rootfs => ha-addon-rootfs}/etc/nginx/includes/proxy_params.conf (100%) rename docker/{hassio-rootfs => ha-addon-rootfs}/etc/nginx/includes/server_params.conf (100%) rename docker/{hassio-rootfs => ha-addon-rootfs}/etc/nginx/includes/ssl_params.conf (100%) rename docker/{hassio-rootfs => ha-addon-rootfs}/etc/nginx/nginx.conf (100%) rename docker/{hassio-rootfs => ha-addon-rootfs}/etc/nginx/servers/direct-ssl.disabled (93%) rename docker/{hassio-rootfs => ha-addon-rootfs}/etc/nginx/servers/direct.disabled (85%) rename docker/{hassio-rootfs => ha-addon-rootfs}/etc/nginx/servers/ingress.conf (79%) rename docker/{hassio-rootfs => ha-addon-rootfs}/etc/services.d/esphome/finish (100%) rename docker/{hassio-rootfs => ha-addon-rootfs}/etc/services.d/esphome/run (96%) rename docker/{hassio-rootfs => ha-addon-rootfs}/etc/services.d/nginx/finish (100%) rename docker/{hassio-rootfs => ha-addon-rootfs}/etc/services.d/nginx/run (100%) diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index d6895becc0..02a55494e9 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -137,7 +137,7 @@ jobs: --build-type "${{ matrix.build_type }}" \ manifest - deploy-hassio-repo: + deploy-ha-addon-repo: if: github.repository == 'esphome/esphome' && github.event_name == 'release' runs-on: ubuntu-latest needs: [deploy-docker] @@ -150,5 +150,5 @@ jobs: -u ":$TOKEN" \ -X POST \ -H "Accept: application/vnd.github.v3+json" \ - https://api.github.com/repos/esphome/hassio/actions/workflows/bump-version.yml/dispatches \ + https://api.github.com/repos/esphome/home-assistant-addon/actions/workflows/bump-version.yml/dispatches \ -d "{\"ref\":\"main\",\"inputs\":{\"version\":\"$TAG\"}}" diff --git a/docker/Dockerfile b/docker/Dockerfile index 0eebbe827e..5d9decbf1b 100644 --- a/docker/Dockerfile +++ b/docker/Dockerfile @@ -102,7 +102,7 @@ RUN \ ARG BUILD_VERSION=dev # Copy root filesystem -COPY docker/hassio-rootfs/ / +COPY docker/ha-addon-rootfs/ / # First install requirements to leverage caching when requirements don't change COPY requirements.txt requirements_optional.txt docker/platformio_install_deps.py platformio.ini / diff --git a/docker/hassio-rootfs/etc/cont-init.d/10-requirements.sh b/docker/ha-addon-rootfs/etc/cont-init.d/10-requirements.sh similarity index 100% rename from docker/hassio-rootfs/etc/cont-init.d/10-requirements.sh rename to docker/ha-addon-rootfs/etc/cont-init.d/10-requirements.sh diff --git a/docker/hassio-rootfs/etc/cont-init.d/20-nginx.sh b/docker/ha-addon-rootfs/etc/cont-init.d/20-nginx.sh similarity index 100% rename from docker/hassio-rootfs/etc/cont-init.d/20-nginx.sh rename to docker/ha-addon-rootfs/etc/cont-init.d/20-nginx.sh diff --git a/docker/hassio-rootfs/etc/cont-init.d/30-dirs.sh b/docker/ha-addon-rootfs/etc/cont-init.d/30-dirs.sh similarity index 100% rename from docker/hassio-rootfs/etc/cont-init.d/30-dirs.sh rename to docker/ha-addon-rootfs/etc/cont-init.d/30-dirs.sh diff --git a/docker/hassio-rootfs/etc/nginx/includes/mime.types b/docker/ha-addon-rootfs/etc/nginx/includes/mime.types similarity index 100% rename from docker/hassio-rootfs/etc/nginx/includes/mime.types rename to docker/ha-addon-rootfs/etc/nginx/includes/mime.types diff --git a/docker/hassio-rootfs/etc/nginx/includes/proxy_params.conf b/docker/ha-addon-rootfs/etc/nginx/includes/proxy_params.conf similarity index 100% rename from docker/hassio-rootfs/etc/nginx/includes/proxy_params.conf rename to docker/ha-addon-rootfs/etc/nginx/includes/proxy_params.conf diff --git a/docker/hassio-rootfs/etc/nginx/includes/server_params.conf b/docker/ha-addon-rootfs/etc/nginx/includes/server_params.conf similarity index 100% rename from docker/hassio-rootfs/etc/nginx/includes/server_params.conf rename to docker/ha-addon-rootfs/etc/nginx/includes/server_params.conf diff --git a/docker/hassio-rootfs/etc/nginx/includes/ssl_params.conf b/docker/ha-addon-rootfs/etc/nginx/includes/ssl_params.conf similarity index 100% rename from docker/hassio-rootfs/etc/nginx/includes/ssl_params.conf rename to docker/ha-addon-rootfs/etc/nginx/includes/ssl_params.conf diff --git a/docker/hassio-rootfs/etc/nginx/nginx.conf b/docker/ha-addon-rootfs/etc/nginx/nginx.conf similarity index 100% rename from docker/hassio-rootfs/etc/nginx/nginx.conf rename to docker/ha-addon-rootfs/etc/nginx/nginx.conf diff --git a/docker/hassio-rootfs/etc/nginx/servers/direct-ssl.disabled b/docker/ha-addon-rootfs/etc/nginx/servers/direct-ssl.disabled similarity index 93% rename from docker/hassio-rootfs/etc/nginx/servers/direct-ssl.disabled rename to docker/ha-addon-rootfs/etc/nginx/servers/direct-ssl.disabled index c2b8d6567d..4ebc435dbb 100644 --- a/docker/hassio-rootfs/etc/nginx/servers/direct-ssl.disabled +++ b/docker/ha-addon-rootfs/etc/nginx/servers/direct-ssl.disabled @@ -10,7 +10,7 @@ server { ssl_certificate_key /ssl/%%keyfile%%; # Clear Hass.io Ingress header - proxy_set_header X-Hassio-Ingress ""; + proxy_set_header X-HA-Ingress ""; # Redirect http requests to https on the same port. # https://rageagainstshell.com/2016/11/redirect-http-to-https-on-the-same-port-in-nginx/ diff --git a/docker/hassio-rootfs/etc/nginx/servers/direct.disabled b/docker/ha-addon-rootfs/etc/nginx/servers/direct.disabled similarity index 85% rename from docker/hassio-rootfs/etc/nginx/servers/direct.disabled rename to docker/ha-addon-rootfs/etc/nginx/servers/direct.disabled index 51f57cab88..80300fc6aa 100644 --- a/docker/hassio-rootfs/etc/nginx/servers/direct.disabled +++ b/docker/ha-addon-rootfs/etc/nginx/servers/direct.disabled @@ -4,7 +4,7 @@ server { include /etc/nginx/includes/server_params.conf; include /etc/nginx/includes/proxy_params.conf; # Clear Hass.io Ingress header - proxy_set_header X-Hassio-Ingress ""; + proxy_set_header X-HA-Ingress ""; location / { proxy_pass http://esphome; diff --git a/docker/hassio-rootfs/etc/nginx/servers/ingress.conf b/docker/ha-addon-rootfs/etc/nginx/servers/ingress.conf similarity index 79% rename from docker/hassio-rootfs/etc/nginx/servers/ingress.conf rename to docker/ha-addon-rootfs/etc/nginx/servers/ingress.conf index 3a800d97e7..9d0d2d3e66 100644 --- a/docker/hassio-rootfs/etc/nginx/servers/ingress.conf +++ b/docker/ha-addon-rootfs/etc/nginx/servers/ingress.conf @@ -3,8 +3,8 @@ server { include /etc/nginx/includes/server_params.conf; include /etc/nginx/includes/proxy_params.conf; - # Set Hass.io Ingress header - proxy_set_header X-Hassio-Ingress "YES"; + # Set Home Assistant Ingress header + proxy_set_header X-HA-Ingress "YES"; location / { # Only allow from Hass.io supervisor diff --git a/docker/hassio-rootfs/etc/services.d/esphome/finish b/docker/ha-addon-rootfs/etc/services.d/esphome/finish similarity index 100% rename from docker/hassio-rootfs/etc/services.d/esphome/finish rename to docker/ha-addon-rootfs/etc/services.d/esphome/finish diff --git a/docker/hassio-rootfs/etc/services.d/esphome/run b/docker/ha-addon-rootfs/etc/services.d/esphome/run similarity index 96% rename from docker/hassio-rootfs/etc/services.d/esphome/run rename to docker/ha-addon-rootfs/etc/services.d/esphome/run index a0f20d63d6..2c821bf4ee 100755 --- a/docker/hassio-rootfs/etc/services.d/esphome/run +++ b/docker/ha-addon-rootfs/etc/services.d/esphome/run @@ -4,7 +4,7 @@ # Runs the ESPHome dashboard # ============================================================================== -export ESPHOME_IS_HASSIO=true +export ESPHOME_IS_HA_ADDON=true if bashio::config.true 'leave_front_door_open'; then export DISABLE_HA_AUTHENTICATION=true @@ -32,4 +32,4 @@ export PLATFORMIO_CACHE_DIR="${pio_cache_base}/cache" export PLATFORMIO_GLOBALLIB_DIR=/piolibs bashio::log.info "Starting ESPHome dashboard..." -exec esphome dashboard /config/esphome --socket /var/run/esphome.sock --hassio +exec esphome dashboard /config/esphome --socket /var/run/esphome.sock --ha-addon diff --git a/docker/hassio-rootfs/etc/services.d/nginx/finish b/docker/ha-addon-rootfs/etc/services.d/nginx/finish similarity index 100% rename from docker/hassio-rootfs/etc/services.d/nginx/finish rename to docker/ha-addon-rootfs/etc/services.d/nginx/finish diff --git a/docker/hassio-rootfs/etc/services.d/nginx/run b/docker/ha-addon-rootfs/etc/services.d/nginx/run similarity index 100% rename from docker/hassio-rootfs/etc/services.d/nginx/run rename to docker/ha-addon-rootfs/etc/services.d/nginx/run diff --git a/esphome/__main__.py b/esphome/__main__.py index 6f57791480..a64f096d54 100644 --- a/esphome/__main__.py +++ b/esphome/__main__.py @@ -661,7 +661,7 @@ def parse_args(argv): "--open-ui", help="Open the dashboard UI in a browser.", action="store_true" ) parser_dashboard.add_argument( - "--hassio", help=argparse.SUPPRESS, action="store_true" + "--ha-addon", help=argparse.SUPPRESS, action="store_true" ) parser_dashboard.add_argument( "--socket", help="Make the dashboard serve under a unix socket", type=str diff --git a/esphome/core/__init__.py b/esphome/core/__init__.py index addecf1326..a4867915bb 100644 --- a/esphome/core/__init__.py +++ b/esphome/core/__init__.py @@ -20,7 +20,7 @@ from esphome.coroutine import FakeEventLoop as _FakeEventLoop # pylint: disable=unused-import from esphome.coroutine import coroutine, coroutine_with_priority # noqa -from esphome.helpers import ensure_unique_string, is_hassio +from esphome.helpers import ensure_unique_string, is_ha_addon from esphome.util import OrderedDict if TYPE_CHECKING: @@ -568,12 +568,12 @@ class EsphomeCore: return self.relative_build_path("src", *path) def relative_pioenvs_path(self, *path): - if is_hassio(): + if is_ha_addon(): return os.path.join("/data", self.name, ".pioenvs", *path) return self.relative_build_path(".pioenvs", *path) def relative_piolibdeps_path(self, *path): - if is_hassio(): + if is_ha_addon(): return os.path.join("/data", self.name, ".piolibdeps", *path) return self.relative_build_path(".piolibdeps", *path) diff --git a/esphome/dashboard/dashboard.py b/esphome/dashboard/dashboard.py index c68d037fe6..0ace97f10e 100644 --- a/esphome/dashboard/dashboard.py +++ b/esphome/dashboard/dashboard.py @@ -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() diff --git a/esphome/helpers.py b/esphome/helpers.py index 289abe5459..76158a1bfd 100644 --- a/esphome/helpers.py +++ b/esphome/helpers.py @@ -144,8 +144,8 @@ def get_bool_env(var, default=False): return bool(os.getenv(var, default)) -def is_hassio(): - return get_bool_env("ESPHOME_IS_HASSIO") +def is_ha_addon(): + return get_bool_env("ESPHOME_IS_HA_ADDON") def walk_files(path): diff --git a/requirements.txt b/requirements.txt index 2cbebb11f5..a33461b79b 100644 --- a/requirements.txt +++ b/requirements.txt @@ -9,7 +9,7 @@ pyserial==3.5 platformio==5.2.4 # When updating platformio, also update Dockerfile esptool==3.2 click==8.0.3 -esphome-dashboard==20220116.0 +esphome-dashboard==20220209.0 aioesphomeapi==10.8.1 zeroconf==0.37.0 diff --git a/script/ci-custom.py b/script/ci-custom.py index 7bbaaf1c79..d1efa22d85 100755 --- a/script/ci-custom.py +++ b/script/ci-custom.py @@ -222,7 +222,13 @@ def lint_ext_check(fname): @lint_file_check( - exclude=["**.sh", "docker/hassio-rootfs/**", "docker/*.py", "script/*", "setup.py"] + exclude=[ + "**.sh", + "docker/ha-addon-rootfs/**", + "docker/*.py", + "script/*", + "setup.py", + ] ) def lint_executable_bit(fname): ex = EXECUTABLE_BIT[fname] diff --git a/tests/unit_tests/test_helpers.py b/tests/unit_tests/test_helpers.py index 00a6b08133..f883b8b44f 100644 --- a/tests/unit_tests/test_helpers.py +++ b/tests/unit_tests/test_helpers.py @@ -124,13 +124,13 @@ def test_get_bool_env(monkeypatch, var, value, default, expected): @pytest.mark.parametrize("value, expected", ((None, False), ("Yes", True))) -def test_is_hassio(monkeypatch, value, expected): +def test_is_ha_addon(monkeypatch, value, expected): if value is None: - monkeypatch.delenv("ESPHOME_IS_HASSIO", raising=False) + monkeypatch.delenv("ESPHOME_IS_HA_ADDON", raising=False) else: - monkeypatch.setenv("ESPHOME_IS_HASSIO", value) + monkeypatch.setenv("ESPHOME_IS_HA_ADDON", value) - actual = helpers.is_hassio() + actual = helpers.is_ha_addon() assert actual == expected