Skip to content

Commit

Permalink
Merge pull request #1218 from dimaqq/fix-allow-bin-resource
Browse files Browse the repository at this point in the history
#1218

I've reset author and re-signed commits from #1147 to get the CLA check to pass.
  • Loading branch information
jujubot authored Nov 27, 2024
2 parents 3f34009 + 6b45296 commit c452b66
Showing 1 changed file with 13 additions and 5 deletions.
18 changes: 13 additions & 5 deletions juju/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -2215,16 +2215,24 @@ async def add_local_resources(self, application, entity_url, metadata, resources
"username": "",
"password": "",
}
data = yaml.dump(docker_image_details)
data = yaml.dump(docker_image_details).encode("utf-8")
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)

return resource_map

def _upload(self, data, path, app_name, res_name, res_type, pending_id):
def _upload(
self,
data: bytes,
path: str | Path,
app_name: str,
res_name: str,
res_type: str,
pending_id: str,
) -> None:
conn, headers, path_prefix = self.connection().https_connection()

query = f"?pendingid={pending_id}"
Expand All @@ -2235,8 +2243,8 @@ def _upload(self, data, path, app_name, res_name, res_type, pending_id):
disp = f'form-data; filename="{path}"'

headers["Content-Type"] = "application/octet-stream"
headers["Content-Length"] = len(data)
headers["Content-Sha384"] = hashlib.sha384(bytes(data, "utf-8")).hexdigest()
headers["Content-Length"] = str(len(data))
headers["Content-Sha384"] = hashlib.sha384(data).hexdigest()
headers["Content-Disposition"] = disp

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

0 comments on commit c452b66

Please sign in to comment.