forked from shaba/openuds
Updating validators
This commit is contained in:
parent
85aab86b02
commit
6a14917ec5
@ -116,6 +116,22 @@ def validatePort(portStr: str) -> int:
|
||||
return validateNumeric(portStr, minValue=0, maxValue=65535, fieldName='Port')
|
||||
|
||||
|
||||
def validateHostPortPair(hostPortPair: str) -> typing.Tuple[str, int]:
|
||||
"""
|
||||
Validates that a host:port pair is valid
|
||||
:param hostPortPair: host:port pair to validate
|
||||
:param returnAsInteger: if True, returns value as integer, if not, as string
|
||||
:return: Raises Module.Validation exception if is invalid, else return the value "fixed"
|
||||
"""
|
||||
try:
|
||||
host, port = hostPortPair.split(':')
|
||||
return validateHostname(host, 255, False), validatePort(port)
|
||||
except Exception:
|
||||
raise Module.ValidationException(
|
||||
_('{} is not a valid host:port pair').format(hostPortPair)
|
||||
)
|
||||
|
||||
|
||||
def validateTimeout(timeOutStr: str) -> int:
|
||||
"""
|
||||
Validates that a timeout value is valid
|
||||
|
@ -37,6 +37,7 @@ from django.utils.translation import ugettext_noop as _
|
||||
from uds.core.ui import gui
|
||||
from uds.core import transports
|
||||
from uds.core.util import os_detector as OsDetector
|
||||
from uds.core.util import validators
|
||||
from uds.models import TicketStore
|
||||
|
||||
from .spice_base import BaseSpiceTransport
|
||||
@ -102,10 +103,7 @@ class TSPICETransport(BaseSpiceTransport):
|
||||
|
||||
def initialize(self, values: 'Module.ValuesType'):
|
||||
if values:
|
||||
if values['tunnelServer'].count(':') != 1:
|
||||
raise transports.Transport.ValidationException(
|
||||
_('Must use HOST:PORT in Tunnel Server Field')
|
||||
)
|
||||
validators.validateHostPortPair(values.get('tunnelServer', ''))
|
||||
|
||||
def getUDSTransportScript( # pylint: disable=too-many-locals
|
||||
self,
|
||||
|
@ -38,7 +38,7 @@ from django.utils.translation import ugettext_noop as _
|
||||
from uds.core.ui import gui
|
||||
from uds.core.managers.user_preferences import CommonPrefs
|
||||
from uds.core.util import os_detector as OsDetector
|
||||
from uds.core.util import tools
|
||||
from uds.core.util import tools, validators
|
||||
from uds.core import transports
|
||||
from uds.models import TicketStore
|
||||
from .x2go_base import BaseX2GOTransport
|
||||
@ -111,10 +111,7 @@ class TX2GOTransport(BaseX2GOTransport):
|
||||
|
||||
def initialize(self, values: 'Module.ValuesType'):
|
||||
if values:
|
||||
if values['tunnelServer'].count(':') != 1:
|
||||
raise BaseX2GOTransport.ValidationException(
|
||||
_('Must use HOST:PORT in Tunnel Server Field')
|
||||
)
|
||||
validators.validateHostPortPair(values.get('tunnelServer', ''))
|
||||
|
||||
def getUDSTransportScript( # pylint: disable=too-many-locals
|
||||
self,
|
||||
|
Loading…
x
Reference in New Issue
Block a user