Skip to content

Commit

Permalink
refactor: Rename to hass-web-proxy-integration (#15)
Browse files Browse the repository at this point in the history
* refactor: Rename to `hass-web-proxy-integration`

* Fix broken rename

* Lint fixes
  • Loading branch information
dermotduffy authored Oct 23, 2024
1 parent a0399ce commit efe75b1
Show file tree
Hide file tree
Showing 20 changed files with 142 additions and 152 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# `hass-proxy`
# `hass-web-proxy-integration`

A small [Home Assistant](https://www.home-assistant.io/) integration to proxy
authenticated web traffic through Home Assistant.
12 changes: 0 additions & 12 deletions custom_components/hass_proxy/manifest.json

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,18 @@
Custom integration to add a small web proxy to Home Assistant.
For more details about this integration, please refer to
https://github.com/dermotduffy/hass-proxy
https://github.com/dermotduffy/hass-web-proxy-integration
"""

from __future__ import annotations

from typing import TYPE_CHECKING

from .const import LOGGER

if TYPE_CHECKING:
from homeassistant.const import Platform
from homeassistant.core import HomeAssistant

from .data import HASSProxyConfigEntry
from .data import HASSWebProxyConfigEntry

from .proxy import async_setup_entry as async_proxy_setup_entry
from .proxy import async_unload_entry as async_proxy_unload_entry
Expand All @@ -26,11 +24,9 @@
# https://developers.home-assistant.io/docs/config_entries_index/#setting-up-an-entry
async def async_setup_entry(
hass: HomeAssistant,
entry: HASSProxyConfigEntry,
entry: HASSWebProxyConfigEntry,
) -> bool:
"""Set up this integration."""
LOGGER.info("HASSPROXY Setting up entry %s", entry.entry_id)

await hass.config_entries.async_forward_entry_setups(entry, PLATFORMS)
entry.async_on_unload(entry.add_update_listener(async_reload_entry))

Expand All @@ -41,20 +37,16 @@ async def async_setup_entry(

async def async_unload_entry(
hass: HomeAssistant,
entry: HASSProxyConfigEntry,
entry: HASSWebProxyConfigEntry,
) -> bool:
"""Handle removal of an entry."""
LOGGER.info("HASSPROXY Unloading entry %s", entry.entry_id)

await async_proxy_unload_entry(hass, entry)

return await hass.config_entries.async_unload_platforms(entry, PLATFORMS)


async def async_reload_entry(
hass: HomeAssistant,
entry: HASSProxyConfigEntry,
entry: HASSWebProxyConfigEntry,
) -> None:
"""Reload config entry."""
LOGGER.info("HASSPROXY Reloading entry %s", entry.entry_id)
await hass.config_entries.async_reload(entry.entry_id)
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
"""Config flow for HASS Proxy."""
"""Config flow for HASS Web Proxy."""

from __future__ import annotations

Expand Down Expand Up @@ -54,16 +54,16 @@
)


class HASSProxyFlowHandler(config_entries.ConfigFlow, domain=DOMAIN): # type: ignore[call-arg,misc]
"""Config flow for HASS Proxy."""
class HASSWebProxyFlowHandler(config_entries.ConfigFlow, domain=DOMAIN): # type: ignore[call-arg,misc]
"""Config flow for HASS Web Proxy."""

@staticmethod
@callback # type: ignore[misc]
def async_get_options_flow(
config_entry: config_entries.ConfigEntry,
) -> HASSProxyOptionsFlowHandler:
) -> HASSWebProxyOptionsFlowHandler:
"""Get the Frigate Options flow."""
return HASSProxyOptionsFlowHandler(config_entry)
return HASSWebProxyOptionsFlowHandler(config_entry)

async def async_step_user(
self,
Expand All @@ -74,11 +74,13 @@ async def async_step_user(
return self.async_abort(reason="single_instance_allowed")

return self.async_create_entry(
title="HASS Proxy", data=user_input or {}, options=DEFAULT_OPTIONS
title="Home Assistant Web Proxy",
data=user_input or {},
options=DEFAULT_OPTIONS,
)


class HASSProxyOptionsFlowHandler(config_entries.OptionsFlow):
class HASSWebProxyOptionsFlowHandler(config_entries.OptionsFlow):
"""Options flow for Blueprint."""

def __init__(self, config_entry: config_entries.ConfigEntry) -> None:
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
"""Constants for hass_proxy."""
"""Constants for HASS Web Proxy."""

from logging import Logger, getLogger
from typing import Final, Literal

DOMAIN: Final = "hass_proxy"
DOMAIN: Final = "hass_web_proxy"

LOGGER: Logger = getLogger(__package__)

Expand All @@ -15,7 +15,7 @@
CONF_SSL_CIPHERS_INTERMEDIATE: Final = "intermediate"
CONF_SSL_CIPHERS_DEFAULT: Final = "default"

type HASSProxySSLCiphers = Literal["insecure", "modern", "intermediate", "default"]
type HASSWebProxySSLCiphers = Literal["insecure", "modern", "intermediate", "default"]

CONF_DYNAMIC_URLS: Final = "dynamic_urls"
CONF_OPEN_LIMIT: Final = "open_limit"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
"""Custom types for hass_proxy."""
"""Custom types for HASS Web Proxy."""

from __future__ import annotations

Expand All @@ -21,12 +21,12 @@ class DynamicProxiedURL:
expiration: int


type HASSProxyConfigEntry = ConfigEntry[HASSProxyData]
type HASSWebProxyConfigEntry = ConfigEntry[HASSWebProxyData]


@dataclass
class HASSProxyData:
"""Data for the HASS Proxy integration."""
class HASSWebProxyData:
"""Data for the HASS Web Proxy integration."""

integration: Integration
dynamic_proxied_urls: dict[str, DynamicProxiedURL]
12 changes: 12 additions & 0 deletions custom_components/hass_web_proxy/manifest.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"domain": "hass_web_proxy",
"name": "Home Assistant Web Proxy",
"codeowners": ["@dermotduffy"],
"config_flow": true,
"dependencies": ["http"],
"documentation": "https://github.com/dermotduffy/hass-web-proxy-integration",
"iot_class": "local_push",
"issue_tracker": "https://github.com/dermotduffy/hass-web-proxy-integration/issues",
"requirements": ["urlmatch==1.0.1"],
"version": "0.0.0"
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
"""HASS Proxy proxy."""
"""HASS Web Proxy proxy."""

from __future__ import annotations

Expand All @@ -20,15 +20,15 @@
client_context_no_verify,
)

from custom_components.hass_proxy.const import DOMAIN
from custom_components.hass_proxy.data import (
from custom_components.hass_web_proxy.const import DOMAIN
from custom_components.hass_web_proxy.data import (
DynamicProxiedURL,
HASSProxyConfigEntry,
HASSProxyData,
HASSWebProxyConfigEntry,
HASSWebProxyData,
)
from custom_components.hass_proxy.proxy_lib import (
HASSProxyLibExpiredError,
HASSProxyLibNotFoundRequestError,
from custom_components.hass_web_proxy.proxy_lib import (
HASSWebProxyLibExpiredError,
HASSWebProxyLibNotFoundRequestError,
ProxiedURL,
ProxyView,
)
Expand Down Expand Up @@ -57,7 +57,7 @@
from aiohttp import web
from homeassistant.core import HomeAssistant, ServiceCall

from .const import HASSProxySSLCiphers
from .const import HASSWebProxySSLCiphers

CREATE_PROXIED_URL_SCHEMA = vol.Schema(
{
Expand Down Expand Up @@ -85,21 +85,15 @@
)


class HASSProxyError(Exception):
"""Exception to indicate a general Proxy error."""


class HASSProxyURLIDNotFoundError(HASSProxyError):
"""Exception to indicate that a URL ID was not found."""


@callback
async def async_setup_entry(hass: HomeAssistant, entry: HASSProxyConfigEntry) -> None:
"""Set up the proxy entry."""
async def async_setup_entry(
hass: HomeAssistant, entry: HASSWebProxyConfigEntry
) -> None:
"""Set up the HASS web proxy entry."""
session = async_get_clientsession(hass)
hass.http.register_view(V0ProxyView(hass, session))

entry.runtime_data = HASSProxyData(
entry.runtime_data = HASSWebProxyData(
integration=async_get_loaded_integration(hass, entry.domain),
dynamic_proxied_urls={},
)
Expand Down Expand Up @@ -146,7 +140,9 @@ def delete_proxied_url(call: ServiceCall) -> None:


@callback
async def async_unload_entry(hass: HomeAssistant, entry: HASSProxyConfigEntry) -> None:
async def async_unload_entry(
hass: HomeAssistant, entry: HASSWebProxyConfigEntry
) -> None:
"""Unload the proxy entry."""
if entry.options.get(CONF_DYNAMIC_URLS):
hass.services.async_remove(DOMAIN, SERVICE_CREATE_PROXIED_URL)
Expand All @@ -157,11 +153,11 @@ class HAProxyView(ProxyView):
"""A proxy view for HomeAssistant."""

def __init__(self, hass: HomeAssistant, websession: aiohttp.ClientSession) -> None:
"""Initialize the HASS Proxy view."""
"""Initialize the HASS Web Proxy view."""
self._hass = hass
super().__init__(websession)

def _get_config_entry(self) -> HASSProxyConfigEntry:
def _get_config_entry(self) -> HASSWebProxyConfigEntry:
"""Get the config entry."""
return self._hass.config_entries.async_entries(DOMAIN)[0]

Expand All @@ -176,7 +172,7 @@ def _get_options(self) -> MappingProxyType[str, Any]:
def _get_proxied_url(self, request: web.Request) -> ProxiedURL:
"""Get the URL to proxy."""
if "url" not in request.query:
raise HASSProxyLibNotFoundRequestError
raise HASSWebProxyLibNotFoundRequestError

options = self._get_options()
url_to_proxy = urllib.parse.unquote(request.query["url"])
Expand Down Expand Up @@ -218,18 +214,18 @@ def _get_proxied_url(self, request: web.Request) -> ProxiedURL:
)

if has_expired_match:
raise HASSProxyLibExpiredError
raise HASSProxyLibNotFoundRequestError
raise HASSWebProxyLibExpiredError
raise HASSWebProxyLibNotFoundRequestError

def _get_ssl_context_no_verify(
self, ssl_cipher: HASSProxySSLCiphers
self, ssl_cipher: HASSWebProxySSLCiphers
) -> ssl.SSLContext:
"""Get an SSL context."""
return client_context_no_verify(
self._proxy_ssl_cipher_to_ha_ssl_cipher(ssl_cipher)
)

def _get_ssl_context(self, ssl_ciphers: HASSProxySSLCiphers) -> ssl.SSLContext:
def _get_ssl_context(self, ssl_ciphers: HASSWebProxySSLCiphers) -> ssl.SSLContext:
"""Get an SSL context."""
return client_context(self._proxy_ssl_cipher_to_ha_ssl_cipher(ssl_ciphers))

Expand All @@ -243,5 +239,5 @@ def _proxy_ssl_cipher_to_ha_ssl_cipher(self, ssl_ciphers: str) -> SSLCipherList:
class V0ProxyView(HAProxyView):
"""A v0 proxy endpoint."""

url = "/api/hass_proxy/v0/"
name = "api:hass_proxy:v0"
url = "/api/hass_web_proxy/v0/"
name = "api:hass_web_proxy:v0"
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
"""HASS Proxy proxy."""
"""HASS Web Proxy proxy."""

from __future__ import annotations

Expand All @@ -23,23 +23,23 @@
from multidict import CIMultiDict


class HASSProxyLibError(Exception):
class HASSWebProxyLibError(Exception):
"""Exception to indicate a general Proxy error."""


class HASSProxyLibBadRequestError(HASSProxyLibError):
class HASSWebProxyLibBadRequestError(HASSWebProxyLibError):
"""Exception to indicate a bad request."""


class HASSProxyLibForbiddenRequestError(HASSProxyLibError):
class HASSWebProxyLibForbiddenRequestError(HASSWebProxyLibError):
"""Exception to indicate a bad request."""


class HASSProxyLibNotFoundRequestError(HASSProxyLibError):
class HASSWebProxyLibNotFoundRequestError(HASSWebProxyLibError):
"""Exception to indicate something being not found."""


class HASSProxyLibExpiredError(HASSProxyLibError):
class HASSWebProxyLibExpiredError(HASSWebProxyLibError):
"""Exception to indicate a URL match that has expired."""


Expand All @@ -66,7 +66,7 @@ def __init__(
self,
websession: aiohttp.ClientSession,
) -> None:
"""Initialize the HASS Proxy view."""
"""Initialize the HASS Web Proxy view."""
self._websession = websession

async def get(
Expand Down Expand Up @@ -94,13 +94,13 @@ def _get_proxied_url_or_handle_error(
"""Get the proxied URL or handle error."""
try:
url = self._get_proxied_url(request, **kwargs)
except HASSProxyLibForbiddenRequestError:
except HASSWebProxyLibForbiddenRequestError:
return web.Response(status=HTTPStatus.FORBIDDEN)
except HASSProxyLibNotFoundRequestError:
except HASSWebProxyLibNotFoundRequestError:
return web.Response(status=HTTPStatus.NOT_FOUND)
except HASSProxyLibBadRequestError:
except HASSWebProxyLibBadRequestError:
return web.Response(status=HTTPStatus.BAD_REQUEST)
except HASSProxyLibExpiredError:
except HASSWebProxyLibExpiredError:
return web.Response(status=HTTPStatus.GONE)

if not url or not url.url:
Expand Down
File renamed without changes.
2 changes: 1 addition & 1 deletion hacs.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"name": "Home Assistant Proxy",
"name": "Home Assistant Web Proxy",
"hide_default_branch": true,
"homeassistant": "2024.6.0",
"render_readme": true
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ norecursedirs = [
".git",
"testing_config",
]
addopts = "--timeout=10 --cov-report=xml:coverage.xml --cov-report=term-missing --cov=custom_components.hass_proxy --cov-fail-under=100"
addopts = "--timeout=10 --cov-report=xml:coverage.xml --cov-report=term-missing --cov=custom_components.hass_web_proxy --cov-fail-under=100"

[tool.coverage.report]
exclude_also = [
Expand Down
Loading

0 comments on commit efe75b1

Please sign in to comment.