From cfe7c9606c6fd628388aecc32127737d35c60877 Mon Sep 17 00:00:00 2001 From: Pilou Date: Thu, 1 Nov 2018 17:04:50 +0100 Subject: [PATCH] s3_bucket: don't assume anything other than *.amazonaws.com is Walrus (#46745) For example, 'https://s3.nl-ams.scw.cloud' isn't Walrus. When Walrus is used, 's3_url' should be a hostname. --- .../fragments/s3_bucket_walrus_endpoint.yaml | 3 +++ lib/ansible/modules/cloud/amazon/s3_bucket.py | 18 +++--------------- 2 files changed, 6 insertions(+), 15 deletions(-) create mode 100644 changelogs/fragments/s3_bucket_walrus_endpoint.yaml diff --git a/changelogs/fragments/s3_bucket_walrus_endpoint.yaml b/changelogs/fragments/s3_bucket_walrus_endpoint.yaml new file mode 100644 index 0000000000..196db18914 --- /dev/null +++ b/changelogs/fragments/s3_bucket_walrus_endpoint.yaml @@ -0,0 +1,3 @@ +--- +minor_changes: + - "s3_bucket - Walrus users: ``s3_url`` must be a FQDN without scheme not path." diff --git a/lib/ansible/modules/cloud/amazon/s3_bucket.py b/lib/ansible/modules/cloud/amazon/s3_bucket.py index 4585c8ed94..1181afa575 100644 --- a/lib/ansible/modules/cloud/amazon/s3_bucket.py +++ b/lib/ansible/modules/cloud/amazon/s3_bucket.py @@ -43,7 +43,9 @@ options: - The JSON policy as a string. s3_url: description: - - S3 URL endpoint for usage with Ceph, Eucalyptus and fakes3 etc. Otherwise assumes AWS. + - S3 URL endpoint for usage with Ceph, Eucalyptus and fakes3 etc. + - Assumes AWS if not specified. + - For Walrus, use FQDN of the endpoint without scheme nor path. aliases: [ S3_URL ] ceph: description: @@ -508,17 +510,6 @@ def is_fakes3(s3_url): return False -def is_walrus(s3_url): - """ Return True if it's Walrus endpoint, not S3 - - We assume anything other than *.amazonaws.com is Walrus""" - if s3_url is not None: - o = urlparse(s3_url) - return not o.hostname.endswith('amazonaws.com') - else: - return False - - def get_s3_client(module, aws_connect_kwargs, location, ceph, s3_url): if s3_url and ceph: # TODO - test this ceph = urlparse(s3_url) @@ -537,9 +528,6 @@ def get_s3_client(module, aws_connect_kwargs, location, ceph, s3_url): params = dict(module=module, conn_type='client', resource='s3', region=location, endpoint="%s://%s:%s" % (protocol, fakes3.hostname, to_text(port)), use_ssl=fakes3.scheme == 'fakes3s', **aws_connect_kwargs) - elif is_walrus(s3_url): - walrus = urlparse(s3_url).hostname - params = dict(module=module, conn_type='client', resource='s3', region=location, endpoint=walrus, **aws_connect_kwargs) else: params = dict(module=module, conn_type='client', resource='s3', region=location, endpoint=s3_url, **aws_connect_kwargs) return boto3_conn(**params)