From d8eb440b34885585243e64e42c9c3707d34e7288 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Adolfo=20G=C3=B3mez=20Garc=C3=ADa?= Date: Tue, 26 Jun 2018 17:20:05 +0200 Subject: [PATCH] Advanced a lot on azure ad integration --- server/src/uds/core/Environment.py | 4 +++- server/src/uds/core/util/decorators.py | 10 ++++++---- 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/server/src/uds/core/Environment.py b/server/src/uds/core/Environment.py index 7e114e8d2..eb3feee08 100644 --- a/server/src/uds/core/Environment.py +++ b/server/src/uds/core/Environment.py @@ -72,6 +72,7 @@ class Environment(object): ''' Method to acces the cache of the environment. @return: a referente to an Storage Instance + :rtype uds.core.util.Storage.Storage ''' return self._storage @@ -179,7 +180,6 @@ class Environmentable(object): ''' self._env = environment - @property def cache(self): ''' @@ -197,6 +197,8 @@ class Environmentable(object): Returns: Storage for the object + + :rtype uds.core.util.Storage.Storage ''' return self._env.storage diff --git a/server/src/uds/core/util/decorators.py b/server/src/uds/core/util/decorators.py index 39b25adb6..a25131d52 100644 --- a/server/src/uds/core/util/decorators.py +++ b/server/src/uds/core/util/decorators.py @@ -39,7 +39,7 @@ from functools import wraps import logging -__updated__ = '2018-06-08' +__updated__ = '2018-06-25' logger = logging.getLogger(__name__) @@ -97,7 +97,7 @@ def deprecated(func): # # Decorator for caching # Decorator that tries to get from cache before executing -def allowCache(cachePrefix, cacheTimeout, cachingArgs=None): +def allowCache(cachePrefix, cacheTimeout, cachingArgs=None, cachingKeyFnc=None): """Decorator that give us a "quick& clean" caching feature on service providers. Note: This decorator is intended ONLY for service providers @@ -107,6 +107,8 @@ def allowCache(cachePrefix, cacheTimeout, cachingArgs=None): :param cachingArgs: The caching args. Can be a single integer or a list. First arg (self) is 0, so normally cachingArgs are 1, or [1,2,..] """ + if not cachingKeyFnc: + cachingKeyFnc = lambda(x):'' def allowCacheDecorator(fnc): @@ -117,9 +119,9 @@ def allowCache(cachePrefix, cacheTimeout, cachingArgs=None): argList = [args[i] if i < len(args) else '' for i in cachingArgs] else: argList = args[cachingArgs] if cachingArgs < len(args) else '' - cacheKey = '{}-{}.{}'.format(cachePrefix, args[0].subscriptionId.value, argList) + cacheKey = '{}-{}.{}'.format(cachePrefix, cachingKeyFnc(args[0]), argList) else: - cacheKey = '{}-{}.gen'.format(cachePrefix, args[0].subscriptionId.value) + cacheKey = '{}-{}.gen'.format(cachePrefix, cachingKeyFnc(args[0])) data = None if kwargs.get('force', False) is False and args[0].cache is not None: