mirror of
https://github.com/home-assistant/core.git
synced 2025-07-17 10:17:09 +00:00
Support for Plex servers with enforced SSL (#8341)
* Support for Plex servers with enforced SSL * Fixed HoundCI warnings * Fixed HoundCI warnings (2nd) * Configurator data validation * Travis linting
This commit is contained in:
parent
9704057959
commit
229000b834
@ -82,8 +82,17 @@ def setup_platform(hass, config, add_devices_callback, discovery_info=None):
|
|||||||
|
|
||||||
if file_config:
|
if file_config:
|
||||||
# Setup a configured PlexServer
|
# Setup a configured PlexServer
|
||||||
host, token = file_config.popitem()
|
host, host_config = file_config.popitem()
|
||||||
token = token['token']
|
token = host_config['token']
|
||||||
|
try:
|
||||||
|
has_ssl = host_config['ssl']
|
||||||
|
except KeyError:
|
||||||
|
has_ssl = False
|
||||||
|
try:
|
||||||
|
verify_ssl = host_config['verify']
|
||||||
|
except KeyError:
|
||||||
|
verify_ssl = True
|
||||||
|
|
||||||
# Via discovery
|
# Via discovery
|
||||||
elif discovery_info is not None:
|
elif discovery_info is not None:
|
||||||
# Parse discovery data
|
# Parse discovery data
|
||||||
@ -95,19 +104,34 @@ def setup_platform(hass, config, add_devices_callback, discovery_info=None):
|
|||||||
if host in _CONFIGURING:
|
if host in _CONFIGURING:
|
||||||
return
|
return
|
||||||
token = None
|
token = None
|
||||||
|
has_ssl = False
|
||||||
|
verify_ssl = True
|
||||||
else:
|
else:
|
||||||
return
|
return
|
||||||
|
|
||||||
setup_plexserver(host, token, hass, config, add_devices_callback)
|
setup_plexserver(
|
||||||
|
host, token, has_ssl, verify_ssl,
|
||||||
|
hass, config, add_devices_callback
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
def setup_plexserver(host, token, hass, config, add_devices_callback):
|
def setup_plexserver(
|
||||||
|
host, token, has_ssl, verify_ssl, hass, config, add_devices_callback):
|
||||||
"""Set up a plexserver based on host parameter."""
|
"""Set up a plexserver based on host parameter."""
|
||||||
import plexapi.server
|
import plexapi.server
|
||||||
import plexapi.exceptions
|
import plexapi.exceptions
|
||||||
|
|
||||||
|
cert_session = None
|
||||||
|
http_prefix = 'https' if has_ssl else 'http'
|
||||||
|
if has_ssl and (verify_ssl is False):
|
||||||
|
_LOGGER.info("Ignoring SSL verification")
|
||||||
|
cert_session = requests.Session()
|
||||||
|
cert_session.verify = False
|
||||||
try:
|
try:
|
||||||
plexserver = plexapi.server.PlexServer('http://%s' % host, token)
|
plexserver = plexapi.server.PlexServer(
|
||||||
|
'%s://%s' % (http_prefix, host),
|
||||||
|
token, cert_session
|
||||||
|
)
|
||||||
_LOGGER.info("Discovery configuration done (no token needed)")
|
_LOGGER.info("Discovery configuration done (no token needed)")
|
||||||
except (plexapi.exceptions.BadRequest, plexapi.exceptions.Unauthorized,
|
except (plexapi.exceptions.BadRequest, plexapi.exceptions.Unauthorized,
|
||||||
plexapi.exceptions.NotFound) as error:
|
plexapi.exceptions.NotFound) as error:
|
||||||
@ -126,11 +150,13 @@ def setup_plexserver(host, token, hass, config, add_devices_callback):
|
|||||||
# Save config
|
# Save config
|
||||||
if not config_from_file(
|
if not config_from_file(
|
||||||
hass.config.path(PLEX_CONFIG_FILE), {host: {
|
hass.config.path(PLEX_CONFIG_FILE), {host: {
|
||||||
'token': token
|
'token': token,
|
||||||
|
'ssl': has_ssl,
|
||||||
|
'verify': verify_ssl,
|
||||||
}}):
|
}}):
|
||||||
_LOGGER.error("Failed to save configuration file")
|
_LOGGER.error("Failed to save configuration file")
|
||||||
|
|
||||||
_LOGGER.info('Connected to: http://%s', host)
|
_LOGGER.info('Connected to: %s://%s', http_prefix, host)
|
||||||
|
|
||||||
plex_clients = {}
|
plex_clients = {}
|
||||||
plex_sessions = {}
|
plex_sessions = {}
|
||||||
@ -217,7 +243,11 @@ def request_configuration(host, hass, config, add_devices_callback):
|
|||||||
def plex_configuration_callback(data):
|
def plex_configuration_callback(data):
|
||||||
"""Handle configuration changes."""
|
"""Handle configuration changes."""
|
||||||
setup_plexserver(
|
setup_plexserver(
|
||||||
host, data.get('token'), hass, config, add_devices_callback)
|
host, data.get('token'),
|
||||||
|
cv.boolean(data.get('has_ssl')),
|
||||||
|
cv.boolean(data.get('do_not_verify')),
|
||||||
|
hass, config, add_devices_callback
|
||||||
|
)
|
||||||
|
|
||||||
_CONFIGURING[host] = configurator.request_config(
|
_CONFIGURING[host] = configurator.request_config(
|
||||||
hass,
|
hass,
|
||||||
@ -230,6 +260,14 @@ def request_configuration(host, hass, config, add_devices_callback):
|
|||||||
'id': 'token',
|
'id': 'token',
|
||||||
'name': 'X-Plex-Token',
|
'name': 'X-Plex-Token',
|
||||||
'type': ''
|
'type': ''
|
||||||
|
}, {
|
||||||
|
'id': 'has_ssl',
|
||||||
|
'name': 'Use SSL',
|
||||||
|
'type': ''
|
||||||
|
}, {
|
||||||
|
'id': 'do_not_verify_ssl',
|
||||||
|
'name': 'Do not verify SSL',
|
||||||
|
'type': ''
|
||||||
}])
|
}])
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user