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

Enable attachment of binary files as charm resources #1147

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
4 changes: 2 additions & 2 deletions juju/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -2060,7 +2060,7 @@ async def add_local_resources(self, application, entity_url, metadata, resources
data = yaml.dump(docker_image_details)
else:
p = Path(path)
data = p.read_text() if p.exists() else ''
data = p.read_bytes() if p.exists() else b''

self._upload(data, path, application, name, resource_type, pending_id)

Expand All @@ -2078,7 +2078,7 @@ def _upload(self, data, path, app_name, res_name, res_type, pending_id):

headers['Content-Type'] = 'application/octet-stream'
headers['Content-Length'] = len(data)
headers['Content-Sha384'] = hashlib.sha384(bytes(data, 'utf-8')).hexdigest()
headers['Content-Sha384'] = hashlib.sha384(data).hexdigest()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This effectively changes the argument type from str to bytes.

There's one more call site at line 2141 that would have to be updated to match.

P.S. please add an explicit type hint on the argument.

headers['Content-Disposition'] = disp

conn.request('PUT', url, data, headers)
Expand Down
Loading