Expose allowed tempurl methods in /info
Clients can construct tempurls for any method, but they only work if they're in this list, so it's helpful for clients to see the list. Change-Id: Id852f457d65b62c4fe79db01b1d7029a5fa5aa09
This commit is contained in:
parent
c8c512b977
commit
979033a14e
@ -80,6 +80,15 @@ above example::
|
||||
https://swift-cluster.example.com/v1/AUTH_account/container/object?
|
||||
temp_url_sig=da39a3ee5e6b4b0d3255bfef95601890afd80709&
|
||||
temp_url_expires=1323479485&filename=My+Test+File.pdf
|
||||
|
||||
If you do not want the object to be downloaded, you can cause
|
||||
"Content-Disposition: inline" to be set on the response by adding the "inline"
|
||||
parameter to the query string, like so::
|
||||
|
||||
https://swift-cluster.example.com/v1/AUTH_account/container/object?
|
||||
temp_url_sig=da39a3ee5e6b4b0d3255bfef95601890afd80709&
|
||||
temp_url_expires=1323479485&inline
|
||||
|
||||
"""
|
||||
|
||||
__all__ = ['TempURL', 'filter_factory',
|
||||
@ -183,14 +192,14 @@ class TempURL(object):
|
||||
:param conf: The configuration dict for the middleware.
|
||||
"""
|
||||
|
||||
def __init__(self, app, conf):
|
||||
def __init__(self, app, conf, methods=('GET', 'HEAD', 'PUT')):
|
||||
#: The next WSGI application/filter in the paste.deploy pipeline.
|
||||
self.app = app
|
||||
#: The filter configuration dict.
|
||||
self.conf = conf
|
||||
|
||||
#: The methods allowed with Temp URLs.
|
||||
self.methods = conf.get('methods', 'GET HEAD PUT').split()
|
||||
self.methods = methods
|
||||
|
||||
headers = DEFAULT_INCOMING_REMOVE_HEADERS
|
||||
if 'incoming_remove_headers' in conf:
|
||||
@ -474,5 +483,8 @@ def filter_factory(global_conf, **local_conf):
|
||||
"""Returns the WSGI filter for use with paste.deploy."""
|
||||
conf = global_conf.copy()
|
||||
conf.update(local_conf)
|
||||
register_swift_info('tempurl')
|
||||
return lambda app: TempURL(app, conf)
|
||||
|
||||
methods = conf.get('methods', 'GET HEAD PUT').split()
|
||||
register_swift_info('tempurl', methods=methods)
|
||||
|
||||
return lambda app: TempURL(app, conf, methods=methods)
|
||||
|
@ -20,7 +20,7 @@ from time import time
|
||||
|
||||
from swift.common.middleware import tempauth, tempurl
|
||||
from swift.common.swob import Request, Response, HeaderKeyDict
|
||||
from swift.common.utils import split_path
|
||||
from swift.common import utils
|
||||
|
||||
|
||||
class FakeApp(object):
|
||||
@ -59,7 +59,7 @@ class TestTempURL(unittest.TestCase):
|
||||
if environ is None:
|
||||
environ = {}
|
||||
|
||||
_junk, account, _junk, _junk = split_path(path, 2, 4)
|
||||
_junk, account, _junk, _junk = utils.split_path(path, 2, 4)
|
||||
self._fake_cache_environ(environ, account, keys)
|
||||
req = Request.blank(path, environ=environ, **kwargs)
|
||||
return req
|
||||
@ -869,5 +869,25 @@ class TestTempURL(unittest.TestCase):
|
||||
self.assertTrue(isinstance(str_value, str))
|
||||
|
||||
|
||||
class TestSwiftInfo(unittest.TestCase):
|
||||
def setUp(self):
|
||||
utils._swift_info = {}
|
||||
utils._swift_admin_info = {}
|
||||
|
||||
def test_registered_defaults(self):
|
||||
tempurl.filter_factory({})
|
||||
swift_info = utils.get_swift_info()
|
||||
self.assertTrue('tempurl' in swift_info)
|
||||
self.assertEqual(set(swift_info['tempurl']['methods']),
|
||||
set(('GET', 'HEAD', 'PUT')))
|
||||
|
||||
def test_non_default_methods(self):
|
||||
tempurl.filter_factory({'methods': 'GET HEAD PUT POST DELETE'})
|
||||
swift_info = utils.get_swift_info()
|
||||
self.assertTrue('tempurl' in swift_info)
|
||||
self.assertEqual(set(swift_info['tempurl']['methods']),
|
||||
set(('GET', 'HEAD', 'PUT', 'POST', 'DELETE')))
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
unittest.main()
|
||||
|
Loading…
Reference in New Issue
Block a user