def _cache_store(self, token_id, data):
        """Store value into memcache.

        data may be the string 'invalid' or a tuple like (data, expires)

        """
        serialized_data = jsonutils.dumps(data)
        if self._memcache_security_strategy is None:
            cache_key = CACHE_KEY_TEMPLATE % token_id
            data_to_store = serialized_data
        else:
            keys = memcache_crypt.derive_keys(
                token_id,
                self._memcache_secret_key,
                self._memcache_security_strategy)
            cache_key = CACHE_KEY_TEMPLATE % memcache_crypt.get_cache_key(keys)
            data_to_store = memcache_crypt.protect_data(keys, serialized_data)

        # Historically the swift cache conection used the argument
        # timeout= for the cache timeout, but this has been unified
        # with the official python memcache client with time= since
        # grizzly, we still need to handle folsom for a while until
        # this could get removed.
        try:
            self._cache.set(cache_key,
                            data_to_store,
                            time=self.token_cache_time)
        except(TypeError):
            self._cache.set(cache_key,
                            data_to_store,
                            timeout=self.token_cache_time)
예제 #2
0
    def _cache_store(self, token, data):
        """Store value into memcache.

        data may be the string 'invalid' or a tuple like (data, expires)

        """
        serialized_data = json.dumps(data)
        if self._memcache_security_strategy is None:
            cache_key = CACHE_KEY_TEMPLATE % token
            data_to_store = serialized_data
        else:
            keys = memcache_crypt.derive_keys(token, self._memcache_secret_key,
                                              self._memcache_security_strategy)
            cache_key = CACHE_KEY_TEMPLATE % memcache_crypt.get_cache_key(keys)
            data_to_store = memcache_crypt.protect_data(keys, serialized_data)

        # Historically the swift cache conection used the argument
        # timeout= for the cache timeout, but this has been unified
        # with the official python memcache client with time= since
        # grizzly, we still need to handle folsom for a while until
        # this could get removed.
        try:
            self._cache.set(cache_key,
                            data_to_store,
                            time=self.token_cache_time)
        except (TypeError):
            self._cache.set(cache_key,
                            data_to_store,
                            timeout=self.token_cache_time)
예제 #3
0
    def _cache_store(self, policy):
        """Store value into memcache.

        data may be the string 'invalid' or a tuple like (data, expires)

        """
        serialized_data = json.dumps(policy['blob'])
        if self._memcache_security_strategy is None:
            cache_key = CACHE_KEY_TEMPLATE
            data_to_store = (policy['timestamp'],serialized_data)
        else:
            keys = memcache_crypt.derive_keys(
                token,
                self._memcache_secret_key,
                self._memcache_security_strategy)
            cache_key = CACHE_KEY_TEMPLATE % memcache_crypt.get_cache_key(keys)
            data_to_store = memcache_crypt.protect_data(keys, serialized_data)
        try:
            self._cache.set(cache_key,
                            data_to_store,
                            time=self.policy_cache_time)
        except(TypeError):
            self._cache.set(cache_key,
                            data_to_store,
                            timeout=self.policy_cache_time)
 def test_protect_wrappers(self):
     data = b'My Pretty Little Data'
     for strategy in [b'MAC', b'ENCRYPT']:
         keys = self._setup_keys(strategy)
         protected = memcache_crypt.protect_data(keys, data)
         self.assertNotEqual(protected, data)
         if strategy == b'ENCRYPT':
             self.assertNotIn(data, protected)
         unprotected = memcache_crypt.unprotect_data(keys, protected)
         self.assertEqual(data, unprotected)
         self.assertRaises(memcache_crypt.InvalidMacError,
                           memcache_crypt.unprotect_data,
                           keys, protected[:-1])
         self.assertIsNone(memcache_crypt.unprotect_data(keys, None))
 def test_protect_wrappers(self):
     data = b'My Pretty Little Data'
     for strategy in [b'MAC', b'ENCRYPT']:
         keys = self._setup_keys(strategy)
         protected = memcache_crypt.protect_data(keys, data)
         self.assertNotEqual(protected, data)
         if strategy == b'ENCRYPT':
             self.assertNotIn(data, protected)
         unprotected = memcache_crypt.unprotect_data(keys, protected)
         self.assertEqual(data, unprotected)
         self.assertRaises(memcache_crypt.InvalidMacError,
                           memcache_crypt.unprotect_data,
                           keys, protected[:-1])
         self.assertIsNone(memcache_crypt.unprotect_data(keys, None))