Skip to content
This repository was archived by the owner on Aug 4, 2021. It is now read-only.

Commit 06b72fa

Browse files
committed
Implement container downloads
1 parent 6a7cc42 commit 06b72fa

File tree

4 files changed

+484
-27
lines changed

4 files changed

+484
-27
lines changed

swift_upload_runner/api.py

+41-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
# import asyncio
66

77
from .common import get_auth_instance
8-
from .download import FileDownloadProxy
8+
from .download import FileDownloadProxy, ContainerArchiveDownloadProxy
99

1010

1111
async def handle_get_object(
@@ -23,9 +23,49 @@ async def handle_get_object(
2323
)
2424

2525
resp = aiohttp.web.StreamResponse()
26+
27+
# Create headers
28+
resp.headers["Content-Type"] = download.get_type()
29+
resp.headers["Content-Length"] = str(download.get_size())
30+
2631
await resp.prepare(request)
2732

2833
# Create a task for writing the output into the StreamResponse
2934
await download.a_write_to_response(resp)
3035

3136
return resp
37+
38+
39+
async def handle_get_container(
40+
request: aiohttp.web.Request
41+
) -> aiohttp.web.StreamResponse:
42+
"""Handle a request for getting container contents as an archive."""
43+
auth = get_auth_instance(request)
44+
45+
resp = aiohttp.web.StreamResponse()
46+
47+
project = request.match_info["project"]
48+
container = request.match_info["container"]
49+
50+
# Create headers
51+
resp.headers["Content-Type"] = "binary/octet-stream"
52+
# Don't give content length, as the content length depends on
53+
# compressibility
54+
# Suggest {project_name}-{container}.tar as file name
55+
disp_header = f'attachment; filename="{project}-{container}.tar"'
56+
resp.headers["Content-Disposition"] = disp_header
57+
58+
await resp.prepare(request)
59+
60+
download = ContainerArchiveDownloadProxy(
61+
auth,
62+
project,
63+
container
64+
)
65+
66+
await download.a_begin_container_download()
67+
68+
# Create a task for writing the tarball into the StreamResponse
69+
await download.a_write_to_response(resp)
70+
71+
return resp

swift_upload_runner/common.py

+16
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
"""Common resources for swift-upload-runner."""
22

33

4+
import typing
5+
6+
47
import aiohttp.web
58

69
import keystoneauth1.session
@@ -35,6 +38,19 @@ def get_auth_instance(
3538
)
3639

3740

41+
def get_path_from_list(
42+
to_parse: typing.List[str],
43+
path_prefix: str
44+
) -> str:
45+
"""Parse a path from a list of path parts."""
46+
ret = path_prefix
47+
48+
for i in to_parse:
49+
ret += f"/{i}"
50+
51+
return ret.lstrip("/").rstrip("/")
52+
53+
3854
async def handle_delete_preflight(_) -> aiohttp.web.Response:
3955
"""Serve correct response headers to allowed DELETE preflight query."""
4056
resp = aiohttp.web.Response(

0 commit comments

Comments
 (0)