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

advancing on refactoring and cache improvements

This commit is contained in:
Adolfo Gómez García 2024-01-08 15:26:08 +01:00
parent bc61814ec4
commit cf4a7e0ef9
No known key found for this signature in database
GPG Key ID: DD1ABF20724CDA23
14 changed files with 22 additions and 22 deletions

View File

@ -392,7 +392,7 @@ class OAuth2Authenticator(auths.Authenticator):
groups.extend(self.commonGroups.value.split(','))
# store groups for this username at storage, so we can check it at a later stage
self.storage.putPickle(username, [realName, groups])
self.storage.put_pickle(username, [realName, groups])
# Validate common groups
gm.validate(groups)

View File

@ -156,7 +156,7 @@ class RadiusAuth(auths.Authenticator):
request.session[client.STATE_VAR_NAME] = state.decode()
# store the user mfa attribute if it is set
if mfaCode:
self.storage.putPickle(
self.storage.put_pickle(
self.mfaStorageKey(username),
mfaCode,
)

View File

@ -506,7 +506,7 @@ class RegexLdap(auths.Authenticator):
# store the user mfa attribute if it is set
if self._mfaAttr:
self.storage.putPickle(
self.storage.put_pickle(
self.mfaStorageKey(username),
usr[self._mfaAttr][0],
)

View File

@ -675,11 +675,11 @@ class SAMLAuthenticator(auths.Authenticator):
logger.debug('Real name: %s', realName)
# store groups for this username at storage, so we can check it at a later stage
self.storage.putPickle(username, [realName, groups])
self.storage.put_pickle(username, [realName, groups])
# store also the mfa identifier field value, in case we have provided it
if self.mfaAttr.value.strip():
self.storage.putPickle(
self.storage.put_pickle(
self.mfaStorageKey(username),
''.join(auth_utils.processRegexField(self.mfaAttr.value, attributes)),
) # in case multipel values is returned, join them

View File

@ -459,7 +459,7 @@ class SimpleLDAPAuthenticator(auths.Authenticator):
# store the user mfa attribute if it is set
if self._mfaAttr:
self.storage.putPickle(
self.storage.put_pickle(
self.mfaStorageKey(username),
user[self._mfaAttr][0],
)

View File

@ -229,7 +229,7 @@ class MFA(Module):
Internal method to put the data into storage
"""
storageKey = request.ip + userId
self.storage.putPickle(storageKey, (sql_datetime(), code))
self.storage.put_pickle(storageKey, (sql_datetime(), code))
def process(
self,

View File

@ -439,7 +439,7 @@ class Service(Module):
return
def store_id_info(self, id: str, data: typing.Any) -> None:
self.storage.putPickle('__nfo_' + id, data)
self.storage.put_pickle('__nfo_' + id, data)
def recover_id_info(self, id: str, delete: bool = False) -> typing.Any:
# recovers the information

View File

@ -256,7 +256,7 @@ class Storage:
def put(self, skey: typing.Union[str, bytes], data: typing.Any) -> None:
return self.saveData(skey, data)
def putPickle(
def put_pickle(
self,
skey: typing.Union[str, bytes],
data: typing.Any,

View File

@ -135,7 +135,7 @@ class TOTP_MFA(mfas.MFA):
return data
def _saveUserData(self, userId: str, data: tuple[str, bool]) -> None:
self.storage.putPickle(userId, data)
self.storage.put_pickle(userId, data)
def _removeUserData(self, userId: str) -> None:
self.storage.remove(userId)

View File

@ -154,7 +154,7 @@ class TelegramNotifier(messaging.Notifier):
chatIds = self.storage.getPickle('chatIds') or []
if chatId not in chatIds:
chatIds.append(chatId)
self.storage.putPickle('chatIds', chatIds)
self.storage.put_pickle('chatIds', chatIds)
logger.info('User %s subscribed to notifications', chatId)
def unsubscriteUser(self, chatId: int) -> None:
@ -163,7 +163,7 @@ class TelegramNotifier(messaging.Notifier):
chatIds = self.storage.getPickle('chatIds') or []
if chatId in chatIds:
chatIds.remove(chatId)
self.storage.putPickle('chatIds', chatIds)
self.storage.put_pickle('chatIds', chatIds)
logger.info('User %s unsubscribed from notifications', chatId)
def retrieveMessages(self) -> None:
@ -176,14 +176,14 @@ class TelegramNotifier(messaging.Notifier):
# If last check is not set, we will set it to now
if lastCheck is None:
lastCheck = now - datetime.timedelta(seconds=self.checkDelay.num() + 1)
self.storage.putPickle('lastCheck', lastCheck)
self.storage.put_pickle('lastCheck', lastCheck)
# If not enough time has passed, we will not check
if lastCheck + datetime.timedelta(seconds=self.checkDelay.num()) > now:
return
# Update last check
self.storage.putPickle('lastCheck', now)
self.storage.put_pickle('lastCheck', now)
lastOffset = self.storage.getPickle('lastOffset') or 0
t = telegram.Telegram(self.accessToken.value, last_offset=lastOffset)
@ -207,4 +207,4 @@ class TelegramNotifier(messaging.Notifier):
elif message in ('/leave', '/unsubscribe'):
self.unsubscriteUser(update.chat.id)
t.send_message(update.chat.id, _('You have been unsubscribed from notifications'))
self.storage.putPickle('lastOffset', t.lastOffset)
self.storage.put_pickle('lastOffset', t.lastOffset)

View File

@ -280,7 +280,7 @@ class IPMachinesService(IPServiceBase):
and self.cache.get('port{}'.format(theIP))
):
continue # The check failed not so long ago, skip it...
self.storage.putPickle(theIP, now)
self.storage.put_pickle(theIP, now)
# Is WOL enabled?
wolENABLED = bool(self.parent().wolURL(theIP, theMAC))
# Now, check if it is available on port, if required...
@ -335,7 +335,7 @@ class IPMachinesService(IPServiceBase):
now = sql_stamp_seconds()
locked = self.storage.getPickle(theIP)
if self.canBeUsed(locked, now):
self.storage.putPickle(theIP, now)
self.storage.put_pickle(theIP, now)
if theMAC:
theIP += ';' + theMAC
return userServiceInstance.assign(theIP)
@ -353,7 +353,7 @@ class IPMachinesService(IPServiceBase):
now = sql_stamp_seconds()
locked: typing.Union[None, str, int] = self.storage.getPickle(theIP)
if self.canBeUsed(locked, now):
self.storage.putPickle(theIP, str(now)) # Lock it
self.storage.put_pickle(theIP, str(now)) # Lock it
def process_logout(self, id: str, remote_login: bool) -> None:
'''

View File

@ -90,7 +90,7 @@ class IPSingleMachineService(IPServiceBase):
try:
counter = self.storage.getPickle('counter')
counter = counter + 1 if counter is not None else 1
self.storage.putPickle('counter', counter)
self.storage.put_pickle('counter', counter)
ip = '{}~{}'.format(self.ip.value, counter)
except Exception:
ip = None

View File

@ -449,7 +449,7 @@ if sys.platform == 'win32':
self.__setTask(self.service().shutdownMachine(int(self._vmid)))
shutdown = sql_stamp_seconds()
logger.debug('Stoped vm using guest tools')
self.storage.putPickle('shutdown', shutdown)
self.storage.put_pickle('shutdown', shutdown)
return State.RUNNING
def __updateVmMacAndHA(self) -> str:
@ -537,7 +537,7 @@ if sys.platform == 'win32':
f'Could not shutdown machine using soft power off in time ({GUEST_SHUTDOWN_WAIT} seconds). Powering off.',
)
# Not stopped by guest in time, but must be stopped normally
self.storage.putPickle('shutdown', 0)
self.storage.put_pickle('shutdown', 0)
return self.__stopMachine() # Launch "hard" stop
return State.RUNNING

View File

@ -50,7 +50,7 @@ class StorageTest(UDSTestCase):
storage.put(b'key', UNICODE_CHARS)
storage.put(UNICODE_CHARS_2, UNICODE_CHARS)
storage.putPickle('pickle', VALUE_1)
storage.put_pickle('pickle', VALUE_1)
self.assertEqual(storage.get(UNICODE_CHARS), u'chars') # Always returns unicod
self.assertEqual(storage.readData('saveData'), UNICODE_CHARS)