Commit 4772c7e1 authored by Gabriel Monnerat's avatar Gabriel Monnerat

erp5_bearer_token: support pass a different cache factory name

parent cbf5deb4
import hmac import hmac
from Products.ERP5Type.Cache import DEFAULT_CACHE_SCOPE from Products.ERP5Type.Cache import DEFAULT_CACHE_SCOPE
CACHE_FACTORY_NAME = 'bearer_token_cache_factory'
def getHMAC(self, key, body): def getHMAC(self, key, body):
digest = hmac.new(key, body) digest = hmac.new(key, body)
return digest.hexdigest() return digest.hexdigest()
def _getCacheFactory(self): def _getCacheFactory(self, cache_factory_name):
portal = self.getPortalObject() portal = self.getPortalObject()
cache_tool = portal.portal_caches cache_tool = portal.portal_caches
cache_factory_name = 'bearer_token_cache_factory'
cache_factory = cache_tool.getRamCacheRoot().get(cache_factory_name) cache_factory = cache_tool.getRamCacheRoot().get(cache_factory_name)
#XXX This conditional statement should be remove as soon as #XXX This conditional statement should be remove as soon as
#Broadcasting will be enable among all zeo clients. #Broadcasting will be enable among all zeo clients.
...@@ -19,15 +20,15 @@ def _getCacheFactory(self): ...@@ -19,15 +20,15 @@ def _getCacheFactory(self):
cache_tool.updateCache() cache_tool.updateCache()
return cache_tool.getRamCacheRoot().get(cache_factory_name) return cache_tool.getRamCacheRoot().get(cache_factory_name)
def setBearerToken(self, key, body): def setBearerToken(self, key, body, cache_factory_name=CACHE_FACTORY_NAME):
cache_factory = _getCacheFactory(self) cache_factory = _getCacheFactory(self, cache_factory_name)
cache_duration = cache_factory.cache_duration cache_duration = cache_factory.cache_duration
for cache_plugin in cache_factory.getCachePluginList(): for cache_plugin in cache_factory.getCachePluginList():
cache_plugin.set(key, DEFAULT_CACHE_SCOPE, cache_plugin.set(key, DEFAULT_CACHE_SCOPE,
body, cache_duration=cache_duration) body, cache_duration=cache_duration)
def getBearerToken(self, key): def getBearerToken(self, key, cache_factory_name=CACHE_FACTORY_NAME):
cache_factory = _getCacheFactory(self) cache_factory = _getCacheFactory(self, cache_factory_name)
for cache_plugin in cache_factory.getCachePluginList(): for cache_plugin in cache_factory.getCachePluginList():
cache_entry = cache_plugin.get(key, DEFAULT_CACHE_SCOPE) cache_entry = cache_plugin.get(key, DEFAULT_CACHE_SCOPE)
if cache_entry is not None: if cache_entry is not None:
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment