From 5dba167b3d3f2a64b714f3b8249eebca40b7d60e Mon Sep 17 00:00:00 2001 From: Niels Robin-Aubertin Date: Tue, 8 Oct 2024 15:16:49 -0400 Subject: [PATCH] Enable attachment of binary files as charm resources --- juju/model.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/juju/model.py b/juju/model.py index a51944de..3b802486 100644 --- a/juju/model.py +++ b/juju/model.py @@ -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) @@ -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() headers['Content-Disposition'] = disp conn.request('PUT', url, data, headers)