Skip to content

Commit 4b633a7

Browse files
Retry on content MD5 failures when we want to validate it (Azure#22201)
* settings files * gitignore * retry on content md5 * fixed test * pylint * pylint
1 parent 433e263 commit 4b633a7

File tree

4 files changed

+28
-4
lines changed
  • sdk/storage
    • azure-storage-blob/azure/storage/blob/_shared
    • azure-storage-file-datalake/azure/storage/filedatalake/_shared
    • azure-storage-file-share/azure/storage/fileshare/_shared
    • azure-storage-queue/azure/storage/queue/_shared

4 files changed

+28
-4
lines changed

sdk/storage/azure-storage-blob/azure/storage/blob/_shared/policies.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ def retry_hook(settings, **kwargs):
7373
settings['hook'](retry_count=settings['count'] - 1, location_mode=settings['mode'], **kwargs)
7474

7575

76-
def is_retry(response, mode):
76+
def is_retry(response, mode): # pylint: disable=too-many-return-statements
7777
"""Is this method/status code retryable? (Based on allowlists and control
7878
variables such as the number of total retries to allow, whether to
7979
respect the Retry-After header, whether this header is present, and
@@ -97,6 +97,12 @@ def is_retry(response, mode):
9797
if status in [501, 505]:
9898
return False
9999
return True
100+
# retry if invalid content md5
101+
if response.context.get('validate_content', False) and response.http_response.headers.get('content-md5'):
102+
computed_md5 = response.http_request.headers.get('content-md5', None) or \
103+
encode_base64(StorageContentValidation.get_content_md5(response.http_response.body()))
104+
if response.http_response.headers['content-md5'] != computed_md5:
105+
return True
100106
return False
101107

102108

sdk/storage/azure-storage-file-datalake/azure/storage/filedatalake/_shared/policies.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ def retry_hook(settings, **kwargs):
7373
settings['hook'](retry_count=settings['count'] - 1, location_mode=settings['mode'], **kwargs)
7474

7575

76-
def is_retry(response, mode):
76+
def is_retry(response, mode): # pylint: disable=too-many-return-statements
7777
"""Is this method/status code retryable? (Based on allowlists and control
7878
variables such as the number of total retries to allow, whether to
7979
respect the Retry-After header, whether this header is present, and
@@ -97,6 +97,12 @@ def is_retry(response, mode):
9797
if status in [501, 505]:
9898
return False
9999
return True
100+
# retry if invalid content md5
101+
if response.context.get('validate_content', False) and response.http_response.headers.get('content-md5'):
102+
computed_md5 = response.http_request.headers.get('content-md5', None) or \
103+
encode_base64(StorageContentValidation.get_content_md5(response.http_response.body()))
104+
if response.http_response.headers['content-md5'] != computed_md5:
105+
return True
100106
return False
101107

102108

sdk/storage/azure-storage-file-share/azure/storage/fileshare/_shared/policies.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ def retry_hook(settings, **kwargs):
7373
settings['hook'](retry_count=settings['count'] - 1, location_mode=settings['mode'], **kwargs)
7474

7575

76-
def is_retry(response, mode):
76+
def is_retry(response, mode): # pylint: disable=too-many-return-statements
7777
"""Is this method/status code retryable? (Based on allowlists and control
7878
variables such as the number of total retries to allow, whether to
7979
respect the Retry-After header, whether this header is present, and
@@ -97,6 +97,12 @@ def is_retry(response, mode):
9797
if status in [501, 505]:
9898
return False
9999
return True
100+
# retry if invalid content md5
101+
if response.context.get('validate_content', False) and response.http_response.headers.get('content-md5'):
102+
computed_md5 = response.http_request.headers.get('content-md5', None) or \
103+
encode_base64(StorageContentValidation.get_content_md5(response.http_response.body()))
104+
if response.http_response.headers['content-md5'] != computed_md5:
105+
return True
100106
return False
101107

102108

sdk/storage/azure-storage-queue/azure/storage/queue/_shared/policies.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ def retry_hook(settings, **kwargs):
7373
settings['hook'](retry_count=settings['count'] - 1, location_mode=settings['mode'], **kwargs)
7474

7575

76-
def is_retry(response, mode):
76+
def is_retry(response, mode): # pylint: disable=too-many-return-statements
7777
"""Is this method/status code retryable? (Based on allowlists and control
7878
variables such as the number of total retries to allow, whether to
7979
respect the Retry-After header, whether this header is present, and
@@ -97,6 +97,12 @@ def is_retry(response, mode):
9797
if status in [501, 505]:
9898
return False
9999
return True
100+
# retry if invalid content md5
101+
if response.context.get('validate_content', False) and response.http_response.headers.get('content-md5'):
102+
computed_md5 = response.http_request.headers.get('content-md5', None) or \
103+
encode_base64(StorageContentValidation.get_content_md5(response.http_response.body()))
104+
if response.http_response.headers['content-md5'] != computed_md5:
105+
return True
100106
return False
101107

102108

0 commit comments

Comments
 (0)