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 Transport
|
||||||
from uds.models import TicketStore
|
from uds.models import TicketStore
|
||||||
from uds.core.util.model import processUuid
|
from uds.core.util.model import processUuid
|
||||||
|
from uds.core.util import tools
|
||||||
|
|
||||||
import datetime
|
import datetime
|
||||||
import six
|
import six
|
||||||
@ -47,7 +48,7 @@ import logging
|
|||||||
|
|
||||||
logger = logging.getLogger(__name__)
|
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
|
# Enclosed methods under /actor path
|
||||||
@ -122,6 +123,8 @@ class Tickets(Handler):
|
|||||||
|
|
||||||
force = self._params.get('force', '0') in ('1', 'true', 'True')
|
force = self._params.get('force', '0') in ('1', 'true', 'True')
|
||||||
|
|
||||||
|
userIp = self._params.get('userIp', None)
|
||||||
|
|
||||||
try:
|
try:
|
||||||
authId = self._params.get('authId', None)
|
authId = self._params.get('authId', None)
|
||||||
authTag = self._params.get('authTag', self._params.get('authSmallName', 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))
|
logger.error('Transport {} is not valid for Service Pool {}'.format(transport.name, servicePool.name))
|
||||||
raise Exception('Invalid transport for Service Pool')
|
raise Exception('Invalid transport for Service Pool')
|
||||||
else:
|
else:
|
||||||
transport = servicePool.transports.order_by('priority').first()
|
if userIp is None:
|
||||||
if transport is None:
|
transport = tools.DictAsObj({'uuid': None})
|
||||||
logger.error('Service pool {} does not has transports')
|
else:
|
||||||
raise Exception('Service pool does not has any assigned transports')
|
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
|
servicePool = servicePool.uuid
|
||||||
transport = transport.uuid
|
transport = transport.uuid # pylint: disable=maybe-no-member
|
||||||
|
|
||||||
except Authenticator.DoesNotExist:
|
except Authenticator.DoesNotExist:
|
||||||
return Tickets.result(error='Authenticator does not exists')
|
return Tickets.result(error='Authenticator does not exists')
|
||||||
|
@ -51,7 +51,7 @@ import requests
|
|||||||
import json
|
import json
|
||||||
import logging
|
import logging
|
||||||
|
|
||||||
__updated__ = '2015-10-15'
|
__updated__ = '2015-11-05'
|
||||||
|
|
||||||
logger = logging.getLogger(__name__)
|
logger = logging.getLogger(__name__)
|
||||||
|
|
||||||
@ -555,7 +555,17 @@ class UserServiceManager(object):
|
|||||||
raise ServiceInMaintenanceMode()
|
raise ServiceInMaintenanceMode()
|
||||||
|
|
||||||
logger.debug('Found service: {0}'.format(userService))
|
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
|
# Ensures that the transport is allowed for this service
|
||||||
if trans not in userService.deployed_service.transports.all():
|
if trans not in userService.deployed_service.transports.all():
|
||||||
|
Loading…
Reference in New Issue
Block a user