1
mirror of https://github.com/home-assistant/core synced 2024-09-12 15:16:21 +02:00

Synology chat add verify ssl (#19276)

* Update synology_chat.py

* Added verify_ssl option to notify.synology_chat

Python requests will verify ssl by default, this configuration options allows the user to specify if they want to verify ssl or not. Non breaking change, default is True - do verify ssl.
This commit is contained in:
bremor 2018-12-14 18:42:01 +11:00 committed by Fabian Affolter
parent ddbfdf14e9
commit 74a93fe764

View File

@ -12,13 +12,14 @@ import voluptuous as vol
from homeassistant.components.notify import ( from homeassistant.components.notify import (
BaseNotificationService, PLATFORM_SCHEMA, ATTR_DATA) BaseNotificationService, PLATFORM_SCHEMA, ATTR_DATA)
from homeassistant.const import CONF_RESOURCE from homeassistant.const import CONF_RESOURCE, CONF_VERIFY_SSL
import homeassistant.helpers.config_validation as cv import homeassistant.helpers.config_validation as cv
ATTR_FILE_URL = 'file_url' ATTR_FILE_URL = 'file_url'
PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend({ PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend({
vol.Required(CONF_RESOURCE): cv.url, vol.Required(CONF_RESOURCE): cv.url,
vol.Optional(CONF_VERIFY_SSL, default=True): cv.boolean,
}) })
_LOGGER = logging.getLogger(__name__) _LOGGER = logging.getLogger(__name__)
@ -27,16 +28,18 @@ _LOGGER = logging.getLogger(__name__)
def get_service(hass, config, discovery_info=None): def get_service(hass, config, discovery_info=None):
"""Get the Synology Chat notification service.""" """Get the Synology Chat notification service."""
resource = config.get(CONF_RESOURCE) resource = config.get(CONF_RESOURCE)
verify_ssl = config.get(CONF_VERIFY_SSL)
return SynologyChatNotificationService(resource) return SynologyChatNotificationService(resource, verify_ssl)
class SynologyChatNotificationService(BaseNotificationService): class SynologyChatNotificationService(BaseNotificationService):
"""Implementation of a notification service for Synology Chat.""" """Implementation of a notification service for Synology Chat."""
def __init__(self, resource): def __init__(self, resource, verify_ssl):
"""Initialize the service.""" """Initialize the service."""
self._resource = resource self._resource = resource
self._verify_ssl = verify_ssl
def send_message(self, message="", **kwargs): def send_message(self, message="", **kwargs):
"""Send a message to a user.""" """Send a message to a user."""
@ -52,7 +55,8 @@ class SynologyChatNotificationService(BaseNotificationService):
to_send = 'payload={}'.format(json.dumps(data)) to_send = 'payload={}'.format(json.dumps(data))
response = requests.post(self._resource, data=to_send, timeout=10) response = requests.post(self._resource, data=to_send, timeout=10,
verify=self._verify_ssl)
if response.status_code not in (200, 201): if response.status_code not in (200, 201):
_LOGGER.exception( _LOGGER.exception(