Add S3 SigV4 location support

Change-Id: I2ee8cb968ae2cf34558546b1be6be5273c2f52d3
Closes-Bug: #1822322
This commit is contained in:
Edward Hope-Morley 2019-03-29 14:05:32 +00:00
parent 55c5f6837a
commit cc280d9dcb
5 changed files with 49 additions and 1 deletions

View File

@ -10,6 +10,7 @@ from charmhelpers.core.hookenv import (
unit_get,
service_name,
leader_get,
DEBUG,
)
from charmhelpers.contrib.openstack.context import (
OSContextGenerator,
@ -24,7 +25,11 @@ from charmhelpers.contrib.network.ip import (
format_ipv6_addr,
get_ipv6_addr,
)
from charmhelpers.contrib.openstack.utils import get_host_ip
from charmhelpers.contrib.openstack.utils import (
os_release,
CompareOpenStackReleases,
get_host_ip,
)
SWIFT_HASH_FILE = '/var/lib/juju/swift-hash-path.conf'
@ -82,6 +87,20 @@ class SwiftRingContext(OSContextGenerator):
return ctxt
class SwiftS3Context(OSContextGenerator):
def __call__(self):
ctxt = {}
if CompareOpenStackReleases(os_release('swift-common')) >= 'queens':
if config('region'):
ctxt['location'] = config('region')
else:
log("Region config not provided so location cannot be set - "
"required from S3 Sig V4 support to work correctly", DEBUG)
return ctxt
class SwiftIdentityContext(OSContextGenerator):
interfaces = ['identity-service']

View File

@ -22,6 +22,7 @@ from lib.swift_context import (
SwiftRingContext,
ApacheSSLContext,
MemcachedContext,
SwiftS3Context,
)
import charmhelpers.contrib.openstack.context as context
@ -144,6 +145,7 @@ CONFIG_FILES = OrderedDict([
}),
(SWIFT_PROXY_CONF, {
'hook_contexts': [SwiftIdentityContext(),
SwiftS3Context(),
context.BindHostContext(),
context.AMQPContext(ssl_dir=SWIFT_CONF_DIR)],
'services': ['swift-proxy'],

View File

@ -131,6 +131,9 @@ auth_version = 3
[filter:swift3]
use = egg:swift3#swift3
{% if location -%}
location = {{ location }}
{% endif -%}
{% endif %}
{% if auth_type == 'swauth' %}

View File

@ -131,6 +131,9 @@ auth_version = 3
[filter:s3api]
use = egg:swift#s3api
{% if location -%}
location = {{ location }}
{% endif -%}
{% endif %}
{% if auth_type == 'swauth' %}

View File

@ -151,3 +151,24 @@ class SwiftContextTestCase(unittest.TestCase):
self.assertEqual(hash_, fd.read())
self.assertTrue(mock_config.called)
class SwiftS3ContextTestCase(unittest.TestCase):
@mock.patch('lib.swift_context.os_release')
@mock.patch('lib.swift_context.config')
def test_location(self, mock_config, mock_os_release):
cfg = {'region': 'London'}
def fake_config(key):
return cfg.get(key)
mock_config.side_effect = fake_config
mock_os_release.return_value = 'queens'
ctxt = swift_context.SwiftS3Context()
self.assertEqual({'location': 'London'}, ctxt())
mock_os_release.return_value = 'pike'
ctxt = swift_context.SwiftS3Context()
self.assertEqual({}, ctxt())