mirror of
https://github.com/lucaspalomodevelop/indico-plugins.git
synced 2026-03-19 18:24:39 +00:00
Storage/S3: Truncate bucket hash if necessary
This commit is contained in:
parent
71a679267c
commit
3a32e524f8
@ -223,7 +223,7 @@ class DynamicS3Storage(S3StorageBase):
|
||||
def _get_bucket_name(self, date):
|
||||
name = self._replace_bucket_placeholders(self.bucket_name_template, date)
|
||||
token = hmac.new(self.bucket_secret.encode('utf-8'), name, hashlib.md5).hexdigest()
|
||||
return '{}-{}'.format(name, token)
|
||||
return '{}-{}'.format(name, token)[:63]
|
||||
|
||||
def _replace_bucket_placeholders(self, name, date):
|
||||
name = name.replace('<year>', date.strftime('%Y'))
|
||||
|
||||
@ -102,8 +102,10 @@ def test_static_bucket_name_too_long():
|
||||
|
||||
|
||||
def test_dynamic_bucket_name_too_long():
|
||||
DynamicS3Storage('bucket_secret=secret,bucket_template=test-<year>' + 'x'*37)
|
||||
DynamicS3Storage('bucket_secret=secret,bucket_template=test-<year>-<month>' + 'x'*34)
|
||||
s = DynamicS3Storage('bucket_secret=secret,bucket_template=test-<year>' + 'x'*37)
|
||||
assert len(s._get_current_bucket_name()) == 63
|
||||
s = DynamicS3Storage('bucket_secret=secret,bucket_template=test-<year>-<month>' + 'x'*34)
|
||||
assert len(s._get_current_bucket_name()) == 63
|
||||
with pytest.raises(StorageError):
|
||||
DynamicS3Storage('bucket_secret=secret,bucket_template=test-<year>' + 'x' * 38)
|
||||
with pytest.raises(StorageError):
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user