Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add MD5 checksum for Bytes parameters #523

Merged
merged 2 commits into from
Dec 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ TBD
- Added support for display name to command decorator
- Updated Wait Timeout Exception expected HTTP code from 408 to 504
- Dropping Official Python 2.7 Support
- Update Bytes file download to validate MD5 checksum

3.29.0
------
Expand Down
17 changes: 16 additions & 1 deletion brewtils/resolvers/bytes.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
# -*- coding: utf-8 -*-

from hashlib import md5

from brewtils.errors import ValidationError
from brewtils.resolvers import ResolverBase


Expand All @@ -19,4 +22,16 @@ def should_download(self, value, definition):
return definition.type.lower() == "bytes"

def download(self, value, definition):
return self.easy_client.download_bytes(value.id)
file_bytes = self.easy_client.download_bytes(value.id)

if value.details:
if (
"md5_sum" in value.details
and value.details["md5_sum"]
!= md5(file_bytes.decode("utf-8").encode("utf-8")).hexdigest()
):
raise ValidationError(
"Requested file %s MD5 SUM %s does match actual MD5 SUM %s"
% (value.id, value.details["md5_sum"], md5(value).hexdigest())
)
return file_bytes
Loading