mirror of
https://github.com/dkmstr/openuds.git
synced 2025-01-22 22:03:54 +03:00
Refactor code to generate ServiceInfo and some minor fixes
This commit is contained in:
parent
c794b2befa
commit
6248ac69af
@ -43,9 +43,6 @@ from uds.core.util.rest.tools import match
|
||||
from uds.models import TicketStore, User
|
||||
from uds.REST import Handler
|
||||
|
||||
if typing.TYPE_CHECKING:
|
||||
from uds.models import UserService
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
CLIENT_VERSION = consts.system.VERSION
|
||||
@ -107,7 +104,7 @@ class Client(Handler):
|
||||
return Client.result(_('Correct'))
|
||||
|
||||
def process(self, ticket: str, scrambler: str) -> dict[str, typing.Any]:
|
||||
userService: typing.Optional['UserService'] = None
|
||||
info: typing.Optional[types.services.UserServiceInfo] = None
|
||||
hostname = self._params.get('hostname', '') # Or if hostname is not included...
|
||||
version = self._params.get('version', '0.0.0')
|
||||
srcIp = self._request.ip
|
||||
@ -136,13 +133,7 @@ class Client(Handler):
|
||||
|
||||
try:
|
||||
logger.debug(data)
|
||||
(
|
||||
ip,
|
||||
userService,
|
||||
userServiceInstance,
|
||||
transport,
|
||||
transportInstance,
|
||||
) = UserServiceManager.manager().get_user_service_info(
|
||||
info = UserServiceManager.manager().get_user_service_info(
|
||||
self._request.user,
|
||||
self._request.os,
|
||||
self._request.ip,
|
||||
@ -151,27 +142,19 @@ class Client(Handler):
|
||||
client_hostname=hostname,
|
||||
)
|
||||
logger.debug(
|
||||
'Res: %s %s %s %s %s',
|
||||
ip,
|
||||
userService,
|
||||
userServiceInstance,
|
||||
transport,
|
||||
transportInstance,
|
||||
'Res: %s',
|
||||
info
|
||||
)
|
||||
password = CryptoManager().symmetric_decrypt(data['password'], scrambler)
|
||||
|
||||
# userService.setConnectionSource(srcIp, hostname) # Store where we are accessing from so we can notify Service
|
||||
if not ip:
|
||||
if not info.ip:
|
||||
raise ServiceNotReadyError()
|
||||
|
||||
# This should never happen, but it's here just in case
|
||||
if not transportInstance:
|
||||
raise Exception('No transport instance!!!')
|
||||
|
||||
transport_script = transportInstance.encoded_transport_script(
|
||||
userService,
|
||||
transport,
|
||||
ip,
|
||||
transport_script = info.transport.get_instance().encoded_transport_script(
|
||||
info.userservice,
|
||||
info.transport,
|
||||
info.ip,
|
||||
self._request.os,
|
||||
self._request.user,
|
||||
password,
|
||||
@ -201,8 +184,8 @@ class Client(Handler):
|
||||
finally:
|
||||
# ensures that we mark the service as accessed by client
|
||||
# so web interface can show can react to this
|
||||
if userService:
|
||||
userService.properties['accessed_by_client'] = True
|
||||
if info and info.userservice:
|
||||
info.userservice.properties['accessed_by_client'] = True
|
||||
|
||||
def get(self) -> dict[str, typing.Any]:
|
||||
"""
|
||||
|
@ -44,9 +44,6 @@ from uds.web.util import services
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
if typing.TYPE_CHECKING:
|
||||
from uds import models
|
||||
|
||||
|
||||
# Enclosed methods under /connection path
|
||||
class Connection(Handler):
|
||||
@ -90,39 +87,33 @@ class Connection(Handler):
|
||||
# Ensure user is present on request, used by web views methods
|
||||
self._request.user = self._user
|
||||
|
||||
return Connection.result(
|
||||
result=services.get_services_info_dict(self._request)
|
||||
)
|
||||
return Connection.result(result=services.get_services_info_dict(self._request))
|
||||
|
||||
def connection(self, idService: str, idTransport: str, skip: str = '') -> dict[str, typing.Any]:
|
||||
doNotCheck = skip in ('doNotCheck', 'do_not_check', 'no_check', 'nocheck')
|
||||
skip_check = skip in ('doNotCheck', 'do_not_check', 'no_check', 'nocheck', 'skip_check')
|
||||
try:
|
||||
(
|
||||
ip,
|
||||
userService,
|
||||
_, # iads,
|
||||
_, # trans,
|
||||
itrans,
|
||||
) = UserServiceManager.manager().get_user_service_info( # pylint: disable=unused-variable
|
||||
info = UserServiceManager.manager().get_user_service_info( # pylint: disable=unused-variable
|
||||
self._user,
|
||||
self._request.os,
|
||||
self._request.ip,
|
||||
idService,
|
||||
idTransport,
|
||||
not doNotCheck,
|
||||
not skip_check,
|
||||
)
|
||||
connectionInfoDict = {
|
||||
connection_info = {
|
||||
'username': '',
|
||||
'password': '',
|
||||
'domain': '',
|
||||
'protocol': 'unknown',
|
||||
'ip': ip,
|
||||
'ip': info.ip or '',
|
||||
}
|
||||
if itrans: # only will be available id doNotCheck is False
|
||||
connectionInfoDict.update(
|
||||
itrans.get_connection_info(userService, self._user, 'UNKNOWN').as_dict()
|
||||
if info.ip: # only will be available id doNotCheck is False
|
||||
connection_info.update(
|
||||
info.transport.get_instance()
|
||||
.get_connection_info(info.userservice, self._user, 'UNKNOWN')
|
||||
.as_dict()
|
||||
)
|
||||
return Connection.result(result=connectionInfoDict)
|
||||
return Connection.result(result=connection_info)
|
||||
except ServiceNotReadyError as e:
|
||||
# Refresh ticket and make this retrayable
|
||||
return Connection.result(
|
||||
@ -134,31 +125,22 @@ class Connection(Handler):
|
||||
|
||||
def script(self, idService: str, idTransport: str, scrambler: str, hostname: str) -> dict[str, typing.Any]:
|
||||
try:
|
||||
res = UserServiceManager.manager().get_user_service_info(
|
||||
info = UserServiceManager.manager().get_user_service_info(
|
||||
self._user, self._request.os, self._request.ip, idService, idTransport
|
||||
)
|
||||
userService: 'models.UserService'
|
||||
logger.debug('Res: %s', res)
|
||||
(
|
||||
ip,
|
||||
userService,
|
||||
_, # userServiceInstance,
|
||||
transport,
|
||||
transport_instance,
|
||||
) = res # pylint: disable=unused-variable
|
||||
password = CryptoManager().symmetric_decrypt(self.recover_value('password'), scrambler)
|
||||
password = CryptoManager.manager().symmetric_decrypt(self.recover_value('password'), scrambler)
|
||||
|
||||
userService.set_connection_source(
|
||||
info.userservice.set_connection_source(
|
||||
types.connections.ConnectionSource(self._request.ip, hostname)
|
||||
) # Store where we are accessing from so we can notify Service
|
||||
|
||||
if not ip or not transport_instance:
|
||||
if not info.ip:
|
||||
raise ServiceNotReadyError()
|
||||
|
||||
transportScript = transport_instance.encoded_transport_script(
|
||||
userService,
|
||||
transport,
|
||||
ip,
|
||||
transportScript = info.transport.get_instance().encoded_transport_script(
|
||||
info.userservice,
|
||||
info.transport,
|
||||
info.ip,
|
||||
self._request.os,
|
||||
self._user,
|
||||
password,
|
||||
@ -168,7 +150,9 @@ class Connection(Handler):
|
||||
return Connection.result(result=transportScript)
|
||||
except ServiceNotReadyError as e:
|
||||
# Refresh ticket and make this retrayable
|
||||
return Connection.result(error=types.errors.Error.SERVICE_IN_PREPARATION, error_code=e.code, is_retrayable=True)
|
||||
return Connection.result(
|
||||
error=types.errors.Error.SERVICE_IN_PREPARATION, error_code=e.code, is_retrayable=True
|
||||
)
|
||||
except Exception as e:
|
||||
logger.exception("Exception")
|
||||
return Connection.result(error=str(e))
|
||||
|
@ -39,7 +39,7 @@ from django.db import transaction
|
||||
from django.db.models import Q, Count, Case, When, IntegerField
|
||||
from django.utils.translation import gettext as _
|
||||
|
||||
from uds.core import consts, exceptions, services, transports, types
|
||||
from uds.core import consts, exceptions, types
|
||||
from uds.core.services.exceptions import (
|
||||
InvalidServiceException,
|
||||
MaxServicesReachedError,
|
||||
@ -411,16 +411,13 @@ class UserServiceManager(metaclass=singleton.Singleton):
|
||||
|
||||
pool_stat = types.services.ServicePoolStats(
|
||||
servicepool,
|
||||
l1_cache_count = counts['l1_cache_count'] + l1_cache_increased_by,
|
||||
l2_cache_count = counts['l2_cache_count'] + l2_cache_increased_by,
|
||||
assigned_count = counts['assigned_count'] + assigned_increased_by,
|
||||
l1_cache_count=counts['l1_cache_count'] + l1_cache_increased_by,
|
||||
l2_cache_count=counts['l2_cache_count'] + l2_cache_increased_by,
|
||||
assigned_count=counts['assigned_count'] + assigned_increased_by,
|
||||
)
|
||||
|
||||
# if we bypasses max cache, we will reduce it in first place. This is so because this will free resources on service provider
|
||||
logger.debug(
|
||||
"Examining %s",
|
||||
pool_stat
|
||||
)
|
||||
logger.debug("Examining %s", pool_stat)
|
||||
|
||||
# Check for cache overflow
|
||||
# We have more than we want
|
||||
@ -867,18 +864,31 @@ class UserServiceManager(metaclass=singleton.Singleton):
|
||||
def locate_user_service(
|
||||
self, user: User, id_service: str, create: bool = False
|
||||
) -> typing.Optional[UserService]:
|
||||
kind, uuid_user_service = id_service[0], id_service[1:]
|
||||
"""
|
||||
Locates a user service from a user and a service id
|
||||
|
||||
Args:
|
||||
user: User owner of the service
|
||||
id_service: Service id (A<uuid> for assigned, M<uuid> for meta, ?<uuid> for service pool)
|
||||
create: If True, will create a new service if not found
|
||||
"""
|
||||
kind, uuid_userservice_pool = id_service[0], id_service[1:]
|
||||
|
||||
logger.debug('Kind of service: %s, idService: %s', kind, uuid_user_service)
|
||||
logger.debug('Kind of service: %s, idService: %s', kind, uuid_userservice_pool)
|
||||
userservice: typing.Optional[UserService] = None
|
||||
|
||||
if kind in 'A': # This is an assigned service
|
||||
logger.debug('Getting A service %s', uuid_user_service)
|
||||
userservice = UserService.objects.get(uuid=uuid_user_service, user=user)
|
||||
userservice.deployed_service.validate_user(user)
|
||||
else:
|
||||
logger.debug('Getting assugned user service %s', uuid_userservice_pool)
|
||||
try:
|
||||
service_pool: ServicePool = ServicePool.objects.get(uuid=uuid_user_service)
|
||||
userservice = UserService.objects.get(uuid=uuid_userservice_pool, user=user)
|
||||
userservice.service_pool.validate_user(user)
|
||||
except UserService.DoesNotExist:
|
||||
logger.debug('Service does not exist')
|
||||
return None
|
||||
else:
|
||||
logger.debug('Getting service pool %s', uuid_userservice_pool)
|
||||
try:
|
||||
service_pool: ServicePool = ServicePool.objects.get(uuid=uuid_userservice_pool)
|
||||
# We first do a sanity check for this, if the user has access to this service
|
||||
# If it fails, will raise an exception
|
||||
service_pool.validate_user(user)
|
||||
@ -906,59 +916,64 @@ class UserServiceManager(metaclass=singleton.Singleton):
|
||||
src_ip: str,
|
||||
user_service_id: str,
|
||||
transport_id: typing.Optional[str],
|
||||
validate_with_test: bool = True,
|
||||
test_userservice_status: bool = True,
|
||||
client_hostname: typing.Optional[str] = None,
|
||||
) -> tuple[
|
||||
typing.Optional[str],
|
||||
UserService,
|
||||
typing.Optional['services.UserService'],
|
||||
Transport,
|
||||
typing.Optional[transports.Transport],
|
||||
]:
|
||||
) -> types.services.UserServiceInfo:
|
||||
"""
|
||||
Get service info from user service
|
||||
Get service info from user service
|
||||
|
||||
Args:
|
||||
user: User owner of the service
|
||||
os: Detected OS (as provided by request)
|
||||
src_ip: Source IP of the request
|
||||
user_service_id: User service id (A<uuid> for assigned, M<uuid> for meta, ?<uuid> for service pool)
|
||||
transport_id: Transport id (optional). If not provided, will try to find a suitable one
|
||||
validate_with_test: If True, will check if the service is ready
|
||||
client_hostname: Client hostname (optional). If not provided, will use src_ip
|
||||
|
||||
Returns:
|
||||
UserServiceInfo: User service info
|
||||
"""
|
||||
if user_service_id[0] == 'M': # Meta pool
|
||||
return self.get_meta_service_info(user, src_ip, os, user_service_id[1:], transport_id or 'meta')
|
||||
|
||||
user_service = self.locate_user_service(user, user_service_id, create=True)
|
||||
userservice = self.locate_user_service(user, user_service_id, create=True)
|
||||
|
||||
if not user_service:
|
||||
if not userservice:
|
||||
raise InvalidServiceException(
|
||||
_('Invalid service. The service is not available at this moment. Please, try later')
|
||||
)
|
||||
|
||||
# Early log of "access try" so we can imagine what is going on
|
||||
user_service.set_connection_source(
|
||||
types.connections.ConnectionSource(src_ip, client_hostname or src_ip)
|
||||
)
|
||||
userservice.set_connection_source(types.connections.ConnectionSource(src_ip, client_hostname or src_ip))
|
||||
|
||||
if user_service.is_in_maintenance():
|
||||
if userservice.is_in_maintenance():
|
||||
raise ServiceInMaintenanceMode()
|
||||
|
||||
if not user_service.deployed_service.is_access_allowed():
|
||||
if not userservice.deployed_service.is_access_allowed():
|
||||
raise ServiceAccessDeniedByCalendar()
|
||||
|
||||
if not transport_id: # Find a suitable transport
|
||||
t: Transport
|
||||
for t in user_service.deployed_service.transports.order_by('priority'):
|
||||
typeTrans = t.get_type()
|
||||
for transport in userservice.deployed_service.transports.order_by('priority'):
|
||||
typeTrans = transport.get_type()
|
||||
if (
|
||||
typeTrans
|
||||
and t.is_ip_allowed(src_ip)
|
||||
and transport.is_ip_allowed(src_ip)
|
||||
and typeTrans.supports_os(os.os)
|
||||
and t.is_os_allowed(os.os)
|
||||
and transport.is_os_allowed(os.os)
|
||||
):
|
||||
transport_id = t.uuid
|
||||
transport_id = transport.uuid
|
||||
break
|
||||
else:
|
||||
raise InvalidServiceException(_('No suitable transport found'))
|
||||
|
||||
try:
|
||||
transport: Transport = Transport.objects.get(uuid=transport_id)
|
||||
except Exception as e:
|
||||
raise InvalidServiceException() from e
|
||||
transport = Transport.objects.get(uuid=transport_id)
|
||||
except Transport.DoesNotExist:
|
||||
raise InvalidServiceException(_('No suitable transport found'))
|
||||
|
||||
# Ensures that the transport is allowed for this service
|
||||
if user_service.deployed_service.transports.filter(id=transport.id).count() == 0:
|
||||
if userservice.deployed_service.transports.filter(id=transport.id).count() == 0:
|
||||
raise InvalidServiceException()
|
||||
|
||||
# If transport is not available for the request IP...
|
||||
@ -969,84 +984,88 @@ class UserServiceManager(metaclass=singleton.Singleton):
|
||||
|
||||
userName = user.name if user else 'unknown'
|
||||
|
||||
if not validate_with_test:
|
||||
if not test_userservice_status:
|
||||
# traceLogger.info('GOT service "{}" for user "{}" with transport "{}" (NOT TESTED)'.format(userService.name, userName, trans.name))
|
||||
return None, user_service, None, transport, None
|
||||
return types.services.UserServiceInfo(
|
||||
ip=None,
|
||||
userservice=userservice,
|
||||
transport=transport,
|
||||
)
|
||||
# return None, userservice, None, transport, None
|
||||
|
||||
service_status: types.services.ReadyStatus = types.services.ReadyStatus.USERSERVICE_NOT_READY
|
||||
userservice_status: types.services.ReadyStatus = types.services.ReadyStatus.USERSERVICE_NOT_READY
|
||||
ip = 'unknown'
|
||||
# Test if the service is ready
|
||||
if user_service.is_ready():
|
||||
if userservice.is_ready():
|
||||
# Is ready, update possible state
|
||||
service_status = types.services.ReadyStatus.USERSERVICE_NO_IP
|
||||
userservice_status = types.services.ReadyStatus.USERSERVICE_NO_IP
|
||||
log.log(
|
||||
user_service,
|
||||
userservice,
|
||||
types.log.LogLevel.INFO,
|
||||
f"User {user.pretty_name} from {src_ip} has initiated access",
|
||||
types.log.LogSource.WEB,
|
||||
)
|
||||
# If ready, show transport for this service, if also ready ofc
|
||||
userServiceInstance = user_service.get_instance()
|
||||
ip = userServiceInstance.get_ip()
|
||||
user_service.log_ip(ip) # Update known ip
|
||||
userservice_instance = userservice.get_instance()
|
||||
ip = userservice_instance.get_ip()
|
||||
userservice.log_ip(ip) # Update known ip
|
||||
logger.debug('IP: %s', ip)
|
||||
|
||||
if self.check_user_service_uuid(user_service) is False: # The service is not the expected one
|
||||
service_status = types.services.ReadyStatus.USERSERVICE_INVALID_UUID
|
||||
if self.check_user_service_uuid(userservice) is False: # The service is not the expected one
|
||||
userservice_status = types.services.ReadyStatus.USERSERVICE_INVALID_UUID
|
||||
log.log(
|
||||
user_service,
|
||||
userservice,
|
||||
types.log.LogLevel.WARNING,
|
||||
f'User service is not accessible due to invalid UUID (user: {user.pretty_name}, ip: {ip})',
|
||||
types.log.LogSource.TRANSPORT,
|
||||
)
|
||||
logger.debug('UUID check failed for user service %s', user_service)
|
||||
logger.debug('UUID check failed for user service %s', userservice)
|
||||
else:
|
||||
events.add_event(
|
||||
user_service.deployed_service,
|
||||
userservice.deployed_service,
|
||||
events.types.stats.EventType.ACCESS,
|
||||
username=userName,
|
||||
srcip=src_ip,
|
||||
dstip=ip,
|
||||
uniqueid=user_service.unique_id,
|
||||
uniqueid=userservice.unique_id,
|
||||
)
|
||||
if ip:
|
||||
service_status = types.services.ReadyStatus.TRANSPORT_NOT_READY
|
||||
transportInstance = transport.get_instance()
|
||||
if transportInstance.is_ip_allowed(user_service, ip):
|
||||
userservice_status = types.services.ReadyStatus.TRANSPORT_NOT_READY
|
||||
transport_instance = transport.get_instance()
|
||||
if transport_instance.is_ip_allowed(userservice, ip):
|
||||
log.log(
|
||||
user_service, types.log.LogLevel.INFO, "User service ready", types.log.LogSource.WEB
|
||||
userservice, types.log.LogLevel.INFO, "User service ready", types.log.LogSource.WEB
|
||||
)
|
||||
self.notify_preconnect(
|
||||
user_service,
|
||||
transportInstance.get_connection_info(user_service, user, ''),
|
||||
userservice,
|
||||
transport_instance.get_connection_info(userservice, user, ''),
|
||||
)
|
||||
trace_logger.info(
|
||||
'READY on service "%s" for user "%s" with transport "%s" (ip:%s)',
|
||||
user_service.name,
|
||||
userservice.name,
|
||||
userName,
|
||||
transport.name,
|
||||
ip,
|
||||
)
|
||||
return (
|
||||
ip,
|
||||
user_service,
|
||||
userServiceInstance,
|
||||
transport,
|
||||
transportInstance,
|
||||
return types.services.UserServiceInfo(
|
||||
ip=ip,
|
||||
userservice=userservice,
|
||||
transport=transport,
|
||||
)
|
||||
# return ( ip, userservice, userservice_instance, transport, transport_instance)
|
||||
|
||||
message = transportInstance.get_available_error_msg(user_service, ip)
|
||||
log.log(user_service, types.log.LogLevel.WARNING, message, types.log.LogSource.TRANSPORT)
|
||||
message = transport_instance.get_available_error_msg(userservice, ip)
|
||||
log.log(userservice, types.log.LogLevel.WARNING, message, types.log.LogSource.TRANSPORT)
|
||||
logger.debug(
|
||||
'Transport is not ready for user service %s: %s',
|
||||
user_service,
|
||||
userservice,
|
||||
message,
|
||||
)
|
||||
else:
|
||||
logger.debug('Ip not available from user service %s', user_service)
|
||||
logger.debug('Ip not available from user service %s', userservice)
|
||||
else:
|
||||
log.log(
|
||||
user_service,
|
||||
userservice,
|
||||
types.log.LogLevel.WARNING,
|
||||
f'User {user.pretty_name} from {src_ip} tried to access, but service was not ready',
|
||||
types.log.LogSource.WEB,
|
||||
@ -1054,13 +1073,13 @@ class UserServiceManager(metaclass=singleton.Singleton):
|
||||
|
||||
trace_logger.error(
|
||||
'ERROR %s on service "%s" for user "%s" with transport "%s" (ip:%s)',
|
||||
service_status,
|
||||
user_service.name,
|
||||
userservice_status,
|
||||
userservice.name,
|
||||
userName,
|
||||
transport.name,
|
||||
ip,
|
||||
)
|
||||
raise ServiceNotReadyError(code=service_status, user_service=user_service, transport=transport)
|
||||
raise ServiceNotReadyError(code=userservice_status, user_service=userservice, transport=transport)
|
||||
|
||||
def is_meta_service(self, meta_id: str) -> bool:
|
||||
return meta_id[0] == 'M'
|
||||
@ -1092,13 +1111,7 @@ class UserServiceManager(metaclass=singleton.Singleton):
|
||||
id_metapool: str,
|
||||
id_transport: str,
|
||||
clientHostName: typing.Optional[str] = None,
|
||||
) -> tuple[
|
||||
typing.Optional[str],
|
||||
UserService,
|
||||
typing.Optional['services.UserService'],
|
||||
Transport,
|
||||
typing.Optional[transports.Transport],
|
||||
]:
|
||||
) -> types.services.UserServiceInfo:
|
||||
logger.debug('This is meta')
|
||||
# We need to locate the service pool related to this meta, and also the transport
|
||||
# First, locate if there is a service in any pool associated with this metapool
|
||||
@ -1199,7 +1212,7 @@ class UserServiceManager(metaclass=singleton.Singleton):
|
||||
srcIp,
|
||||
'F' + usable[0].uuid,
|
||||
usable[1].uuid,
|
||||
validate_with_test=False,
|
||||
test_userservice_status=False,
|
||||
client_hostname=clientHostName,
|
||||
)
|
||||
# Not usable, will notify that it is not accessible
|
||||
@ -1224,7 +1237,7 @@ class UserServiceManager(metaclass=singleton.Singleton):
|
||||
srcIp,
|
||||
'F' + usable[0].uuid,
|
||||
usable[1].uuid,
|
||||
validate_with_test=False,
|
||||
test_userservice_status=False,
|
||||
client_hostname=clientHostName,
|
||||
)
|
||||
except Exception as e:
|
||||
|
@ -34,7 +34,7 @@ import dataclasses
|
||||
import enum
|
||||
|
||||
if typing.TYPE_CHECKING:
|
||||
from uds.models.service_pool import ServicePool
|
||||
from uds import models
|
||||
|
||||
|
||||
class ServiceType(enum.StrEnum):
|
||||
@ -210,7 +210,7 @@ class Operation(enum.IntEnum):
|
||||
|
||||
@dataclasses.dataclass
|
||||
class ServicePoolStats:
|
||||
servicepool: typing.Optional['ServicePool']
|
||||
servicepool: typing.Optional['models.ServicePool']
|
||||
l1_cache_count: int
|
||||
l2_cache_count: int
|
||||
assigned_count: int
|
||||
@ -274,3 +274,12 @@ class ServicePoolStats:
|
||||
return 'ServicePoolStats[Null]'
|
||||
|
||||
return f'ServicePoolStats[{self.servicepool}: L1 {self.l1_cache_count}, L2 {self.l2_cache_count}, Assigned {self.assigned_count}]'
|
||||
|
||||
|
||||
@dataclasses.dataclass
|
||||
class UserServiceInfo:
|
||||
# Ip is unknown if not requested test
|
||||
ip: typing.Optional[str]
|
||||
userservice: 'models.UserService'
|
||||
transport: 'models.Transport'
|
||||
|
||||
|
@ -428,26 +428,24 @@ def enable_service(
|
||||
# If meta service, process and rebuild idService & idTransport
|
||||
|
||||
try:
|
||||
res = UserServiceManager.manager().get_user_service_info(
|
||||
request.user, request.os, request.ip, service_id, transport_id, validate_with_test=False
|
||||
info = UserServiceManager.manager().get_user_service_info(
|
||||
request.user, request.os, request.ip, service_id, transport_id, test_userservice_status=False
|
||||
)
|
||||
scrambler = CryptoManager().random_string(32)
|
||||
password = CryptoManager().symmetric_encrypt(web_password(request), scrambler)
|
||||
|
||||
userservice, trans = res[1], res[3]
|
||||
info.userservice.properties['accessed_by_client'] = False # Reset accesed property to
|
||||
|
||||
userservice.properties['accessed_by_client'] = False # Reset accesed property to
|
||||
|
||||
transport_type = trans.get_type()
|
||||
transport_type = info.transport.get_type()
|
||||
|
||||
error = '' # No error
|
||||
|
||||
if transport_type.own_link:
|
||||
url = reverse('webapi.transport_own_link', args=('A' + userservice.uuid, trans.uuid))
|
||||
url = reverse('webapi.transport_own_link', args=('A' + info.userservice.uuid, info.transport.uuid))
|
||||
else:
|
||||
data = {
|
||||
'service': 'A' + userservice.uuid,
|
||||
'transport': trans.uuid,
|
||||
'service': 'A' + info.userservice.uuid,
|
||||
'transport': info.transport.uuid,
|
||||
'user': request.user.uuid,
|
||||
'password': password,
|
||||
}
|
||||
|
@ -206,7 +206,7 @@ def ticket_auth(
|
||||
groups = data['groups']
|
||||
auth = data['auth']
|
||||
realname = data['realname']
|
||||
poolUuid = data['servicePool']
|
||||
pool_uuid = data['servicePool']
|
||||
password = CryptoManager().decrypt(data['password'])
|
||||
except Exception:
|
||||
logger.error('Ticket stored is not valid')
|
||||
@ -249,21 +249,21 @@ def ticket_auth(
|
||||
|
||||
# Transport must always be automatic for ticket authentication
|
||||
|
||||
logger.debug("Service & transport: %s", poolUuid)
|
||||
logger.debug("Service & transport: %s", pool_uuid)
|
||||
|
||||
# Check if servicePool is part of the ticket
|
||||
if poolUuid:
|
||||
if pool_uuid:
|
||||
# Request service, with transport = None so it is automatic
|
||||
res = UserServiceManager.manager().get_user_service_info(
|
||||
request.user, request.os, request.ip, poolUuid, None, False
|
||||
info = UserServiceManager.manager().get_user_service_info(
|
||||
request.user, request.os, request.ip, pool_uuid, None, False
|
||||
)
|
||||
_, userservice, _, transport, _ = res
|
||||
#_, userservice, _, transport, _ = res
|
||||
|
||||
transportInstance = transport.get_instance()
|
||||
if transportInstance.own_link is True:
|
||||
link = reverse('webapi.transport_own_link', args=('A' + userservice.uuid, transport.uuid))
|
||||
transport_instance = info.transport.get_instance()
|
||||
if transport_instance.own_link is True:
|
||||
link = reverse('webapi.transport_own_link', args=('A' + info.userservice.uuid, info.transport.uuid))
|
||||
else:
|
||||
link = html.uds_access_link(request, 'A' + userservice.uuid, transport.uuid)
|
||||
link = html.uds_access_link(request, 'A' + info.userservice.uuid, info.transport.uuid)
|
||||
|
||||
request.session['launch'] = link
|
||||
response = HttpResponseRedirect(reverse('page.ticket.launcher'))
|
||||
|
@ -67,17 +67,17 @@ def transport_own_link(
|
||||
response: collections.abc.MutableMapping[str, typing.Any] = {}
|
||||
|
||||
try:
|
||||
res = UserServiceManager.manager().get_user_service_info(
|
||||
info = UserServiceManager.manager().get_user_service_info(
|
||||
request.user, request.os, request.ip, service_id, transport_id
|
||||
)
|
||||
ip, userService, _iads, trans, itrans = res
|
||||
# ip, userService, _iads, trans, itrans = res
|
||||
# This returns a response object in fact
|
||||
if itrans and ip:
|
||||
if info.ip:
|
||||
response = _response(
|
||||
url=itrans.get_link(
|
||||
userService,
|
||||
trans,
|
||||
ip,
|
||||
url=info.transport.get_instance().get_link(
|
||||
info.userservice,
|
||||
info.transport,
|
||||
info.ip,
|
||||
request.os,
|
||||
request.user,
|
||||
web_password(request),
|
||||
|
Loading…
x
Reference in New Issue
Block a user