Skip to content

Commit

Permalink
refactor: Rename to hass-web-proxy-integration
Browse files Browse the repository at this point in the history
  • Loading branch information
dermotduffy committed Oct 23, 2024
1 parent a0399ce commit 6311536
Show file tree
Hide file tree
Showing 21 changed files with 415 additions and 148 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.
6 changes: 3 additions & 3 deletions custom_components/hass_proxy/const.py
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
12 changes: 0 additions & 12 deletions custom_components/hass_proxy/manifest.json

This file was deleted.

56 changes: 26 additions & 30 deletions custom_components/hass_proxy/proxy.py
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
Expand Up @@ -2,7 +2,7 @@
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
Expand All @@ -15,7 +15,7 @@
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 +26,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 +39,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,11 @@ 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
34 changes: 34 additions & 0 deletions custom_components/hass_web_proxy/const.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
"""Constants for HASS Web Proxy."""

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

DOMAIN: Final = "hass_web_proxy"

LOGGER: Logger = getLogger(__package__)

CONF_SSL_VERIFICATION: Final = "ssl_verification"
CONF_SSL_CIPHERS: Final = "ssl_ciphers"

CONF_SSL_CIPHERS_INSECURE: Final = "insecure"
CONF_SSL_CIPHERS_MODERN: Final = "modern"
CONF_SSL_CIPHERS_INTERMEDIATE: Final = "intermediate"
CONF_SSL_CIPHERS_DEFAULT: Final = "default"

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

CONF_DYNAMIC_URLS: Final = "dynamic_urls"
CONF_OPEN_LIMIT: Final = "open_limit"
CONF_TTL: Final = "ttl"
CONF_URL_ID: Final = "url_id"
CONF_URL_PATTERN: Final = "url_pattern"
CONF_URL_PATTERNS: Final = "url_patterns"

SERVICE_CREATE_PROXIED_URL: Final = "create_proxied_url"
SERVICE_DELETE_PROXIED_URL: Final = "delete_proxied_url"

DEFAULT_OPTIONS: dict[str, str | bool | list[str]] = {
CONF_SSL_VERIFICATION: True,
CONF_DYNAMIC_URLS: True,
CONF_SSL_CIPHERS: CONF_SSL_CIPHERS_DEFAULT,
}
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"
}
Loading

0 comments on commit 6311536

Please sign in to comment.