Set webhook `local_only` to True by default (#107670)
parent
52acc4bbab
commit
bd37d3776b
|
@ -1,8 +0,0 @@
|
||||||
{
|
|
||||||
"issues": {
|
|
||||||
"trigger_missing_local_only": {
|
|
||||||
"title": "Update webhook trigger: {webhook_id}",
|
|
||||||
"description": "A choice needs to be made about whether the {webhook_id} webhook automation trigger is accessible from the internet. [Edit the automation]({edit}) \"{automation_name}\", (`{entity_id}`) and click the gear icon beside the Webhook ID to choose a value for 'Only accessible from the local network'"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -11,11 +11,6 @@ import voluptuous as vol
|
||||||
from homeassistant.const import CONF_PLATFORM, CONF_WEBHOOK_ID
|
from homeassistant.const import CONF_PLATFORM, CONF_WEBHOOK_ID
|
||||||
from homeassistant.core import CALLBACK_TYPE, HassJob, HomeAssistant, callback
|
from homeassistant.core import CALLBACK_TYPE, HassJob, HomeAssistant, callback
|
||||||
import homeassistant.helpers.config_validation as cv
|
import homeassistant.helpers.config_validation as cv
|
||||||
from homeassistant.helpers.issue_registry import (
|
|
||||||
IssueSeverity,
|
|
||||||
async_create_issue,
|
|
||||||
async_delete_issue,
|
|
||||||
)
|
|
||||||
from homeassistant.helpers.trigger import TriggerActionType, TriggerInfo
|
from homeassistant.helpers.trigger import TriggerActionType, TriggerInfo
|
||||||
from homeassistant.helpers.typing import ConfigType
|
from homeassistant.helpers.typing import ConfigType
|
||||||
|
|
||||||
|
@ -88,31 +83,7 @@ async def async_attach_trigger(
|
||||||
) -> CALLBACK_TYPE:
|
) -> CALLBACK_TYPE:
|
||||||
"""Trigger based on incoming webhooks."""
|
"""Trigger based on incoming webhooks."""
|
||||||
webhook_id: str = config[CONF_WEBHOOK_ID]
|
webhook_id: str = config[CONF_WEBHOOK_ID]
|
||||||
local_only = config.get(CONF_LOCAL_ONLY)
|
local_only = config.get(CONF_LOCAL_ONLY, True)
|
||||||
issue_id: str | None = None
|
|
||||||
if local_only is None:
|
|
||||||
issue_id = f"trigger_missing_local_only_{webhook_id}"
|
|
||||||
variables = trigger_info["variables"] or {}
|
|
||||||
automation_info = variables.get("this", {})
|
|
||||||
automation_id = automation_info.get("attributes", {}).get("id")
|
|
||||||
automation_entity_id = automation_info.get("entity_id")
|
|
||||||
automation_name = trigger_info.get("name") or automation_entity_id
|
|
||||||
async_create_issue(
|
|
||||||
hass,
|
|
||||||
DOMAIN,
|
|
||||||
issue_id,
|
|
||||||
breaks_in_ha_version="2023.11.0",
|
|
||||||
is_fixable=False,
|
|
||||||
severity=IssueSeverity.WARNING,
|
|
||||||
learn_more_url="https://www.home-assistant.io/docs/automation/trigger/#webhook-trigger",
|
|
||||||
translation_key="trigger_missing_local_only",
|
|
||||||
translation_placeholders={
|
|
||||||
"webhook_id": webhook_id,
|
|
||||||
"automation_name": automation_name,
|
|
||||||
"entity_id": automation_entity_id,
|
|
||||||
"edit": f"/config/automation/edit/{automation_id}",
|
|
||||||
},
|
|
||||||
)
|
|
||||||
allowed_methods = config.get(CONF_ALLOWED_METHODS, DEFAULT_METHODS)
|
allowed_methods = config.get(CONF_ALLOWED_METHODS, DEFAULT_METHODS)
|
||||||
job = HassJob(action)
|
job = HassJob(action)
|
||||||
|
|
||||||
|
@ -138,8 +109,6 @@ async def async_attach_trigger(
|
||||||
@callback
|
@callback
|
||||||
def unregister() -> None:
|
def unregister() -> None:
|
||||||
"""Unregister webhook."""
|
"""Unregister webhook."""
|
||||||
if issue_id:
|
|
||||||
async_delete_issue(hass, DOMAIN, issue_id)
|
|
||||||
triggers[webhook_id].remove(trigger_instance)
|
triggers[webhook_id].remove(trigger_instance)
|
||||||
if not triggers[webhook_id]:
|
if not triggers[webhook_id]:
|
||||||
async_unregister(hass, webhook_id)
|
async_unregister(hass, webhook_id)
|
||||||
|
|
|
@ -150,7 +150,7 @@ async def test_webhook_allowed_methods_internet(
|
||||||
"platform": "webhook",
|
"platform": "webhook",
|
||||||
"webhook_id": "post_webhook",
|
"webhook_id": "post_webhook",
|
||||||
"allowed_methods": "PUT",
|
"allowed_methods": "PUT",
|
||||||
# Enable after 2023.11.0: "local_only": False,
|
"local_only": False,
|
||||||
},
|
},
|
||||||
"action": {
|
"action": {
|
||||||
"event": "test_success",
|
"event": "test_success",
|
||||||
|
|
Loading…
Reference in New Issue