Add username to cache key in datasource renderer if OAuth2 is used

(fixes #5849)
This commit is contained in:
Benjamin Dauvergne 2014-11-03 16:37:00 +01:00
parent 7040ba8900
commit fd74d2f7c1
2 changed files with 8 additions and 0 deletions

3
README
View File

@ -162,6 +162,9 @@ A source definition is a dictionnary containing the following keys:
as keyword arguments to the `reader()` or `DictReader()`
constructors, depending on whether the `fieldnames` arguments is
present,
- `user_context`, whether the user must be part of the cache key. For retro
compatibility If authentication mechanism is OAuth2, it defaults to True
otherwise to False.
Exemple with the JSON parser
----------------------------

View File

@ -141,9 +141,14 @@ class Data(object):
self.signature_key = source.get('signature_key')
self.parser_type = source.get('parser_type', 'raw')
self.content_type = source.get('content_type', self.MAPPING[self.parser_type])
self.user_context = source.get('user_context',
config.get('user_context', self.auth_mech == 'oauth2'))
pre_hash = 'datasource-{self.slug}-{self.url}-{self.limit}-' \
'{self.refresh}-{self.auth_mech}-{self.signature_key}' \
.format(self=self)
# If authentication is used
if self.user_context:
pre_hash += '-%s' % unicode(self.request.user).encode('utf-8')
self.key = hashlib.md5(pre_hash).hexdigest()
self.now = time.time()
self.__content = self.__CACHE_SENTINEL