From 7a3692cc43183fd21dfa42b5831e4e60f02f40be Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Adolfo=20G=C3=B3mez=20Garc=C3=ADa?= Date: Wed, 12 Nov 2014 07:28:50 +0100 Subject: [PATCH] Fixed to use lowercase for uuids (as rfc 4122 says that they will be) --- server/src/uds/REST/methods/tickets.py | 6 +- server/src/uds/REST/model.py | 10 ++-- server/src/uds/core/managers/CryptoManager.py | 5 +- server/src/uds/models/UUIDModel.py | 6 +- server/src/uds/models/__init__.py | 56 +++++++++---------- 5 files changed, 42 insertions(+), 41 deletions(-) diff --git a/server/src/uds/REST/methods/tickets.py b/server/src/uds/REST/methods/tickets.py index fde709ccd..1f1858fae 100644 --- a/server/src/uds/REST/methods/tickets.py +++ b/server/src/uds/REST/methods/tickets.py @@ -105,7 +105,7 @@ class Tickets(Handler): # Will raise an exception if no auth found if authId is not None: - auth = Authenticator.objects.get(uuid=authId.upper()) + auth = Authenticator.objects.get(uuid=authId.lower()) elif authName is not None: auth = Authenticator.objects.get(name=authName) else: @@ -135,11 +135,11 @@ class Tickets(Handler): transport = None if servicePool is not None: - servicePool = DeployedService.objects.get(uuid=servicePool.upper()) + servicePool = DeployedService.objects.get(uuid=servicePool.lower()) transport = self._params.get('transport', None) if transport is not None: - transport = Transport.objects.get(uuid=transport.upper()) + transport = Transport.objects.get(uuid=transport.lower()) try: servicePool.validateTransport(transport) except Exception: diff --git a/server/src/uds/REST/model.py b/server/src/uds/REST/model.py index a97c22e97..c7f36224e 100644 --- a/server/src/uds/REST/model.py +++ b/server/src/uds/REST/model.py @@ -614,7 +614,7 @@ class ModelHandler(BaseModelHandler): if self._args[1] == cm[0]: try: operation = getattr(self, self._args[1]) - item = self.model.objects.get(uuid=self._args[0].upper()) + item = self.model.objects.get(uuid=self._args[0].lower()) except Exception: self.invalidMethodException() @@ -639,7 +639,7 @@ class ModelHandler(BaseModelHandler): # get item ID try: - val = self.model.objects.get(uuid=self._args[0].upper()) + val = self.model.objects.get(uuid=self._args[0].lower()) res = self.item_as_dict(val) self.fillIntanceFields(val, res) return res @@ -664,7 +664,7 @@ class ModelHandler(BaseModelHandler): if nArgs != 2: self.invalidRequestException() try: - item = self.model.objects.get(uuid=self._args[0].upper()) # DB maybe case sensitive??, anyway, uuids are stored in uppercase + item = self.model.objects.get(uuid=self._args[0].lower()) # DB maybe case sensitive??, anyway, uuids are stored in lowercase except Exception: self.invalidItemException() return self.getLogs(item) @@ -708,7 +708,7 @@ class ModelHandler(BaseModelHandler): deleteOnError = True else: # Must have 1 arg # We have to take care with this case, update will efectively update records on db - item = self.model.objects.get(uuid=self._args[0].upper()) + item = self.model.objects.get(uuid=self._args[0].lower()) for v in self.remove_fields: if v in args: del args[v] @@ -759,7 +759,7 @@ class ModelHandler(BaseModelHandler): if len(self._args) != 1: raise RequestError('Delete need one and only one argument') try: - item = self.model.objects.get(uuid=self._args[0].upper()) + item = self.model.objects.get(uuid=self._args[0].lower()) self.checkDelete(item) self.deleteItem(item) except self.model.DoesNotExist: diff --git a/server/src/uds/core/managers/CryptoManager.py b/server/src/uds/core/managers/CryptoManager.py index bd2a5f1ad..f1f686f85 100644 --- a/server/src/uds/core/managers/CryptoManager.py +++ b/server/src/uds/core/managers/CryptoManager.py @@ -128,7 +128,7 @@ class CryptoManager(object): def uuid(self, obj=None): ''' - Generates an uuid from obj. + Generates an uuid from obj. (lower case) If obj is None, returns an uuid based on current datetime + counter ''' if obj is None: @@ -139,4 +139,5 @@ class CryptoManager(object): obj = obj.decode('utf-8') else: obj = six. binary_type(obj) - return six.text_type(uuid.uuid5(self._namespace, six.binary_type(obj))) + + return six.text_type(uuid.uuid5(self._namespace, six.binary_type(obj))).lower() # I believe uuid returns a lowercase uuid always, but in case... :) diff --git a/server/src/uds/models/UUIDModel.py b/server/src/uds/models/UUIDModel.py index 0569c13b0..122e0d147 100644 --- a/server/src/uds/models/UUIDModel.py +++ b/server/src/uds/models/UUIDModel.py @@ -33,7 +33,7 @@ from __future__ import unicode_literals -__updated__ = '2014-11-02' +__updated__ = '2014-11-12' from django.db import models from django.utils.encoding import python_2_unicode_compatible @@ -61,8 +61,8 @@ class UUIDModel(models.Model): def save(self, *args, **kwargs): if self.uuid is None or self.uuid == '': self.uuid = generateUuid() - elif self.uuid != self.uuid.upper(): - self.uuid = self.uuid.upper() # If we modify uuid elsewhere, ensure that it's stored in upper case + elif self.uuid != self.uuid.lower(): + self.uuid = self.uuid.lower() # If we modify uuid elsewhere, ensure that it's stored in lower case return models.Model.save(self, *args, **kwargs) diff --git a/server/src/uds/models/__init__.py b/server/src/uds/models/__init__.py index 1ad29ec95..def49fe49 100644 --- a/server/src/uds/models/__init__.py +++ b/server/src/uds/models/__init__.py @@ -33,7 +33,7 @@ from __future__ import unicode_literals -__updated__ = '2014-11-04' +__updated__ = '2014-11-12' import logging @@ -41,54 +41,54 @@ logger = logging.getLogger(__name__) # Utility -from uds.models.Util import getSqlDatetime -from uds.models.Util import optimizeTable -from uds.models.Util import NEVER -from uds.models.Util import NEVER_UNIX +from .Util import getSqlDatetime +from .Util import optimizeTable +from .Util import NEVER +from .Util import NEVER_UNIX # Services -from uds.models.Provider import Provider -from uds.models.Service import Service +from .Provider import Provider +from .Service import Service # Os managers -from uds.models.OSManager import OSManager +from .OSManager import OSManager # Transports -from uds.models.Transport import Transport -from uds.models.Network import Network +from .Transport import Transport +from .Network import Network # Authenticators -from uds.models.Authenticator import Authenticator -from uds.models.User import User -from uds.models.UserPreference import UserPreference -from uds.models.Group import Group +from .Authenticator import Authenticator +from .User import User +from .UserPreference import UserPreference +from .Group import Group # Provisioned services -from uds.models.ServicesPool import DeployedService # Old name, will continue here for a while already -from uds.models.ServicesPool import ServicePool # New name -from uds.models.ServicesPoolPublication import DeployedServicePublication -from uds.models.UserService import UserService +from .ServicesPool import DeployedService # Old name, will continue here for a while already +from .ServicesPool import ServicePool # New name +from .ServicesPoolPublication import DeployedServicePublication +from .UserService import UserService # Especific log information for an user service -from uds.models.Log import Log +from .Log import Log # Stats -from uds.models.StatsCounters import StatsCounters -from uds.models.StatsEvents import StatsEvents +from .StatsCounters import StatsCounters +from .StatsEvents import StatsEvents # General utility models, such as a database cache (for caching remote content of slow connections to external services providers for example) # We could use django cache (and maybe we do it in a near future), but we need to clean up things when objecs owning them are deleted -from uds.models.Cache import Cache -from uds.models.Config import Config -from uds.models.Storage import Storage -from uds.models.UniqueId import UniqueId +from .Cache import Cache +from .Config import Config +from .Storage import Storage +from .UniqueId import UniqueId # Workers/Schedulers related -from uds.models.Scheduler import Scheduler -from uds.models.DelayedTask import DelayedTask +from .Scheduler import Scheduler +from .DelayedTask import DelayedTask # Image galery related -from uds.models.Image import Image \ No newline at end of file +from .Image import Image \ No newline at end of file