Add dot as a valid s3 metadata key (#3958)
This commit is contained in:
parent
75730e6f83
commit
6adb570c48
@ -73,7 +73,7 @@ def parse_region_from_url(url):
|
||||
|
||||
def metadata_from_headers(headers):
|
||||
metadata = CaseInsensitiveDict()
|
||||
meta_regex = re.compile(r"^x-amz-meta-([a-zA-Z0-9\-_]+)$", flags=re.IGNORECASE)
|
||||
meta_regex = re.compile(r"^x-amz-meta-([a-zA-Z0-9\-_.]+)$", flags=re.IGNORECASE)
|
||||
for header, value in headers.items():
|
||||
if isinstance(header, six.string_types):
|
||||
result = meta_regex.match(header)
|
||||
|
@ -65,13 +65,16 @@ def reduced_min_part_size(f):
|
||||
|
||||
|
||||
class MyModel(object):
|
||||
def __init__(self, name, value):
|
||||
def __init__(self, name, value, metadata={}):
|
||||
self.name = name
|
||||
self.value = value
|
||||
self.metadata = metadata
|
||||
|
||||
def save(self):
|
||||
s3 = boto3.client("s3", region_name=DEFAULT_REGION_NAME)
|
||||
s3.put_object(Bucket="mybucket", Key=self.name, Body=self.value)
|
||||
s3.put_object(
|
||||
Bucket="mybucket", Key=self.name, Body=self.value, Metadata=self.metadata
|
||||
)
|
||||
|
||||
|
||||
@mock_s3
|
||||
@ -133,6 +136,24 @@ def test_my_model_save():
|
||||
assert body == "is awesome"
|
||||
|
||||
|
||||
@mock_s3
|
||||
def test_object_metadata():
|
||||
"""Metadata keys can contain certain special characters like dash and dot"""
|
||||
# Create Bucket so that test can run
|
||||
conn = boto3.resource("s3", region_name=DEFAULT_REGION_NAME)
|
||||
conn.create_bucket(Bucket="mybucket")
|
||||
####################################
|
||||
|
||||
metadata = {"meta": "simple", "my-meta": "dash", "meta.data": "namespaced"}
|
||||
|
||||
model_instance = MyModel("steve", "is awesome", metadata=metadata)
|
||||
model_instance.save()
|
||||
|
||||
meta = conn.Object("mybucket", "steve").get()["Metadata"]
|
||||
|
||||
assert meta == metadata
|
||||
|
||||
|
||||
@mock_s3
|
||||
def test_key_etag():
|
||||
conn = boto3.resource("s3", region_name=DEFAULT_REGION_NAME)
|
||||
|
Loading…
Reference in New Issue
Block a user