1
0
mirror of https://github.com/dkmstr/openuds.git synced 2024-12-24 21:34:41 +03:00

Merge remote-tracking branch 'origin/v3.5'

This commit is contained in:
Adolfo Gómez García 2022-01-30 19:34:19 +01:00
commit 082ef6830d
10 changed files with 18 additions and 36 deletions

View File

@ -784,7 +784,8 @@ class UserServiceManager(metaclass=singleton.Singleton):
for t in userService.deployed_service.transports.order_by('priority'):
typeTrans = t.getType()
if (
t.validForIp(srcIp)
typeTrans
and t.validForIp(srcIp)
and typeTrans.supportsOs(os['OS'])
and t.validForOs(os['OS'])
):
@ -1007,7 +1008,8 @@ class UserServiceManager(metaclass=singleton.Singleton):
for t in q:
typeTrans = t.getType()
if (
t.getType()
typeTrans
and t.getType()
and t.validForIp(srcIp)
and typeTrans.supportsOs(os['OS'])
and t.validForOs(os['OS'])

View File

@ -102,6 +102,7 @@ class ManagedObjectModel(UUIDModel):
return self._cachedInstance
klass = self.getType()
env = self.getEnvironment()
obj = klass(env, values)
self.deserialize(obj, values)

View File

@ -82,11 +82,7 @@ class OSManager(ManagedObjectModel, TaggingMixin): # type: ignore
# We only need to get info from this, not access specific data (class specific info)
from uds.core import osmanagers
type_ = osmanagers.factory().lookup(self.data_type)
if type_:
return type_
# If invalid type, ensure at least we have "basic" model (that will fail if used, but not if referenced)
return osmanagers.OSManager
return osmanagers.factory().lookup(self.data_type) or osmanagers.OSManager
def remove(self) -> bool:
"""

View File

@ -78,12 +78,7 @@ class Provider(ManagedObjectModel, TaggingMixin): # type: ignore
"""
from uds.core import services # pylint: disable=redefined-outer-name
type_ = services.factory().lookup(self.data_type)
if type_:
return type_
return (
services.ServiceProvider
) # Basic Service implementation. Will fail if we try to use it, but will be ok to reference it
return services.factory().lookup(self.data_type) or services.ServiceProvider
def getInstance(
self, values: typing.Optional[typing.Dict[str, str]] = None

View File

@ -173,15 +173,7 @@ class Service(ManagedObjectModel, TaggingMixin): # type: ignore
:note: We only need to get info from this, not access specific data (class specific info)
"""
prov: typing.Type['services.ServiceProvider'] = self.provider.getType()
type_ = prov.getServiceByType(self.data_type)
if type_:
return type_
raise Exception(
'Service type of {} is not recogniced by provider {}'.format(
self.data_type, prov
)
)
return prov.getServiceByType(self.data_type) or services.Service
def isInMaintenance(self) -> bool:
# orphaned services?

View File

@ -88,7 +88,7 @@ class Transport(ManagedObjectModel, TaggingMixin):
) -> 'transports.Transport':
return typing.cast('transports.Transport', super().getInstance(values=values))
def getType(self) -> 'typing.Type[transports.Transport]':
def getType(self) -> typing.Type['transports.Transport']:
"""
Get the type of the object this record represents.
@ -99,10 +99,7 @@ class Transport(ManagedObjectModel, TaggingMixin):
:note: We only need to get info from this, not access specific data (class specific info)
"""
v = transports.factory().lookup(self.data_type)
if not v:
raise Exception('transport not found')
return v
return transports.factory().lookup(self.data_type) or transports.Transport
def validForIp(self, ipStr: str) -> bool:
"""

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View File

@ -308,12 +308,10 @@ def getServicesData(
for t in sorted(
sPool.transports.all(), key=lambda x: x.priority
): # In memory sort, allows reuse prefetched and not too big array
try:
typeTrans = t.getType()
except Exception:
continue
typeTrans = t.getType()
if (
t.validForIp(request.ip)
typeTrans
and t.validForIp(request.ip)
and typeTrans.supportsOs(osName)
and t.validForOs(osName)
):
@ -411,8 +409,8 @@ def getServicesData(
autorun = False
if (
hasattr(request, 'session') and
len(services) == 1
hasattr(request, 'session')
and len(services) == 1
and GlobalConfig.AUTORUN_SERVICE.getBool(False)
and services[0]['transports']
):

View File

@ -155,6 +155,7 @@ def userServiceStatus(
'running' if not ready
'ready' if is ready but not accesed by client
'accessed' if ready and accesed by UDS client
'error' if error is found (for example, intancing user service)
Note:
'''
ip: typing.Union[str, None, bool]