Skip to content
Merged
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
11 changes: 7 additions & 4 deletions web/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,13 @@
import logging
import mimetypes
import os
from typing import Optional
from typing import Generator, Optional

import google.auth.transport.requests
import google.cloud.storage
import google.oauth2.id_token
from cachetools import TTLCache, cached
from flask import Flask, abort, request, send_file
from flask import Flask, abort, request

from cpg_utils.cloud import read_secret
from cpg_utils.membership import is_member_in_cached_group
Expand Down Expand Up @@ -74,7 +74,7 @@


@app.route('/<dataset>/<path:filename>')
def handler(
def handler( # noqa: C901
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Adding the extra iterfile function took this over an arbitrary complexity limit, to fix would need to refactor out some of the other code in the handler function, not keen to do that in this PR as it would make the diff and intent of the change unclear.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Fine by me.

dataset: Optional[str] = None,
filename: Optional[str] = None,
):
Expand Down Expand Up @@ -142,7 +142,10 @@
blob.download_to_file(file_obj)
file_obj.seek(0)

return send_file(file_obj, mimetype=content_type)
def iterfile() -> Generator[bytes, None, None]:
yield from file_obj

return iterfile(), {'Content-Type': content_type}


if __name__ == '__main__':
Expand Down
Loading