1
0
Fork 0
mirror of https://github.com/ansible-collections/community.general.git synced 2024-09-14 20:13:21 +02:00

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.
This commit is contained in:
Pilou 2018-11-01 17:04:50 +01:00 committed by ansibot
parent d14f9dc685
commit cfe7c9606c
2 changed files with 6 additions and 15 deletions

View file

@ -0,0 +1,3 @@
---
minor_changes:
- "s3_bucket - Walrus users: ``s3_url`` must be a FQDN without scheme not path."

View file

@ -43,7 +43,9 @@ options:
- The JSON policy as a string. - The JSON policy as a string.
s3_url: s3_url:
description: 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 ] aliases: [ S3_URL ]
ceph: ceph:
description: description:
@ -508,17 +510,6 @@ def is_fakes3(s3_url):
return False 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): def get_s3_client(module, aws_connect_kwargs, location, ceph, s3_url):
if s3_url and ceph: # TODO - test this if s3_url and ceph: # TODO - test this
ceph = urlparse(s3_url) 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, params = dict(module=module, conn_type='client', resource='s3', region=location,
endpoint="%s://%s:%s" % (protocol, fakes3.hostname, to_text(port)), endpoint="%s://%s:%s" % (protocol, fakes3.hostname, to_text(port)),
use_ssl=fakes3.scheme == 'fakes3s', **aws_connect_kwargs) 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: else:
params = dict(module=module, conn_type='client', resource='s3', region=location, endpoint=s3_url, **aws_connect_kwargs) params = dict(module=module, conn_type='client', resource='s3', region=location, endpoint=s3_url, **aws_connect_kwargs)
return boto3_conn(**params) return boto3_conn(**params)