1
0
mirror of https://github.com/dkmstr/openuds.git synced 2025-01-18 06:03:54 +03:00

Refactor OpenGnsys views and helpers to improve code readability and maintainability

This commit is contained in:
Adolfo Gómez García 2024-04-10 17:21:09 +02:00
parent e5e72de4b4
commit 7c16960d3a
No known key found for this signature in database
GPG Key ID: DD1ABF20724CDA23
2 changed files with 22 additions and 22 deletions

View File

@ -56,11 +56,11 @@ def opengnsys(
) -> HttpResponse:
logger.debug('Received opengnsys message %s, token %s, uuid %s', msg, token, uuid)
def getUserService() -> typing.Optional[UserService]:
def _get_userservice() -> typing.Optional[UserService]:
try:
userService = UserService.objects.get(uuid=process_uuid(uuid), state=types.states.State.USABLE)
if userService.properties.get('token') == token:
return userService
userservice = UserService.objects.get(uuid=process_uuid(uuid), state=types.states.State.USABLE)
if userservice.properties.get('token') == token:
return userservice
logger.warning(
'OpenGnsys: invalid token %s for userService %s. (Ignored)',
token,
@ -74,37 +74,37 @@ def opengnsys(
return None
def release() -> None:
userService = getUserService()
if userService:
logger.info('Released from OpenGnsys %s', userService.friendly_name)
userService.properties['from_release'] = True
userService.release()
userservice = _get_userservice()
if userservice:
logger.info('Released from OpenGnsys %s', userservice.friendly_name)
userservice.properties['from_release'] = True
userservice.release()
def login() -> None:
userService = getUserService()
if userService:
userservice = _get_userservice()
if userservice:
# Ignore login to cached machines...
if userService.cache_level != 0:
if userservice.cache_level != 0:
logger.info(
'Ignored OpenGnsys login to %s to cached machine',
userService.friendly_name,
userservice.friendly_name,
)
return
logger.debug('Processing login from OpenGnsys %s', userService.friendly_name)
actor_v3.Login.process_login(userService, 'OpenGnsys')
logger.debug('Processing login from OpenGnsys %s', userservice.friendly_name)
actor_v3.Login.process_login(userservice, 'OpenGnsys')
def logout() -> None:
userService = getUserService()
if userService:
userservice = _get_userservice()
if userservice:
# Ignore logout to cached machines...
if userService.cache_level != 0:
if userservice.cache_level != 0:
logger.info(
'Ignored OpenGnsys logout to %s to cached machine',
userService.friendly_name,
userservice.friendly_name,
)
return
logger.debug('Processing logout from OpenGnsys %s', userService.friendly_name)
actor_v3.Logout.process_logout(userService, 'OpenGnsys', '') # Close all sessions
logger.debug('Processing logout from OpenGnsys %s', userservice.friendly_name)
actor_v3.Logout.process_logout(userservice, 'OpenGnsys', '') # Close all sessions
fnc: typing.Optional[collections.abc.Callable[[], None]] = {
'login': login,

View File

@ -47,7 +47,7 @@ logger = logging.getLogger(__name__)
def get_resources(parameters: typing.Any) -> types.ui.CallbackResultType:
logger.debug('Parameters received by getResources Helper: %s', parameters)
provider = typing.cast(
'OGProvider', models.Provider.objects.get(id=parameters['prov_uuid']).get_instance()
'OGProvider', models.Provider.objects.get(uuid=parameters['prov_uuid']).get_instance()
)
api = provider.api