From e87a74695e2f55dbb0e01721de9d46e230e36008 Mon Sep 17 00:00:00 2001 From: John Dickinson Date: Sat, 6 Jun 2015 13:03:15 -0700 Subject: [PATCH] add domain_remap to /info Also added the value of default_reseller_prefix to /info. I did not add the reseller_prefixes value to /info because deployers may not want to expose all of the resellers that are available. Change-Id: I9ca2f002dc395913bb646390d6908dfb8f554df1 --- swift/common/middleware/domain_remap.py | 8 +++++-- .../common/middleware/test_domain_remap.py | 22 +++++++++++++++++++ 2 files changed, 28 insertions(+), 2 deletions(-) diff --git a/swift/common/middleware/domain_remap.py b/swift/common/middleware/domain_remap.py index 052f7728df..ee74b4fd83 100644 --- a/swift/common/middleware/domain_remap.py +++ b/swift/common/middleware/domain_remap.py @@ -51,6 +51,7 @@ sync destinations. """ from swift.common.swob import Request, HTTPBadRequest +from swift.common.utils import list_from_csv, register_swift_info class DomainRemapMiddleware(object): @@ -71,8 +72,7 @@ class DomainRemapMiddleware(object): self.storage_domain = '.' + self.storage_domain self.path_root = conf.get('path_root', 'v1').strip('/') prefixes = conf.get('reseller_prefixes', 'AUTH') - self.reseller_prefixes = [x.strip() for x in prefixes.split(',') - if x.strip()] + self.reseller_prefixes = list_from_csv(prefixes) self.reseller_prefixes_lower = [x.lower() for x in self.reseller_prefixes] self.default_reseller_prefix = conf.get('default_reseller_prefix') @@ -136,6 +136,10 @@ def filter_factory(global_conf, **local_conf): conf = global_conf.copy() conf.update(local_conf) + register_swift_info( + 'domain_remap', + default_reseller_prefix=conf.get('default_reseller_prefix')) + def domain_filter(app): return DomainRemapMiddleware(app, conf) return domain_filter diff --git a/test/unit/common/middleware/test_domain_remap.py b/test/unit/common/middleware/test_domain_remap.py index b14dfbcb2e..225e947a76 100644 --- a/test/unit/common/middleware/test_domain_remap.py +++ b/test/unit/common/middleware/test_domain_remap.py @@ -17,6 +17,7 @@ import unittest from swift.common.swob import Request from swift.common.middleware import domain_remap +from swift.common import utils class FakeApp(object): @@ -155,5 +156,26 @@ class TestDomainRemap(unittest.TestCase): self.assertEquals(resp, '/v1/AUTH_uuid/test') +class TestSwiftInfo(unittest.TestCase): + def setUp(self): + utils._swift_info = {} + utils._swift_admin_info = {} + + def test_registered_defaults(self): + domain_remap.filter_factory({}) + swift_info = utils.get_swift_info() + self.assertTrue('domain_remap' in swift_info) + self.assertTrue( + swift_info['domain_remap'].get('default_reseller_prefix') is None) + + def test_registered_nondefaults(self): + domain_remap.filter_factory({'default_reseller_prefix': 'cupcake'}) + swift_info = utils.get_swift_info() + self.assertTrue('domain_remap' in swift_info) + self.assertEquals( + swift_info['domain_remap'].get('default_reseller_prefix'), + 'cupcake') + + if __name__ == '__main__': unittest.main()