Advertisement
Guest User

swill

a guest
May 8th, 2012
69
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.78 KB | None | 0 0
  1. def _get_key(self, env, account):
  2. """
  3. Returns the X-Account-Meta-Temp-URL-Key header value for the
  4. account, or None if none is set.
  5.  
  6. :param env: The WSGI environment for the request.
  7. :param account: Account str.
  8. :returns: X-Account-Meta-Temp-URL-Key str value, or None.
  9. """
  10. key = None
  11. memcache = env.get('swift.cache')
  12. if memcache:
  13. key = memcache.get('temp-url-key/%s' % account)
  14. if not key:
  15. newenv = {'REQUEST_METHOD': 'HEAD', 'SCRIPT_NAME': '',
  16. 'PATH_INFO': '/v1/' + account, 'CONTENT_LENGTH': '0',
  17. 'SERVER_PROTOCOL': 'HTTP/1.0',
  18. 'HTTP_USER_AGENT': 'TempURL', 'wsgi.version': (1, 0),
  19. 'wsgi.url_scheme': 'http', 'wsgi.input': StringIO('')}
  20. for name in ('SERVER_NAME', 'SERVER_PORT', 'wsgi.errors',
  21. 'wsgi.multithread', 'wsgi.multiprocess',
  22. 'wsgi.run_once', 'swift.cache', 'swift.trans_id'):
  23. if name in env:
  24. newenv[name] = env[name]
  25. newenv['swift.authorize'] = lambda req: None
  26. newenv['swift.authorize_override'] = True
  27. newenv['REMOTE_USER'] = '.wsgi.tempurl'
  28. key = [None]
  29.  
  30. def _start_response(status, response_headers, exc_info=None):
  31. for h, v in response_headers:
  32. if h.lower() == 'x-account-meta-temp-url-key':
  33. key[0] = v
  34.  
  35. self.logger.debug("env: %s" % str(env))
  36. self.logger.debug("new: %s" % str(newenv))
  37. self.app(newenv, _start_response)
  38. self.logger.debug("key: %s" % str(key))
  39. key = key[0]
  40. if key and memcache:
  41. memcache.set('temp-url-key/%s' % account, key, timeout=60)
  42. return key
  43.  
  44.  
  45. -----
  46.  
  47. May 8 15:41:37 SwiftTest proxy-server env: {'webob._parsed_query_vars': (GET([('temp_url_sig', '440638f0fb33bc955197408a6a15e9fb5ce2adf8'), ('temp_url_expires', '1336507058')]), 'temp_url_sig=440638f0fb33bc955197408a6a15e9fb5ce2adf8&temp_url_expires=1336507058'), 'SCRIPT_NAME': '', 'REQUEST_METHOD': 'GET', 'PATH_INFO': '/v1/admin/curl_container/TEST_README', 'SERVER_PROTOCOL': 'HTTP/1.0', 'QUERY_STRING': 'temp_url_sig=440638f0fb33bc955197408a6a15e9fb5ce2adf8&temp_url_expires=1336507058', 'HTTP_USER_AGENT': 'curl/7.22.0 (x86_64-pc-linux-gnu) libcurl/7.22.0 OpenSSL/1.0.1 zlib/1.2.3.4 libidn/1.23 librtmp/2.3', 'eventlet.posthooks': [], 'SERVER_NAME': '10.150.1.61', 'REMOTE_ADDR': '10.150.1.61', 'eventlet.input': <eventlet.wsgi.Input object at 0x2077d90>, 'wsgi.url_scheme': 'http', 'SERVER_PORT': '8080', 'wsgi.input': <eventlet.wsgi.Input object at 0x2077d90>, 'HTTP_HOST': '10.150.1.61:8080', 'wsgi.multithread': True, 'HTTP_ACCEPT': '*/*', 'wsgi.version': (1, 0), 'GATEWAY_INTERFACE': 'CGI/1.1', 'wsgi.run_once': False, 'wsgi.errors': <swift.common.utils.LoggerFileObject object at 0x206ee50>, 'wsgi.multiprocess': False, 'swift.trans_id': 'txfcb89c0e9f3f405abffeecefd1ab7aa6', 'CONTENT_TYPE': None, 'swift.cache': <swift.common.memcached.MemcacheRing object at 0x2095e90>}
  48. May 8 15:41:37 SwiftTest proxy-server new: {'wsgi.multithread': True, 'SCRIPT_NAME': '', 'wsgi.input': <StringIO.StringIO instance at 0x2062d88>, 'REQUEST_METHOD': 'HEAD', 'PATH_INFO': '/v1/admin', 'SERVER_PROTOCOL': 'HTTP/1.0', 'swift.authorize': <function <lambda> at 0x207d410>, 'CONTENT_LENGTH': '0', 'HTTP_USER_AGENT': 'TempURL', 'wsgi.version': (1, 0), 'SERVER_NAME': '10.150.1.61', 'wsgi.run_once': False, 'wsgi.errors': <swift.common.utils.LoggerFileObject object at 0x206ee50>, 'wsgi.multiprocess': False, 'swift.trans_id': 'txfcb89c0e9f3f405abffeecefd1ab7aa6', 'wsgi.url_scheme': 'http', 'REMOTE_USER': '.wsgi.tempurl', 'SERVER_PORT': '8080', 'swift.cache': <swift.common.memcached.MemcacheRing object at 0x2095e90>, 'swift.authorize_override': True}
  49. May 8 15:41:37 SwiftTest proxy-server key: [None]
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement