Ignore requests which do not match reseller_prefix
When we cannot extract the account ID from the request environment, instead of using the request path as resource ID, just return without emitting an event. Implement a configuration parameter to enable this new behavior, the legacy behavior remaining the default. Change-Id: Ice91bc1ce4436568472e8edfac984ed2ed09e34e
This commit is contained in:
parent
fecef0bd84
commit
e1b14cf0b0
|
@ -27,6 +27,10 @@ before "proxy-server" and add the following filter in the file:
|
|||
metadata_headers = X-TEST
|
||||
# Set reseller prefix (defaults to "AUTH_" if not set)
|
||||
reseller_prefix = AUTH_
|
||||
# If True, ignore requests whose account does not start with the
|
||||
# reseller_prefix. When False, keep the legacy behavior: emit an event
|
||||
# with the request path as resource ID.
|
||||
match_reseller_prefix = False
|
||||
# Set control_exchange to publish to.
|
||||
control_exchange = swift
|
||||
# Set transport url
|
||||
|
@ -177,6 +181,8 @@ class Swift(object):
|
|||
self.reseller_prefix = conf.get('reseller_prefix', 'AUTH_')
|
||||
if self.reseller_prefix and self.reseller_prefix[-1] != '_':
|
||||
self.reseller_prefix += '_'
|
||||
self.match_reseller_prefix = strutils.bool_from_string(
|
||||
conf.get('match_reseller_prefix', False))
|
||||
|
||||
LOG.setLevel(getattr(logging, conf.get('log_level', 'WARNING')))
|
||||
|
||||
|
@ -329,6 +335,10 @@ class Swift(object):
|
|||
except ValueError:
|
||||
return
|
||||
|
||||
if (self.match_reseller_prefix
|
||||
and not account.startswith(self.reseller_prefix)):
|
||||
return
|
||||
|
||||
now = datetime.datetime.utcnow().isoformat()
|
||||
|
||||
resource_metadata = {
|
||||
|
|
|
@ -465,6 +465,19 @@ class TestSwift(tests_base.TestCase):
|
|||
warning.assert_called_once_with(
|
||||
"fail to find project '%s' in keystone", "gnocchi")
|
||||
|
||||
def test_match_reseller_prefix(self):
|
||||
"""
|
||||
Ensure we do not notify if the request's account does not match
|
||||
the configured reseller_prefix.
|
||||
"""
|
||||
app = swift.Swift(FakeApp(), {'reseller_prefix': 'CUSTOM',
|
||||
'match_reseller_prefix': 'True'})
|
||||
req = self.get_request('/1.0/NOTMYRESELLER_account/container/obj',
|
||||
environ={'REQUEST_METHOD': 'GET'})
|
||||
with mock.patch('oslo_messaging.Notifier.info') as notify:
|
||||
list(app(req.environ, self.start_response))
|
||||
self.assertFalse(notify.called)
|
||||
|
||||
|
||||
class TestSwiftS3Api(TestSwift):
|
||||
|
||||
|
|
Loading…
Reference in New Issue