File size: 1,211 Bytes
2e175db
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
"""
Optional image storage (S3 / Cloudflare R2).

Privacy contract
----------------
Visitor uploads are NEVER persisted by default. This module is only invoked
when ALL of the following are true:

  1. settings.store_uploads is True (env: STORE_UPLOADS=true)
  2. The request comes from an authenticated user
  3. That user has explicitly opted in to scan history / forensic reports

None of this is wired up in Stage 1. The module exists to make the
architecture visible and to lock in the privacy default at the type level.
"""
from __future__ import annotations


def store_image(scan_id: str, image_bytes: bytes) -> str:  # noqa: ARG001
    """Upload image to blob storage; return the object key.

    Raises
    ------
    PermissionError :
        If called when settings.store_uploads is False, as a defence-in-depth
        check against a future bug accidentally persisting visitor uploads.
    """
    from ..config import settings

    if not settings.store_uploads:
        raise PermissionError(
            "Image storage is disabled by default. Enable explicitly via "
            "STORE_UPLOADS=true AND user opt-in."
        )
    raise NotImplementedError("Blob storage wired up in Stage 2.")