Skip to content

Commit

Permalink
Merge pull request #523 from beer-garden/bytes_checksum
Browse files Browse the repository at this point in the history
Add MD5 checksum for Bytes parameters
  • Loading branch information
TheBurchLog authored Dec 19, 2024
2 parents 5b7c8fa + a9f8b66 commit 2f3db60
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
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

0 comments on commit 2f3db60

Please sign in to comment.