forked from shaba/openuds
Added better transpor selection for tickets
This commit is contained in:
parent
9a59725504
commit
fe6c701e44
@ -39,6 +39,7 @@ from uds.models import DeployedService
|
||||
from uds.models import Transport
|
||||
from uds.models import TicketStore
|
||||
from uds.core.util.model import processUuid
|
||||
from uds.core.util import tools
|
||||
|
||||
import datetime
|
||||
import six
|
||||
@ -47,7 +48,7 @@ import logging
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
VALID_PARAMS = ('authId', 'authTag', 'authSmallName', 'auth', 'username', 'realname', 'password', 'groups', 'servicePool', 'transport', 'force')
|
||||
VALID_PARAMS = ('authId', 'authTag', 'authSmallName', 'auth', 'username', 'realname', 'password', 'groups', 'servicePool', 'transport', 'force', 'userIp')
|
||||
|
||||
|
||||
# Enclosed methods under /actor path
|
||||
@ -122,6 +123,8 @@ class Tickets(Handler):
|
||||
|
||||
force = self._params.get('force', '0') in ('1', 'true', 'True')
|
||||
|
||||
userIp = self._params.get('userIp', None)
|
||||
|
||||
try:
|
||||
authId = self._params.get('authId', None)
|
||||
authTag = self._params.get('authTag', self._params.get('authSmallName', None))
|
||||
@ -177,13 +180,21 @@ class Tickets(Handler):
|
||||
logger.error('Transport {} is not valid for Service Pool {}'.format(transport.name, servicePool.name))
|
||||
raise Exception('Invalid transport for Service Pool')
|
||||
else:
|
||||
transport = servicePool.transports.order_by('priority').first()
|
||||
if transport is None:
|
||||
logger.error('Service pool {} does not has transports')
|
||||
raise Exception('Service pool does not has any assigned transports')
|
||||
if userIp is None:
|
||||
transport = tools.DictAsObj({'uuid': None})
|
||||
else:
|
||||
transport = None
|
||||
for v in servicePool.transports.order_by('priority'):
|
||||
if v.validForIp(userIp):
|
||||
transport = v
|
||||
break
|
||||
|
||||
if transport is None:
|
||||
logger.error('Service pool {} does not has valid transports for ip {}'.format(servicePool.name, userIp))
|
||||
raise Exception('Service pool does not has any valid transports for ip {}'.format(userIp))
|
||||
|
||||
servicePool = servicePool.uuid
|
||||
transport = transport.uuid
|
||||
transport = transport.uuid # pylint: disable=maybe-no-member
|
||||
|
||||
except Authenticator.DoesNotExist:
|
||||
return Tickets.result(error='Authenticator does not exists')
|
||||
|
@ -51,7 +51,7 @@ import requests
|
||||
import json
|
||||
import logging
|
||||
|
||||
__updated__ = '2015-10-15'
|
||||
__updated__ = '2015-11-05'
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
@ -555,7 +555,17 @@ class UserServiceManager(object):
|
||||
raise ServiceInMaintenanceMode()
|
||||
|
||||
logger.debug('Found service: {0}'.format(userService))
|
||||
trans = Transport.objects.get(uuid=idTransport)
|
||||
|
||||
if idTransport is None: # Find a suitable transport
|
||||
for v in userService.deployed_service.transports.order_by('priority'):
|
||||
if v.validForIp(srcIp):
|
||||
idTransport = v.uuid
|
||||
break
|
||||
|
||||
try:
|
||||
trans = Transport.objects.get(uuid=idTransport)
|
||||
except Exception:
|
||||
raise InvalidServiceException()
|
||||
|
||||
# Ensures that the transport is allowed for this service
|
||||
if trans not in userService.deployed_service.transports.all():
|
||||
|
Loading…
x
Reference in New Issue
Block a user