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

Update webapp for private storage bucket #305

Merged
merged 3 commits into from
Jul 30, 2020
Merged

Update webapp for private storage bucket #305

merged 3 commits into from
Jul 30, 2020

Conversation

hdoupe
Copy link
Contributor

@hdoupe hdoupe commented Jul 30, 2020

This PR updates the webapp to work with a private storage bucket. Prior to this PR, the storage bucket was public and anyone could read files directly from it. Granted, the name of each zip file and picture were UUID's and thus, semi-private. However, this makes all files completely private, and access to them is controlled through the C/S authentication system.

The only substantial change required to make this happen was to route the screenshots through a new url /storage/screenshots/[data_id].png. Thanks to the Postgresql JSON field, this was easy to do. It turns out that you can query deeply nested JSON fields such as the "id" field in this data:

{
    "outputs": {
        "renderable": {
            "outputs": [
                {
                    "id": "3da9cbab-e634-4381-b2a2-0fd8df28c414",
                    "title": "Max Scherzer v. All batters",
                    "filename": "Max Scherzer v. All batters.json",
                    "media_type": "bokeh"
                },
                {
                    "id": "1dd082e9-bc92-43c6-ac55-62dadebefe76",
                    "title": "Max Scherzer v. Brian McCann",
                    "filename": "Max Scherzer v. Brian McCann.json",
                    "media_type": "bokeh"
                }
            ]
        }
    }
}

This query will then find a Simulation object with an output that has the queried ID.

Simulation.objects.get(
    outputs__outputs__renderable__outputs__contains=[{"id": "1dd082e9-bc92-43c6-ac55-62dadebefe76"}],
)

Not going directly through to the Google Storage link for loading the screenshots seems to have a minor performance impact (100-200ms per screenshot load), but the privacy trade-off makes this tolerable.

@hdoupe
Copy link
Contributor Author

hdoupe commented Jul 30, 2020

Related to #304.

@hdoupe hdoupe merged commit ab1ae5d into master Jul 30, 2020
@hdoupe hdoupe deleted the private-bucket2 branch July 30, 2020 17:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant