Prepare connect ssl support

This commit is contained in:
angelblue05 2016-10-20 03:29:24 -05:00
parent 0fa91e1f5d
commit afacc8b978

View file

@ -172,8 +172,8 @@ class ConnectionManager(object):
raise AttributeError("Request cannot be null") raise AttributeError("Request cannot be null")
self._getHeaders(request) self._getHeaders(request)
request['timeout'] = request.get('timeout') or self.default_timeout request['timeout'] = request.get('timeout', self.default_timeout)
request['verify'] = False request['verify'] = request.get('ssl') or False
action = request['type'] action = request['type']
request.pop('type') request.pop('type')
@ -307,7 +307,7 @@ class ConnectionManager(object):
return self._resolveFailure() return self._resolveFailure()
try: try:
publicInfo = self._tryConnect(address) publicInfo = self._tryConnect(address, options)
except Exception: except Exception:
return _onFail() return _onFail()
else: else:
@ -343,7 +343,7 @@ class ConnectionManager(object):
self._saveUserInfoIntoCredentials(server, result['User']) self._saveUserInfoIntoCredentials(server, result['User'])
self.credentialProvider.getCredentials(credentials) self.credentialProvider.getCredentials(credentials)
def _tryConnect(self, url, timeout=None): def _tryConnect(self, url, timeout=None, options={}):
url = self.getEmbyServerUrl(url, "system/info/public") url = self.getEmbyServerUrl(url, "system/info/public")
log.info("tryConnect url: %s" % url) log.info("tryConnect url: %s" % url)
@ -353,7 +353,8 @@ class ConnectionManager(object):
'type': "GET", 'type': "GET",
'url': url, 'url': url,
'dataType': "json", 'dataType': "json",
'timeout': timeout 'timeout': timeout,
'ssl': options.get('ssl')
}) })
def _addAppInfoToConnectRequest(self): def _addAppInfoToConnectRequest(self):
@ -536,7 +537,7 @@ class ConnectionManager(object):
log.info("testing connection mode %s with server %s" % (mode, server['Name'])) log.info("testing connection mode %s with server %s" % (mode, server['Name']))
try: try:
result = self._tryConnect(address, timeout) result = self._tryConnect(address, timeout, options)
except Exception: except Exception:
log.error("test failed for connection mode %s with server %s" % (mode, server['Name'])) log.error("test failed for connection mode %s with server %s" % (mode, server['Name']))
@ -569,7 +570,7 @@ class ConnectionManager(object):
if server.get('ExchangeToken'): if server.get('ExchangeToken'):
self._addAuthenticationInfoFromConnect(server, connectionMode, credentials) self._addAuthenticationInfoFromConnect(server, connectionMode, credentials, options)
return self._afterConnectValidated(server, credentials, systemInfo, connectionMode, True, options) return self._afterConnectValidated(server, credentials, systemInfo, connectionMode, True, options)
@ -582,10 +583,10 @@ class ConnectionManager(object):
elif (verifyLocalAuthentication and server.get('AccessToken') and elif (verifyLocalAuthentication and server.get('AccessToken') and
options.get('enableAutoLogin') is not False): options.get('enableAutoLogin') is not False):
if self._validateAuthentication(server, connectionMode) is not False: if self._validateAuthentication(server, connectionMode, options) is not False:
return self._afterConnectValidated(server, credentials, systemInfo, connectionMode, False, options) return self._afterConnectValidated(server, credentials, systemInfo, connectionMode, False, options)
return self._resolveFailure() return
self._updateServerInfo(server, systemInfo) self._updateServerInfo(server, systemInfo)
server['LastConnectionMode'] = connectionMode server['LastConnectionMode'] = connectionMode
@ -606,13 +607,14 @@ class ConnectionManager(object):
# Connected # Connected
return result return result
def _validateAuthentication(self, server, connectionMode): def _validateAuthentication(self, server, connectionMode, options={}):
url = getServerAddress(server, connectionMode) url = getServerAddress(server, connectionMode)
request = { request = {
'type': "GET", 'type': "GET",
'url': self.getEmbyServerUrl(url, "System/Info"), 'url': self.getEmbyServerUrl(url, "System/Info"),
'ssl': options.get('ssl'),
'dataType': "json", 'dataType': "json",
'headers': { 'headers': {
'X-MediaBrowser-Token': server['AccessToken'] 'X-MediaBrowser-Token': server['AccessToken']
@ -627,6 +629,7 @@ class ConnectionManager(object):
'type': "GET", 'type': "GET",
'url': self.getEmbyServerUrl(url, "users/%s" % server['UserId']), 'url': self.getEmbyServerUrl(url, "users/%s" % server['UserId']),
'ssl': options.get('ssl'),
'dataType': "json", 'dataType': "json",
'headers': { 'headers': {
'X-MediaBrowser-Token': server['AccessToken'] 'X-MediaBrowser-Token': server['AccessToken']
@ -696,7 +699,7 @@ class ConnectionManager(object):
} }
}) })
def _addAuthenticationInfoFromConnect(self, server, connectionMode, credentials): def _addAuthenticationInfoFromConnect(self, server, connectionMode, credentials, options={}):
if not server.get('ExchangeToken'): if not server.get('ExchangeToken'):
raise KeyError("server['ExchangeToken'] cannot be null") raise KeyError("server['ExchangeToken'] cannot be null")
@ -714,6 +717,7 @@ class ConnectionManager(object):
'url': url, 'url': url,
'type': "GET", 'type': "GET",
'dataType': "json", 'dataType': "json",
'ssl': options.get('ssl'),
'params': { 'params': {
'ConnectUserId': credentials['ConnectUserId'] 'ConnectUserId': credentials['ConnectUserId']
}, },
@ -759,7 +763,7 @@ class ConnectionManager(object):
if len(servers) == 1: if len(servers) == 1:
result = self.connectToServer(servers[0], options) result = self.connectToServer(servers[0], options)
if result.get('State') == ConnectionState['Unavailable']: if result and result.get('State') == ConnectionState['Unavailable']:
result['State'] = ConnectionState['ConnectSignIn'] if result['ConnectUser'] == None else ConnectionState['ServerSelection'] result['State'] = ConnectionState['ConnectSignIn'] if result['ConnectUser'] == None else ConnectionState['ServerSelection']
log.info("resolving connectToServers with result['State']: %s" % result) log.info("resolving connectToServers with result['State']: %s" % result)