forked from mtusi2026/mtusi2026lab4
Compare commits
4
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
c84d112f0d | ||
|
|
483d7eecb3 | ||
|
|
9017861707 | ||
|
|
e9ef559c34 |
+1
-1
@@ -12,7 +12,7 @@ CACHE_URL_FILE=/run/secrets/cache_url
|
||||
API_REPLICAS=2
|
||||
IDEMPOTENCY_TTL_SECONDS=86400
|
||||
CURSOR_SECRET_FILE=/run/secrets/cursor_secret
|
||||
S3_ENDPOINT=http://s3:9000
|
||||
S3_ENDPOINT=http://s3:8333
|
||||
S3_REGION=us-east-1
|
||||
S3_BUCKET=messenger-attachments
|
||||
S3_ACCESS_KEY_ID_FILE=/run/secrets/s3_access_key_id
|
||||
|
||||
@@ -1,14 +1,27 @@
|
||||
## Лабораторная 4
|
||||
|
||||
Автор / группа: TODO
|
||||
Целевая оценка (3/4/5): TODO
|
||||
Трек 5, если заявлен: TODO
|
||||
Автор / группа: Матвей Козырев / БВТ2301
|
||||
Целевая оценка (3/4/5): 5
|
||||
Трек 5, если заявлен: 2 — согласованность PostgreSQL и S3
|
||||
|
||||
Что реализовано и что перенесено: TODO
|
||||
Команды запуска из чистого clone: TODO
|
||||
Результаты проверок и ссылка на REPORT.md: TODO
|
||||
Ограничения / известные ошибки: TODO
|
||||
Источники и использование ИИ: TODO
|
||||
Что реализовано и что перенесено: основа lab3 (две API-реплики, общие сессии,
|
||||
идемпотентные сообщения); приватные S3-вложения PNG/JPEG, ACL и лимиты;
|
||||
reconciler с dry-run, grace period и блокировкой параллельного upload/COMMIT.
|
||||
|
||||
Команды запуска из чистого clone:
|
||||
`python3 scripts/init-secrets.py`, `docker compose up -d --build --wait`, `make test`.
|
||||
Полные зависимости и порядок аудита — в [REPORT.md](../REPORT.md).
|
||||
|
||||
Результаты проверок: [последовательный аудит](../evidence/audit/results.json),
|
||||
логи каждого шага в `evidence/audit/`; гипотеза и ограничения трека в REPORT.md.
|
||||
|
||||
Ограничения: один Docker-host; отсутствующий оригинал восстанавливается из
|
||||
известной копии оператором; полный inventory требует O(N) памяти и на время
|
||||
сверки задерживает PUT/COMMIT. Измерения RAM дискретные, benchmark локальный.
|
||||
|
||||
Источники и использование ИИ: собственный проект lab3; контракт курса;
|
||||
SeaweedFS, Pillow, boto3; Codex использован для реализации, тестов и ревью.
|
||||
Ссылки и закреплённые версии — в REPORT.md.
|
||||
|
||||
- [ ] Весь обязательный минимум текущей и предыдущих работ сохранён с объявленными переходами.
|
||||
- [ ] Контракт и публичные тесты не ослаблены.
|
||||
|
||||
@@ -28,3 +28,41 @@ test-persistence:
|
||||
test-failover:
|
||||
@test -n "$(ACTION_SCRIPT)" || (echo "Set ACTION_SCRIPT to your implemented executable stop-one hook"; exit 2)
|
||||
$(PYTHON) tests/resilience.py --mode failover --action-script "$(ACTION_SCRIPT)" --base-url "$(BASE_URL)" $(TLS_ARGS)
|
||||
|
||||
.PHONY: test-attachments test-private test-upload-failover test-s3-outage reconcile reconcile-apply test-reconcile test-reconcile-benchmark test-upload-memory test-s3-permissions
|
||||
test-attachments:
|
||||
uv run python student-tests/attachments.py --base-url "$(BASE_URL)"
|
||||
|
||||
test-private:
|
||||
$(PYTHON) student-tests/attachment_resilience.py --mode private --base-url "$(BASE_URL)"
|
||||
|
||||
test-upload-failover:
|
||||
$(PYTHON) student-tests/attachment_resilience.py --mode failover --base-url "$(BASE_URL)"
|
||||
|
||||
test-s3-outage:
|
||||
$(PYTHON) student-tests/attachment_resilience.py --mode s3-outage --base-url "$(BASE_URL)"
|
||||
|
||||
reconcile:
|
||||
docker compose --profile maintenance run --rm --no-deps reconcile --grace-seconds 3600
|
||||
|
||||
reconcile-apply:
|
||||
docker compose --profile maintenance run --rm --no-deps reconcile --apply --grace-seconds 3600
|
||||
|
||||
test-reconcile:
|
||||
$(PYTHON) student-tests/reconcile.py --base-url "$(BASE_URL)"
|
||||
|
||||
test-reconcile-benchmark:
|
||||
$(PYTHON) student-tests/reconcile_benchmark.py --base-url "$(BASE_URL)"
|
||||
|
||||
.PHONY: test-reconcile-audit audit
|
||||
test-reconcile-audit:
|
||||
$(PYTHON) student-tests/reconcile_audit.py --base-url "$(BASE_URL)"
|
||||
|
||||
audit:
|
||||
$(PYTHON) scripts/audit.py
|
||||
|
||||
test-upload-memory:
|
||||
uv run python student-tests/upload_memory.py --base-url "$(BASE_URL)"
|
||||
|
||||
test-s3-permissions:
|
||||
$(PYTHON) student-tests/s3_permissions.py --base-url "$(BASE_URL)"
|
||||
|
||||
@@ -1,100 +1,161 @@
|
||||
# Отчёт — лабораторная 4
|
||||
|
||||
- Автор, группа: TODO
|
||||
- Целевая оценка; выбранный трек 5, если нужен: TODO
|
||||
- Commit/PR: TODO после публикации
|
||||
- Использованные источники, библиотеки и помощь ИИ: TODO
|
||||
- Автор, группа: Матвей Козырев, БВТ2301.
|
||||
- Целевая оценка: **5 — исследование и доказанный результат; трек 2: согласованность PostgreSQL и S3**.
|
||||
- Ветка: `solution/BVT2301-Kozyrev`.
|
||||
- Проверки: 22 октября 2026 года. Базовый commit и SHA-256 исходников проверенного рабочего дерева — [evidence/environment.json](evidence/environment.json).
|
||||
- Использованные библиотеки: FastAPI, Uvicorn, asyncpg, argon2-cffi, boto3, Pillow. Помощь ИИ: Codex — перенос основы lab3, реализация вложений, тесты и документация.
|
||||
|
||||
## Запуск из чистого clone
|
||||
|
||||
На текущем этапе перенесена база lab3; S3 и вложения ещё не реализованы.
|
||||
Инструкция ниже запускает только эту базу.
|
||||
|
||||
Нужны Docker Engine с Compose v2 и Python 3 для создания локальных секретов.
|
||||
Версии: Python 3.12.12 и uv 0.11.28 в Dockerfile, PostgreSQL 17.6-alpine,
|
||||
HAProxy 3.0.11-alpine в compose.yaml; зависимости Python закреплены в uv.lock.
|
||||
|
||||
Из корня репозитория:
|
||||
Нужны Docker Engine с Compose v2, Python 3.12+ и свободный порт 8080.
|
||||
|
||||
```sh
|
||||
python3 - <<'PY'
|
||||
from pathlib import Path
|
||||
import secrets
|
||||
|
||||
directory = Path("secrets")
|
||||
directory.mkdir(mode=0o700, exist_ok=True)
|
||||
names = ("postgres_password", "database_url", "cursor_secret")
|
||||
if any((directory / name).exists() for name in names):
|
||||
raise SystemExit("Секреты уже существуют: сохраните их для существующей БД.")
|
||||
password = secrets.token_hex(32)
|
||||
values = (
|
||||
password,
|
||||
f"postgresql://messenger:{password}@postgres:5432/messenger",
|
||||
secrets.token_hex(32),
|
||||
)
|
||||
for name, value in zip(names, values):
|
||||
path = directory / name
|
||||
with path.open("x", encoding="utf-8") as stream:
|
||||
path.chmod(0o600)
|
||||
stream.write(value + "\n")
|
||||
PY
|
||||
docker compose --env-file .env.example config --quiet
|
||||
docker compose --env-file .env.example up -d --build --wait
|
||||
python3 scripts/init-secrets.py
|
||||
docker compose config --quiet
|
||||
docker compose up -d --build --wait
|
||||
curl --fail http://localhost:8080/health/ready
|
||||
make check
|
||||
python3 student-tests/review_regressions.py
|
||||
make test
|
||||
```
|
||||
|
||||
Сервис `migrate` применяет SQL-миграции до запуска API.
|
||||
Вход через HAProxy: `http://localhost:8080`; порты API и PostgreSQL на host не опубликованы.
|
||||
Порт 8080 должен быть свободен. Compose использует отдельный проект и volume lab4;
|
||||
секреты и данные lab3 не переносились.
|
||||
`init-secrets.py` создаёт локальные случайные credentials в игнорируемом каталоге `secrets/`, не выводит значения и сохраняет существующие файлы при повторном запуске. `.env` не требуется для стандартного Compose: параметры и пути к secrets заданы в [compose.yaml](compose.yaml). Для переопределения TTL можно скопировать `.env.example` в `.env`. S3 endpoint, bucket и лимиты стандартного стенда заданы непосредственно в Compose; `API_REPLICAS`, `SESSION_STORE` и `CACHE_URL_FILE` из шаблона не управляют этой топологией. Реплик две, сессии в PostgreSQL, Redis не используется.
|
||||
|
||||
Остановка с сохранением данных: `docker compose down`.
|
||||
Намеренное удаление данных этого стенда: `docker compose down -v`.
|
||||
Последовательность запуска: PostgreSQL → `migrate` → API; SeaweedFS → `s3-init` → API; здоровые API → HAProxy. Миграции и bootstrap — одноразовые сервисы; их успешное состояние — `Exited (0)`. Bucket `messenger-attachments` создаётся bootstrap-сервисом, ему устанавливается private ACL и удаляется публичная policy, если она существовала. Повторный bootstrap безопасен:
|
||||
|
||||
Полный `make test` пока не проходит: модель Message перенесена из lab3 без
|
||||
`attachment_ids`, endpoint вложений отсутствуют. Публичные тесты и контракт lab4
|
||||
сохранены. Проверки `test-persistence`, `test-failover` и собственная проверка
|
||||
`idempotency_concurrency.py` используют контракт lab4 и требуют дальнейшей
|
||||
реализации. Скрипты restart/stop-one перенесены для текущей топологии;
|
||||
при добавлении S3 restart необходимо дополнить перезапуском этого хранилища.
|
||||
```sh
|
||||
docker compose run --rm --no-deps s3-init
|
||||
```
|
||||
|
||||
Вход только через `http://127.0.0.1:8080`. Порты PostgreSQL, API и SeaweedFS на host не публикуются. Остановка с сохранением данных: `docker compose down`; повторный запуск — `docker compose up -d --wait`. **Намеренное удаление всех учебных данных lab4:** `docker compose down -v`. Секреты следует сохранять вместе с volumes, иначе существующая БД может перестать принимать подключение.
|
||||
|
||||
Версии runtime и зависимостей закреплены в [Dockerfile](Dockerfile), [pyproject.toml](pyproject.toml) и [uv.lock](uv.lock). Python контейнера — 3.12.12, uv — 0.11.28; boto3 — 1.43.115, Pillow — 13.0.0.
|
||||
|
||||
## Архитектура и решения
|
||||
|
||||
Перенесено из локального проекта `mtusi2026lab3`: `src/`, миграции
|
||||
`001`–`003`, Dockerfile, зависимости и lockfile, основной Compose, конфигурация
|
||||
HAProxy, restart/failover hooks и собственные проверки сессий, идемпотентности,
|
||||
readiness и ошибок API. Исследовательский benchmark lab3 и старые результаты
|
||||
экспериментов не входят в этот перенос.
|
||||
```text
|
||||
Клиент → HAProxy → api-a / api-b → PostgreSQL (метаданные)
|
||||
→ SeaweedFS S3 (оригиналы)
|
||||
```
|
||||
|
||||
Текущая схема: клиент → HAProxy → api-a / api-b → PostgreSQL.
|
||||
PostgreSQL хранит пользователей, сессии, чаты, сообщения и записи идемпотентности.
|
||||
Общий `CURSOR_SECRET_FILE` задаёт ключ подписи курсоров для обеих реплик.
|
||||
Исходники API пока сохраняют поведение и версию 1.3.0 из lab3.
|
||||
Параметры S3 из `.env.example` будут подключены на следующем этапе.
|
||||
| Роль / service | Версия | Готовность | Persistent storage | Доступ и credentials |
|
||||
| --- | --- | --- | --- | --- |
|
||||
| API / api-a, api-b | Python 3.12.12, исходники репозитория | `/health/ready`: PostgreSQL SELECT + S3 HeadBucket | Нет | Внутренний 8080; DB URL, cursor secret, отдельные S3 credentials из файлов |
|
||||
| PostgreSQL / postgres | 17.6-alpine | pg_isready | postgres_data | Внутренний 5432; password file |
|
||||
| LB / load_balancer | HAProxy 3.0.11-alpine | readiness API, активные backend checks | Нет | Host 127.0.0.1:8080 |
|
||||
| S3 / s3 | SeaweedFS 4.17, digest в Compose | master cluster status; bootstrap дополнительно проверяет S3 | s3_data: файлы и LevelDB filer | Внутренний 8333; identity config из secret |
|
||||
| Bootstrap / s3-init | Тот же Python-образ | exit 0 | Нет | Отдельные административные S3 credentials |
|
||||
|
||||
TODO: схема процессов/хранилищ, источник истины, транзакционные границы, ограничения. Что перенесено из lab3, что изменено в этой работе. Соответствие переменных из .env.example реальной конфигурации.
|
||||
SeaweedFS закреплён digest `sha256:186de7ef977a20343ee9a5544073f081976a29e2d29ecf8379891e7bf177fbe9`. Настройка filer LevelDB в [infra/filer.toml](infra/filer.toml) сохраняет его метаданные в `/data/filer` на том же volume. S3 identity `api` имеет Read/Write/List только для `messenger-attachments`; anonymous identity отсутствует. Она не может выполнять bucket-admin operations. Административные credentials доступны bootstrap и maintenance-reconciler, но не API. SeaweedFS классифицирует DELETE object как Write, поэтому этот провайдер не разделяет PUT и DELETE внутри одной Write-разрешённой bucket-scoped identity; reconciler вынесен в отдельный maintenance container, а API-код не содержит операции удаления. Внутренняя Docker-сеть считается доверенной; это не защита от компрометации контейнера.
|
||||
|
||||
## Доказательства критериев
|
||||
Лимиты Compose: каждая API — 0,5 CPU / 512 MiB; PostgreSQL — 0,75 CPU / 512 MiB; SeaweedFS — 1 CPU / 512 MiB; HAProxy — 0,25 CPU / 128 MiB. SeaweedFS допускает до 64 локальных data volumes по 128 MiB; это предотвращает исчерпание учебного лимита при повторяемых test uploads. Это учебный стенд на одном Docker-host, без высокой доступности БД, S3, LB и самого host.
|
||||
|
||||
| Критерий README | Команда/сценарий | Наблюдаемый результат | Файл доказательства |
|
||||
| --- | --- | --- | --- |
|
||||
| Публичный smoke | make test | TODO | TODO |
|
||||
| Остальные пункты уровня 3 | TODO | TODO | TODO |
|
||||
| Все пункты уровня 4, если заявлен | TODO | TODO | TODO |
|
||||
| Выбранный трек 5, если заявлен | TODO | TODO | TODO |
|
||||
### Перенос lab3 и модель вложений
|
||||
|
||||
TODO: добавить отдельную строку для каждого заявленного критерия. PASS без команды и наблюдения не является доказательством. Проверка инфраструктурного hook требует подтверждения, какие реальные процессы/хранилища перезапущены.
|
||||
Из lab3 сохранены пользователи, чаты, общие PostgreSQL-сессии, Argon2 password hashing, keyset-пагинация, подпись cursor общим ключом, `X-Request-Id`, `X-Instance-Id`, идемпотентность сообщений и две реплики за HAProxy. Исходные публичные `tests/` и `contracts/` lab4 не изменены.
|
||||
|
||||
## Эксперименты и отказы
|
||||
Миграция [004_attachments.sql](migrations/004_attachments.sql) добавляет таблицу Attachment: ID, чат, владелец, отображаемое имя, MIME, размер, SHA-256, внутренний object key и время. Байты в PostgreSQL не записываются. `messages.attachment_ids` — массив UUID, по умолчанию пустой. При создании сообщения в одной транзакции проверяются членство в чате и принадлежность всех вложений этому чату, затем записываются сообщение и результат идемпотентности. У массива нет отдельного внешнего ключа: связь проверяет приложение; удаления вложений и изменения состава чата в API нет.
|
||||
|
||||
TODO: гипотеза, hardware/лимиты, версии, объём данных, профиль нагрузки, concurrency/arrival rate, длительность/прогрев, повторы, успешные RPS, ошибки, p50/p95/p99, CPU/RAM. Сохранить raw summary без tokens и объяснить ограничения измерения.
|
||||
Пустой текст разрешён только с вложением. Пропущенное `attachment_ids` и `[]` эквивалентны; hash текстовых сообщений сохранён совместимым с lab3. Для сообщения с вложениями hash также включает упорядоченный список нормализованных UUID. История и повтор POST возвращают те же attachment IDs.
|
||||
|
||||
| Воздействие | Что ожидаем | Что наблюдали | Время восстановления / потеря данных |
|
||||
| --- | --- | --- | --- |
|
||||
| TODO | TODO | TODO | TODO |
|
||||
### Загрузка и скачивание
|
||||
|
||||
## Ограничения и следующие шаги
|
||||
[attachments.py](src/attachments.py) принимает raw PNG/JPEG. Сначала проверяются Bearer-сессия и членство в чате. `filename` не используется как путь; запрещены `/`, `\`, управляющие символы и недопустимая длина. Сервер генерирует ключ `originals/<UUID>`.
|
||||
|
||||
TODO: какие отказы выдерживаются и какие нет; что не реализовано; где учебное упрощение; какое улучшение подтверждено, а какое пока гипотеза.
|
||||
Лимит **10 MiB = 10 × 1024 × 1024 = 10 485 760 байт** проверяется по Content-Length и повторно при чтении каждого блока, в том числе для chunked upload. До декодирования Pillow определяет фактический формат и размеры; максимум **40 000 000 пикселей**. Проверяются целостность PNG и декодирование пикселей PNG/JPEG. MIME должен совпадать с содержимым. Анимированный PNG не поддерживается: ответ 415.
|
||||
|
||||
Во время приёма используется удаляемый временный файл; он не является хранилищем оригиналов и не используется при скачивании. На одну API-реплику допускается одна одновременная загрузка/проверка изображения (`UPLOAD_CONCURRENCY=1`), ожидание вместе с загрузкой ограничено 30 секундами (`UPLOAD_TIMEOUT_SECONDS`). SDK и декодирование выполняются вне event loop. S3 connect timeout — 2 с, read timeout — 5 с, автоматические повторы выключены. Объект и запрос ограничены 10 MiB; следовательно API не накапливает неограниченное тело запроса в памяти. Временный файл ограничивает RAM ценой bounded disk usage до 10 MiB на активную загрузку.
|
||||
|
||||
Порядок фиксации: валидация → S3 PUT → INSERT метаданных PostgreSQL → **201, status=ready, variants=[], error_code=null**. GET метаданных и оригинала снова проверяет членство. Для постороннего — 404; без сессии — 401. GET content читает оригинал из S3, проверяет размер и SHA-256 и возвращает байты через API без redirect. Object key и credentials не входят в публичную модель.
|
||||
|
||||
### Согласованность PostgreSQL и S3
|
||||
|
||||
Атомарной транзакции между PostgreSQL и S3 нет. При обработанной ошибке после PUT и до подтверждённого COMMIT API возвращает 503; при аварийном завершении процесса клиент может не получить ответ. Приложение намеренно не удаляет объект синхронно: исход COMMIT мог быть неизвестен. Вместо небезопасного удаления применяется [src.reconcile](src/reconcile.py).
|
||||
|
||||
`make reconcile` запускает inventory в **dry-run**. Он сравнивает только `originals/` S3 с `attachments.object_key`, сообщает orphan, свежие unreferenced и missing objects. `make reconcile-apply` удаляет только orphan старше 3600 секунд; отсутствующие объекты и все referenced записи не удаляются. Возраст объекта отсчитывается от начала обхода. Grace period дополняет общую advisory-блокировку PostgreSQL: upload удерживает shared transaction lock от PUT до COMMIT, а reconciler — exclusive lock на время inventory и удаления. Это исключает гонку с API, завершающим запись. Ожидание блокировки ограничено 5 с; при ошибке БД сверка прекращается. Для ручной аварийной проверки возможно `docker compose --profile maintenance run --rm --no-deps reconcile --apply --grace-seconds N`; значение 0 применяется только в тестах с `--object-key originals/<точный-ключ>`; этот повторяемый флаг ограничивает apply выбранными ключами, сохраняя полный inventory. Reconciler использует отдельные admin credentials, API не получает эти секреты.
|
||||
|
||||
Missing object считается наблюдаемой ошибкой, а не поводом удалить метаданные: download вернёт 503, а maintenance output содержит attachment ID и object key. Восстановление байтов требует оператора или резервной копии; автоматическое восстановление не заявляется. Это безопаснее удаления используемого сообщения/метаданных без источника оригинала.
|
||||
|
||||
### Трек 2 — гипотеза, методика и результат
|
||||
|
||||
**Гипотеза.** Полный inventory ключей `originals/` в S3 и `attachments.object_key` в PostgreSQL позволяет повторяемо обнаружить оба направления рассогласования. При удалении только aged orphan и при запрете автоматического удаления метаданных свежий или используемый файл не будет удалён maintenance-командой.
|
||||
|
||||
**Методика.** [student-tests/reconcile.py](student-tests/reconcile.py) создаёт используемое вложение, новый orphan и запускает dry-run, apply с grace 3600 с и apply с grace 0. Затем повторяет apply и проверяет, что уже исправленный orphan не появился снова. Граница между хранилищами моделируется контролируемым отказом API после успешного S3 PUT и до INSERT; следующая сверка обнаруживает orphan и удаляет его. Ошибка на стороне S3 моделируется удалением оригинала после созданной metadata; сверка сообщает пару `attachment_id`/`object_key`, не удаляет metadata, после восстановления байтов следующий обход не сообщает missing. Защищённое вложение прикреплено к сообщению; после исправления проверяются история и оригинал. Дополнительно [reconcile_audit.py](student-tests/reconcile_audit.py) временно устанавливает PostgreSQL trigger только для собственного тестового чата: реальный INSERT отвергается после PUT, API возвращает 503, dry-run находит orphan, apply удаляет только выбранный ключ, повторный apply ничего не удаляет. Тот же тест проверяет незавершённый PUT/COMMIT параллельно с apply, обрыв клиентского upload и реальную S3-пагинацию с `MaxKeys=7`.
|
||||
|
||||
**Стоимость обхода.** [student-tests/reconcile_benchmark.py](student-tests/reconcile_benchmark.py) добавляет 32, затем 128 свежих неиспользуемых объектов с уникальным префиксом. Для каждого размера выполняются три dry-run обхода; после измерения fixtures удаляются. Reconciler возвращает число объектов, metadata-строк, S3 list pages и длительности стадий. `total_seconds` измеряется после подключения и получения блокировки; запуск контейнера, подключение и ожидание lock в него не входят. Inventory хранит все ключи в памяти: время и RAM имеют порядок O(S3 keys + metadata rows), число LIST зависит от страниц провайдера. Это не измерение предельной пропускной способности.
|
||||
|
||||
В актуальном прогоне для 32 добавленных объектов проверены 155 S3 keys и 122 metadata-строки, одна S3 page; длительности 0,405214, 0,404481 и 0,406961 с, медиана 0,405214 с. Для 128 добавленных объектов: 251 keys, те же 122 metadata-строки, одна page; 0,406231, 0,304459 и 0,403061 с, медиана 0,403061 с. Медиана — среднее по порядку значение отсортированной тройки. Полный машинный вывод — [evidence/audit/reconcile-benchmark.txt](evidence/audit/reconcile-benchmark.txt). Эти замеры не показывают монотонного роста задержки на малом наборе и не доказывают масштабируемость. Отдельная функциональная проверка пагинации прочитала 113 keys через 17 страниц с `MaxKeys=7` — [лог](evidence/audit/reconcile-audit.txt).
|
||||
|
||||
Недоступность S3: upload/download и readiness возвращают 503 в формате Error; liveness остаётся 200. HAProxy исключает unready backend, поэтому при недоступности обеих реплик сам LB может вернуть собственный 503. Проверка формата ошибки API при таком отказе выполняется напрямую внутри Docker-сети. После запуска S3 повторяется `s3-init`: реальный PUT/DELETE подтверждает восстановление записи, затем проверяются прежний download и новый upload. Один успешный HeadBucket не гарантирует готовность записи.
|
||||
|
||||
## Проверки и доказательства
|
||||
|
||||
Полный последовательный повтор: `make audit`. [scripts/audit.py](scripts/audit.py) сохраняет фактический stdout/stderr каждого шага и его exit code в [evidence/audit/results.json](evidence/audit/results.json), останавливаясь при первой ошибке. Актуальные результаты находятся в `evidence/audit/`; прежние логи вне этого каталога относятся к предыдущим версиям. При проверке исходников `git diff ec540a1 -- tests contracts README.md` пуст: обязательные публичные файлы не менялись.
|
||||
|
||||
Для собственных image-тестов и полной OpenAPI-валидации нужны локальные зависимости:
|
||||
|
||||
```sh
|
||||
uv sync --frozen
|
||||
uv pip install -r requirements-dev.txt
|
||||
make check validate PYTHON=.venv/bin/python
|
||||
make test
|
||||
make test-attachments PYTHON=.venv/bin/python
|
||||
python3 student-tests/idempotency_concurrency.py
|
||||
python3 student-tests/review_regressions.py
|
||||
make test-private
|
||||
make test-upload-failover
|
||||
make test-s3-outage
|
||||
python3 scripts/verify-persistence.py
|
||||
make test-failover ACTION_SCRIPT=scripts/stop-one.sh
|
||||
docker compose start api-a api-b
|
||||
make reconcile
|
||||
make test-reconcile
|
||||
make test-reconcile-audit
|
||||
make test-reconcile-benchmark
|
||||
make test-upload-memory
|
||||
make test-s3-permissions
|
||||
```
|
||||
|
||||
Сценарии отказов выполняются последовательно на учебном стенде: они временно останавливают контейнеры. Собственные проверки возвращают остановленные сервисы в работу; публичный `test-failover` оставляет реплику остановленной, поэтому после него нужна команда восстановления реплик. Все данные синтетические, токены не сохраняются. API-тесты добавляют синтетические данные. Reconcile-тесты удаляют только собственные выбранные orphan, а benchmark удаляет свои временные объекты.
|
||||
|
||||
| Критерий | Команда / наблюдение | Результат |
|
||||
| --- | --- | --- |
|
||||
| Структура и OpenAPI | `make check validate PYTHON=.venv/bin/python` | [PASS](evidence/audit/contracts.txt) |
|
||||
| Обязательный API lab4, checksum, ACL | `make test` | [PASS](evidence/audit/smoke.txt) |
|
||||
| PNG/JPEG, сообщение с вложением, чужой чат, неверный MIME/filename, лимиты, chunked | `make test-attachments PYTHON=.venv/bin/python` | [PASS](evidence/audit/attachments.txt) |
|
||||
| Приватность bucket вне API | `make test-private`: anonymous GET существующего объекта → 403 | [PASS](evidence/audit/private-bucket.txt) |
|
||||
| Отказ именно загрузившей API | `make test-upload-failover`: загрузка, остановка обслужившей реплики, те же байты через другую реплику | [PASS](evidence/audit/upload-failover.txt) |
|
||||
| Недоступность S3 | `make test-s3-outage`: 503, восстановление, прежний оригинал | [PASS](evidence/audit/s3-outage.txt) |
|
||||
| Перезапуск всех компонентов, сохранение действующей сессии, метаданных и файла | `python3 scripts/verify-persistence.py`; StartedAt каждого сервиса изменился | [PASS](evidence/audit/persistence.txt) |
|
||||
| Публичный failover, сообщения без дублей и сохранение файла | `make test-failover ACTION_SCRIPT=scripts/stop-one.sh` | [PASS](evidence/audit/public-failover.txt) |
|
||||
| Конкурентная идемпотентность и регрессии lab3 | Собственные проверки lab3 | [Результат](evidence/audit/idempotency.txt) |
|
||||
| Повторный bootstrap bucket | `docker compose run --rm --no-deps s3-init` | [Результат](evidence/audit/bootstrap.txt) |
|
||||
| Reconcile: dry-run, grace period, protected object, missing object, post-PUT/pre-DB отказ | `make test-reconcile` | [PASS](evidence/audit/reconcile.txt) |
|
||||
| Реальный отказ INSERT, ошибка inventory, гонка PUT/COMMIT, обрыв upload, S3 pagination | `make test-reconcile-audit` | [Лог](evidence/audit/reconcile-audit.txt) |
|
||||
| Трек 2: три обхода для 32 и 128 добавленных S3-объектов; метрики inventory | `make test-reconcile-benchmark` | [PASS](evidence/audit/reconcile-benchmark.txt) |
|
||||
| Ограниченные S3 credentials | `make test-s3-permissions`: API не создаёт bucket; отдельный maintenance principal выполняет admin list | [PASS](evidence/audit/s3-permissions.txt) |
|
||||
| 10 одновременных потоковых upload по 5 MiB | `make test-upload-memory`, cgroup `memory.current`, фактические интервалы опроса в JSON | [PASS](evidence/audit/upload-memory.txt), [raw JSON](evidence/upload-memory.json) |
|
||||
|
||||
Точные границы проверены отдельно: PNG с trailing bytes доведён до 10 485 760 байт и скачан без изменений; PNG 8000 × 5000 = 40 000 000 пикселей принят; заголовок 8001 × 5000 = 40 005 000 пикселей отклонён до декодирования. Актуальные значения RAM — в [upload-memory.json](evidence/upload-memory.json), вывод запуска — [audit/upload-memory.txt](evidence/audit/upload-memory.txt). Десять клиентов стартуют через barrier; измерение проверяет наличие обеих API, успешность sampler и минимум две пробы. Между завершением опросов есть пауза 0,1 с; реальный интервал включает Docker latency и записывается в `sample_intervals_seconds`. Измерение дискретное: максимальная проба — нижняя оценка истинного пика, а не строгая верхняя граница.
|
||||
|
||||
### Итог аудита уровней 3–5
|
||||
|
||||
В [results.json](evidence/audit/results.json) завершены 20 шагов, каждый с `exit_code=0`, `complete=true`. Это число включает конфигурацию, восстановление реплик и снимок окружения, а не только тесты. Для повторения нужен запущенный стенд и зависимости из инструкции выше.
|
||||
|
||||
Исправления аудита: синхронизация upload/reconcile; ограничение тестового apply точными ключами; проверка вложения, действительно прикреплённого к сообщению; реальный отказ PostgreSQL INSERT и отказ inventory; корректная обработка ClientDisconnect; write-probe при восстановлении S3; фактические интервалы измерения RAM. Заполнен шаблон PR. Аудит запускался на существующем учебном volume после пересборки образов; отдельный запуск из чистого clone с пустыми volumes в этот прогон не входил.
|
||||
|
||||
## Ограничения
|
||||
|
||||
- Advisory lock действует для писателей, использующих протокол приложения. Ручные SQL/S3-изменения администратора должны выполняться в maintenance-окне. Длительный полный обход задерживает новые PUT/COMMIT; после 5 с ожидания запрос получает 503. Отдельная общая транзакция между S3 и PostgreSQL отсутствует.
|
||||
- Между S3 PUT и COMMIT PostgreSQL нет общей транзакции; orphan закрывает reconciler с grace period, но missing-object запись восстанавливается только оператором/backup. Автоматический repair исходного файла не реализован. Inventory выполняет полный обход keyspace `originals/` и таблицы metadata, поэтому его стоимость растёт с их размером.
|
||||
- API буферизует скачивание не более 10 MiB, чтобы проверить checksum до ответа. Эксперимент 10 upload измеряет cgroup memory.current, но не является capacity benchmark и не покрывает произвольные медленные клиенты, filesystem quota и одновременные скачивания.
|
||||
- Readiness проверяет доступность БД и bucket, но не наличие каждого отдельного объекта. Потеря одного объекта при доступном S3 обнаруживается при скачивании как 503.
|
||||
- Перезапуск с volumes и отказ API подтверждены на одном Docker-host. Потеря volumes/host не покрывается, резервное копирование не реализовано.
|
||||
- HTTP предназначен для локального учебного стенда. Presigned flow, обработка thumbnail и брокер не реализованы.
|
||||
|
||||
## Источники
|
||||
|
||||
- [Контракт API](contracts/README.md), [OpenAPI](contracts/openapi.json), [критерии задания](README.md).
|
||||
- [SeaweedFS исходники и запуск](https://github.com/seaweedfs/seaweedfs), [релиз 4.17](https://github.com/seaweedfs/seaweedfs/releases/tag/4.17). Параметры закреплённого образа дополнительно проверены через `docker run --rm chrislusf/seaweedfs:4.17 server -help`.
|
||||
- [SeaweedFS S3 authorization](https://github.com/seaweedfs/seaweedfs/blob/master/weed/s3api/auth_signature_v4.go): в используемой модели операции, отличные от GET/HEAD, проверяются как `Write`; это источник ограничения на раздельные PUT/DELETE права.
|
||||
- [Pillow Image API](https://pillow.readthedocs.io/en/stable/reference/Image.html): lazy open, размеры, verify/load и decompression bomb limits.
|
||||
- [Boto3 S3 PutObject](https://docs.aws.amazon.com/boto3/latest/reference/services/s3/client/put_object.html): запись оригинала в S3.
|
||||
|
||||
+91
-2
@@ -9,10 +9,23 @@ x-api: &api
|
||||
SESSION_TTL_SECONDS: ${SESSION_TTL_SECONDS:-3600}
|
||||
IDEMPOTENCY_TTL_SECONDS: ${IDEMPOTENCY_TTL_SECONDS:-86400}
|
||||
CURSOR_SECRET_FILE: /run/secrets/cursor_secret
|
||||
S3_ENDPOINT: http://s3:8333
|
||||
S3_BUCKET: messenger-attachments
|
||||
S3_ACCESS_KEY_ID_FILE: /run/secrets/s3_access_key_id
|
||||
S3_SECRET_ACCESS_KEY_FILE: /run/secrets/s3_secret_access_key
|
||||
MAX_UPLOAD_BYTES: "10485760"
|
||||
MAX_IMAGE_PIXELS: "40000000"
|
||||
UPLOAD_CONCURRENCY: "1"
|
||||
UPLOAD_TIMEOUT_SECONDS: "30"
|
||||
UPLOAD_FAULT_AFTER_S3_PUT: ${UPLOAD_FAULT_AFTER_S3_PUT:-0}
|
||||
secrets:
|
||||
- database_url
|
||||
- cursor_secret
|
||||
- s3_access_key_id
|
||||
- s3_secret_access_key
|
||||
depends_on:
|
||||
s3-init:
|
||||
condition: service_completed_successfully
|
||||
migrate:
|
||||
condition: service_completed_successfully
|
||||
expose:
|
||||
@@ -28,9 +41,46 @@ x-api: &api
|
||||
resources:
|
||||
limits:
|
||||
cpus: "0.50"
|
||||
memory: 256M
|
||||
memory: 512M
|
||||
|
||||
services:
|
||||
s3:
|
||||
image: chrislusf/seaweedfs:4.17@sha256:186de7ef977a20343ee9a5544073f081976a29e2d29ecf8379891e7bf177fbe9
|
||||
command: ["server", "-dir=/data", "-ip=s3", "-ip.bind=0.0.0.0", "-s3", "-s3.config=/run/secrets/s3_config", "-master.volumeSizeLimitMB=128", "-volume.max=64", "-s3.port.iceberg=0", "-filer.exposeDirectoryData=false"]
|
||||
secrets:
|
||||
- s3_config
|
||||
volumes:
|
||||
- s3_data:/data
|
||||
- ./infra/filer.toml:/etc/seaweedfs/filer.toml:ro
|
||||
healthcheck:
|
||||
test: ["CMD", "wget", "-q", "-O", "/dev/null", "http://localhost:9333/cluster/status"]
|
||||
interval: 5s
|
||||
timeout: 3s
|
||||
retries: 20
|
||||
start_period: 15s
|
||||
deploy:
|
||||
resources:
|
||||
limits:
|
||||
cpus: "1.0"
|
||||
memory: 512M
|
||||
|
||||
s3-init:
|
||||
build:
|
||||
context: .
|
||||
command: ["/app/.venv/bin/python", "-m", "src.bootstrap_s3"]
|
||||
environment:
|
||||
S3_ENDPOINT: http://s3:8333
|
||||
S3_BUCKET: messenger-attachments
|
||||
S3_ACCESS_KEY_ID_FILE: /run/secrets/s3_admin_key
|
||||
S3_SECRET_ACCESS_KEY_FILE: /run/secrets/s3_admin_secret
|
||||
secrets:
|
||||
- s3_admin_key
|
||||
- s3_admin_secret
|
||||
depends_on:
|
||||
s3:
|
||||
condition: service_healthy
|
||||
restart: "no"
|
||||
|
||||
postgres:
|
||||
image: postgres:17.6-alpine
|
||||
environment:
|
||||
@@ -73,6 +123,34 @@ services:
|
||||
cpus: "0.25"
|
||||
memory: 128M
|
||||
|
||||
reconcile:
|
||||
build:
|
||||
context: .
|
||||
entrypoint: ["/app/.venv/bin/python", "-m", "src.reconcile"]
|
||||
profiles: ["maintenance"]
|
||||
environment:
|
||||
DATABASE_URL_FILE: /run/secrets/database_url
|
||||
CURSOR_SECRET_FILE: /run/secrets/cursor_secret
|
||||
S3_ENDPOINT: http://s3:8333
|
||||
S3_BUCKET: messenger-attachments
|
||||
S3_ACCESS_KEY_ID_FILE: /run/secrets/s3_admin_key
|
||||
S3_SECRET_ACCESS_KEY_FILE: /run/secrets/s3_admin_secret
|
||||
secrets:
|
||||
- database_url
|
||||
- cursor_secret
|
||||
- s3_admin_key
|
||||
- s3_admin_secret
|
||||
depends_on:
|
||||
postgres:
|
||||
condition: service_healthy
|
||||
s3:
|
||||
condition: service_healthy
|
||||
deploy:
|
||||
resources:
|
||||
limits:
|
||||
cpus: "0.25"
|
||||
memory: 128M
|
||||
|
||||
api-a:
|
||||
<<: *api
|
||||
|
||||
@@ -82,7 +160,7 @@ services:
|
||||
load_balancer:
|
||||
image: haproxy:3.0.11-alpine
|
||||
ports:
|
||||
- "8080:8080"
|
||||
- "127.0.0.1:8080:8080"
|
||||
volumes:
|
||||
- ./infra/haproxy.cfg:/usr/local/etc/haproxy/haproxy.cfg:ro
|
||||
depends_on:
|
||||
@@ -103,6 +181,16 @@ services:
|
||||
memory: 128M
|
||||
|
||||
secrets:
|
||||
s3_config:
|
||||
file: ./secrets/s3.json
|
||||
s3_admin_key:
|
||||
file: ./secrets/s3_admin_key
|
||||
s3_admin_secret:
|
||||
file: ./secrets/s3_admin_secret
|
||||
s3_access_key_id:
|
||||
file: ./secrets/s3_access_key_id
|
||||
s3_secret_access_key:
|
||||
file: ./secrets/s3_secret_access_key
|
||||
postgres_password:
|
||||
file: ./secrets/postgres_password
|
||||
database_url:
|
||||
@@ -111,4 +199,5 @@ secrets:
|
||||
file: ./secrets/cursor_secret
|
||||
|
||||
volumes:
|
||||
s3_data:
|
||||
postgres_data:
|
||||
|
||||
@@ -0,0 +1 @@
|
||||
PASS: uploaded via api-b; stopped that container; original downloaded through another replica
|
||||
@@ -0,0 +1,5 @@
|
||||
uv run python student-tests/attachments.py --base-url "http://localhost:8080"
|
||||
PASS: PNG/JPEG originals, metadata, attachment-only messages and ACL
|
||||
PASS: filename, MIME, malformed image, byte/pixel and chunked limits
|
||||
PASS: attachment scope, duplicates and idempotency normalization
|
||||
PASS: inclusive 10 MiB and 40 million pixel boundaries
|
||||
@@ -0,0 +1,4 @@
|
||||
PASS: PNG/JPEG originals, metadata, attachment-only messages and ACL
|
||||
PASS: filename, MIME, malformed image, byte/pixel and chunked limits
|
||||
PASS: attachment scope, duplicates and idempotency normalization
|
||||
PASS: inclusive 10 MiB and 40 million pixel boundaries
|
||||
@@ -0,0 +1,5 @@
|
||||
uv run python student-tests/attachments.py --base-url "http://localhost:8080"
|
||||
PASS: PNG/JPEG originals, metadata, attachment-only messages and ACL
|
||||
PASS: filename, MIME, malformed image, byte/pixel and chunked limits
|
||||
PASS: attachment scope, duplicates and idempotency normalization
|
||||
PASS: inclusive 10 MiB and 40 million pixel boundaries
|
||||
@@ -0,0 +1,3 @@
|
||||
Container mtusi2026lab4-s3-init-run-2b50a47ece12 Creating
|
||||
Container mtusi2026lab4-s3-init-run-2b50a47ece12 Created
|
||||
PASS: private S3 bucket ready
|
||||
@@ -0,0 +1,4 @@
|
||||
.venv/bin/python scripts/check_contract.py
|
||||
PASS: offline skeleton structure, local refs and Python syntax; application NOT tested.
|
||||
.venv/bin/python scripts/validate_openapi.py
|
||||
PASS: full OpenAPI 3.1 and JSON Schema validation; application NOT tested.
|
||||
@@ -0,0 +1 @@
|
||||
PASS: sanitized environment and source hashes saved
|
||||
@@ -0,0 +1,2 @@
|
||||
python3 tests/smoke.py --base-url "http://localhost:8080"
|
||||
PASS: lab4 public API scenario; infrastructure and grading evidence remain separate.
|
||||
@@ -0,0 +1 @@
|
||||
PASS: concurrent idempotency through load balancer
|
||||
@@ -0,0 +1,5 @@
|
||||
Before: {"api-a": {"container": "20ad79ee2eed", "started_at": "2026-10-22T09:02:05.82757442Z"}, "api-b": {"container": "1af56e498842", "started_at": "2026-10-22T09:03:29.014379Z"}, "load_balancer": {"container": "8cc83af691c9", "started_at": "2026-10-22T08:39:31.728278626Z"}, "postgres": {"container": "b756a119c924", "started_at": "2026-10-22T08:29:42.97697609Z"}, "s3": {"container": "fe8f16b7a24d", "started_at": "2026-10-22T09:05:52.697448136Z"}}
|
||||
Executing explicit persistence hook; hook output suppressed to avoid leaking secrets.
|
||||
PASS: persistence preserved confirmed data and existing session. Hook scope needs operator evidence.
|
||||
After: {"api-a": {"container": "20ad79ee2eed", "started_at": "2026-10-22T09:06:32.459401543Z"}, "api-b": {"container": "1af56e498842", "started_at": "2026-10-22T09:06:32.503877126Z"}, "load_balancer": {"container": "8cc83af691c9", "started_at": "2026-10-22T09:06:32.274093543Z"}, "postgres": {"container": "b756a119c924", "started_at": "2026-10-22T09:06:12.261186631Z"}, "s3": {"container": "fe8f16b7a24d", "started_at": "2026-10-22T09:06:15.296714216Z"}}
|
||||
PASS: PostgreSQL, S3, both API replicas and LB actually restarted; volumes preserved
|
||||
@@ -0,0 +1,2 @@
|
||||
python3 student-tests/attachment_resilience.py --mode private --base-url "http://localhost:8080"
|
||||
PASS: anonymous S3 GET returns 403 for an existing object
|
||||
@@ -0,0 +1,4 @@
|
||||
python3 tests/resilience.py --mode failover --action-script "scripts/stop-one.sh" --base-url "http://localhost:8080"
|
||||
Executing explicit failover hook; hook output suppressed to avoid leaking secrets.
|
||||
{"observed_instances_before": 2, "successful_writes": 110, "failed_attempts": 1, "first_recovery_seconds": 2.438}
|
||||
PASS: failover preserved confirmed data and existing session. Hook scope needs operator evidence.
|
||||
@@ -0,0 +1,8 @@
|
||||
python3 student-tests/reconcile_audit.py --base-url "http://localhost:8080"
|
||||
Container mtusi2026lab4-reconcile-run-15577660c231 Creating
|
||||
Container mtusi2026lab4-reconcile-run-15577660c231 Created
|
||||
PASS: failed PostgreSQL inventory aborts apply without deleting the orphan
|
||||
PASS: actual PostgreSQL INSERT rejection -> 503, dry-run detection, scoped repair, repeat no-op
|
||||
PASS: apply with zero grace waits for in-flight PUT/COMMIT; committed original survives
|
||||
PASS: interrupted upload leaves no metadata/object and next upload succeeds
|
||||
PASS: S3 pagination: 113 keys across 17 pages, no missing/duplicate keys
|
||||
@@ -0,0 +1,23 @@
|
||||
python3 student-tests/reconcile_benchmark.py --base-url "http://localhost:8080"
|
||||
Container mtusi2026lab4-s3-init-run-6a8baf52639c Creating
|
||||
Container mtusi2026lab4-s3-init-run-6a8baf52639c Created
|
||||
Container mtusi2026lab4-reconcile-run-59b1c6ee9b52 Creating
|
||||
Container mtusi2026lab4-reconcile-run-59b1c6ee9b52 Created
|
||||
Container mtusi2026lab4-reconcile-run-ee05d61bcec3 Creating
|
||||
Container mtusi2026lab4-reconcile-run-ee05d61bcec3 Created
|
||||
Container mtusi2026lab4-reconcile-run-153fed7867b0 Creating
|
||||
Container mtusi2026lab4-reconcile-run-153fed7867b0 Created
|
||||
Container mtusi2026lab4-s3-init-run-5d803fce14c6 Creating
|
||||
Container mtusi2026lab4-s3-init-run-5d803fce14c6 Created
|
||||
Container mtusi2026lab4-s3-init-run-3c280622f4f2 Creating
|
||||
Container mtusi2026lab4-s3-init-run-3c280622f4f2 Created
|
||||
Container mtusi2026lab4-reconcile-run-feb4441d6df4 Creating
|
||||
Container mtusi2026lab4-reconcile-run-feb4441d6df4 Created
|
||||
Container mtusi2026lab4-reconcile-run-48539f3d2d44 Creating
|
||||
Container mtusi2026lab4-reconcile-run-48539f3d2d44 Created
|
||||
Container mtusi2026lab4-reconcile-run-52134038d85e Creating
|
||||
Container mtusi2026lab4-reconcile-run-52134038d85e Created
|
||||
Container mtusi2026lab4-s3-init-run-8524bd7d89a0 Creating
|
||||
Container mtusi2026lab4-s3-init-run-8524bd7d89a0 Created
|
||||
{"method": "three dry-run inventories per controlled size", "results": [{"added_unreferenced_objects": 32, "median_seconds": 0.405214, "metadata_rows_scanned": 122, "runs": 3, "s3_list_pages": 1, "s3_objects_scanned": 155, "seconds": [0.405214, 0.404481, 0.406961]}, {"added_unreferenced_objects": 128, "median_seconds": 0.403061, "metadata_rows_scanned": 122, "runs": 3, "s3_list_pages": 1, "s3_objects_scanned": 251, "seconds": [0.406231, 0.304459, 0.403061]}]}
|
||||
PASS: reconciler cost measured for 32 and 128 added S3 objects; fixtures removed
|
||||
@@ -0,0 +1,40 @@
|
||||
python3 student-tests/reconcile.py --base-url "http://localhost:8080"
|
||||
Container mtusi2026lab4-s3-init-run-873e8d2796d3 Creating
|
||||
Container mtusi2026lab4-s3-init-run-873e8d2796d3 Created
|
||||
Container mtusi2026lab4-reconcile-run-c2ac112ce56e Creating
|
||||
Container mtusi2026lab4-reconcile-run-c2ac112ce56e Created
|
||||
Container mtusi2026lab4-reconcile-run-41147f965ded Creating
|
||||
Container mtusi2026lab4-reconcile-run-41147f965ded Created
|
||||
Container mtusi2026lab4-reconcile-run-c9842622f73e Creating
|
||||
Container mtusi2026lab4-reconcile-run-c9842622f73e Created
|
||||
Container mtusi2026lab4-reconcile-run-557b0a13c872 Creating
|
||||
Container mtusi2026lab4-reconcile-run-557b0a13c872 Created
|
||||
Container mtusi2026lab4-s3-init-run-73474bd49386 Creating
|
||||
Container mtusi2026lab4-s3-init-run-73474bd49386 Created
|
||||
Container mtusi2026lab4-reconcile-run-c34b435de6ef Creating
|
||||
Container mtusi2026lab4-reconcile-run-c34b435de6ef Created
|
||||
Container mtusi2026lab4-s3-init-run-ee3a098fecf9 Creating
|
||||
Container mtusi2026lab4-s3-init-run-ee3a098fecf9 Created
|
||||
Container mtusi2026lab4-reconcile-run-5e20e2eda1ee Creating
|
||||
Container mtusi2026lab4-reconcile-run-5e20e2eda1ee Created
|
||||
PASS: S3-side missing object, dry-run, grace period and idempotent orphan repair
|
||||
Container mtusi2026lab4-reconcile-run-cb994093df21 Creating
|
||||
Container mtusi2026lab4-reconcile-run-cb994093df21 Created
|
||||
Container mtusi2026lab4-api-a-1 Recreate
|
||||
Container mtusi2026lab4-api-a-1 Recreated
|
||||
Container mtusi2026lab4-api-a-1 Starting
|
||||
Container mtusi2026lab4-api-a-1 Started
|
||||
Container mtusi2026lab4-api-a-1 Running
|
||||
Container mtusi2026lab4-api-a-1 Waiting
|
||||
Container mtusi2026lab4-api-a-1 Healthy
|
||||
Container mtusi2026lab4-reconcile-run-9f42ecfc5dfe Creating
|
||||
Container mtusi2026lab4-reconcile-run-9f42ecfc5dfe Created
|
||||
Container mtusi2026lab4-reconcile-run-9bb0b9b36ed0 Creating
|
||||
Container mtusi2026lab4-reconcile-run-9bb0b9b36ed0 Created
|
||||
PASS: injected pre-INSERT failure repaired; message and used original survive
|
||||
Container mtusi2026lab4-api-a-1 Recreate
|
||||
Container mtusi2026lab4-api-a-1 Recreated
|
||||
Container mtusi2026lab4-api-a-1 Starting
|
||||
Container mtusi2026lab4-api-a-1 Started
|
||||
Container mtusi2026lab4-api-a-1 Waiting
|
||||
Container mtusi2026lab4-api-a-1 Healthy
|
||||
@@ -0,0 +1 @@
|
||||
PASS: non-ASCII Bearer returns 401/challenge; malformed JSON returns contract Error/400
|
||||
@@ -0,0 +1,40 @@
|
||||
Container mtusi2026lab4-postgres-1 Running
|
||||
Container mtusi2026lab4-api-a-1 Running
|
||||
Container mtusi2026lab4-s3-1 Running
|
||||
Container mtusi2026lab4-load_balancer-1 Running
|
||||
Container mtusi2026lab4-s3-1 Waiting
|
||||
Container mtusi2026lab4-postgres-1 Waiting
|
||||
Container mtusi2026lab4-s3-1 Healthy
|
||||
Container mtusi2026lab4-postgres-1 Healthy
|
||||
Container mtusi2026lab4-s3-init-1 Starting
|
||||
Container mtusi2026lab4-migrate-1 Starting
|
||||
Container mtusi2026lab4-s3-init-1 Started
|
||||
Container mtusi2026lab4-migrate-1 Started
|
||||
Container mtusi2026lab4-s3-init-1 Waiting
|
||||
Container mtusi2026lab4-migrate-1 Waiting
|
||||
Container mtusi2026lab4-migrate-1 Waiting
|
||||
Container mtusi2026lab4-s3-init-1 Waiting
|
||||
Container mtusi2026lab4-s3-init-1 Exited
|
||||
Container mtusi2026lab4-s3-init-1 Exited
|
||||
Container mtusi2026lab4-migrate-1 Exited
|
||||
Container mtusi2026lab4-migrate-1 Exited
|
||||
Container mtusi2026lab4-api-b-1 Starting
|
||||
Container mtusi2026lab4-api-b-1 Started
|
||||
Container mtusi2026lab4-api-a-1 Waiting
|
||||
Container mtusi2026lab4-api-b-1 Waiting
|
||||
Container mtusi2026lab4-api-a-1 Healthy
|
||||
Container mtusi2026lab4-api-b-1 Healthy
|
||||
Container mtusi2026lab4-load_balancer-1 Waiting
|
||||
Container mtusi2026lab4-migrate-1 Waiting
|
||||
Container mtusi2026lab4-api-b-1 Waiting
|
||||
Container mtusi2026lab4-s3-init-1 Waiting
|
||||
Container mtusi2026lab4-postgres-1 Waiting
|
||||
Container mtusi2026lab4-api-a-1 Waiting
|
||||
Container mtusi2026lab4-s3-1 Waiting
|
||||
Container mtusi2026lab4-s3-1 Healthy
|
||||
Container mtusi2026lab4-load_balancer-1 Healthy
|
||||
Container mtusi2026lab4-migrate-1 Exited
|
||||
Container mtusi2026lab4-s3-init-1 Exited
|
||||
Container mtusi2026lab4-postgres-1 Healthy
|
||||
Container mtusi2026lab4-api-a-1 Healthy
|
||||
Container mtusi2026lab4-api-b-1 Healthy
|
||||
@@ -0,0 +1,201 @@
|
||||
{
|
||||
"recorded_at_utc": "2026-10-22T09:10:01.024409+00:00",
|
||||
"checks": [
|
||||
{
|
||||
"name": "contracts",
|
||||
"command": [
|
||||
"make",
|
||||
"check",
|
||||
"validate",
|
||||
"PYTHON=.venv/bin/python"
|
||||
],
|
||||
"exit_code": 0,
|
||||
"seconds": 0.529
|
||||
},
|
||||
{
|
||||
"name": "compose",
|
||||
"command": [
|
||||
"docker",
|
||||
"compose",
|
||||
"config",
|
||||
"--quiet"
|
||||
],
|
||||
"exit_code": 0,
|
||||
"seconds": 0.206
|
||||
},
|
||||
{
|
||||
"name": "smoke",
|
||||
"command": [
|
||||
"make",
|
||||
"test"
|
||||
],
|
||||
"exit_code": 0,
|
||||
"seconds": 2.432
|
||||
},
|
||||
{
|
||||
"name": "attachments",
|
||||
"command": [
|
||||
"make",
|
||||
"test-attachments"
|
||||
],
|
||||
"exit_code": 0,
|
||||
"seconds": 4.112
|
||||
},
|
||||
{
|
||||
"name": "idempotency",
|
||||
"command": [
|
||||
"/Library/Frameworks/Python.framework/Versions/3.14/bin/python3",
|
||||
"student-tests/idempotency_concurrency.py"
|
||||
],
|
||||
"exit_code": 0,
|
||||
"seconds": 2.78
|
||||
},
|
||||
{
|
||||
"name": "regressions",
|
||||
"command": [
|
||||
"/Library/Frameworks/Python.framework/Versions/3.14/bin/python3",
|
||||
"student-tests/review_regressions.py"
|
||||
],
|
||||
"exit_code": 0,
|
||||
"seconds": 0.071
|
||||
},
|
||||
{
|
||||
"name": "private-bucket",
|
||||
"command": [
|
||||
"make",
|
||||
"test-private"
|
||||
],
|
||||
"exit_code": 0,
|
||||
"seconds": 2.478
|
||||
},
|
||||
{
|
||||
"name": "s3-permissions",
|
||||
"command": [
|
||||
"make",
|
||||
"test-s3-permissions"
|
||||
],
|
||||
"exit_code": 0,
|
||||
"seconds": 3.223
|
||||
},
|
||||
{
|
||||
"name": "bootstrap",
|
||||
"command": [
|
||||
"docker",
|
||||
"compose",
|
||||
"run",
|
||||
"--rm",
|
||||
"--no-deps",
|
||||
"s3-init"
|
||||
],
|
||||
"exit_code": 0,
|
||||
"seconds": 0.749
|
||||
},
|
||||
{
|
||||
"name": "upload-failover",
|
||||
"command": [
|
||||
"make",
|
||||
"test-upload-failover"
|
||||
],
|
||||
"exit_code": 0,
|
||||
"seconds": 5.878
|
||||
},
|
||||
{
|
||||
"name": "public-failover",
|
||||
"command": [
|
||||
"make",
|
||||
"test-failover",
|
||||
"ACTION_SCRIPT=scripts/stop-one.sh"
|
||||
],
|
||||
"exit_code": 0,
|
||||
"seconds": 18.54
|
||||
},
|
||||
{
|
||||
"name": "restore-replicas",
|
||||
"command": [
|
||||
"docker",
|
||||
"compose",
|
||||
"up",
|
||||
"-d",
|
||||
"--wait",
|
||||
"api-a",
|
||||
"api-b",
|
||||
"load_balancer"
|
||||
],
|
||||
"exit_code": 0,
|
||||
"seconds": 7.856
|
||||
},
|
||||
{
|
||||
"name": "s3-outage",
|
||||
"command": [
|
||||
"make",
|
||||
"test-s3-outage"
|
||||
],
|
||||
"exit_code": 0,
|
||||
"seconds": 23.474
|
||||
},
|
||||
{
|
||||
"name": "persistence",
|
||||
"command": [
|
||||
"/Library/Frameworks/Python.framework/Versions/3.14/bin/python3",
|
||||
"scripts/verify-persistence.py"
|
||||
],
|
||||
"exit_code": 0,
|
||||
"seconds": 28.621
|
||||
},
|
||||
{
|
||||
"name": "reconcile",
|
||||
"command": [
|
||||
"make",
|
||||
"test-reconcile"
|
||||
],
|
||||
"exit_code": 0,
|
||||
"seconds": 61.524
|
||||
},
|
||||
{
|
||||
"name": "reconcile-audit",
|
||||
"command": [
|
||||
"make",
|
||||
"test-reconcile-audit"
|
||||
],
|
||||
"exit_code": 0,
|
||||
"seconds": 9.908
|
||||
},
|
||||
{
|
||||
"name": "upload-memory",
|
||||
"command": [
|
||||
"make",
|
||||
"test-upload-memory"
|
||||
],
|
||||
"exit_code": 0,
|
||||
"seconds": 10.33
|
||||
},
|
||||
{
|
||||
"name": "reconcile-benchmark",
|
||||
"command": [
|
||||
"make",
|
||||
"test-reconcile-benchmark"
|
||||
],
|
||||
"exit_code": 0,
|
||||
"seconds": 30.609
|
||||
},
|
||||
{
|
||||
"name": "final-smoke",
|
||||
"command": [
|
||||
"make",
|
||||
"test"
|
||||
],
|
||||
"exit_code": 0,
|
||||
"seconds": 2.676
|
||||
},
|
||||
{
|
||||
"name": "environment",
|
||||
"command": [
|
||||
"/Library/Frameworks/Python.framework/Versions/3.14/bin/python3",
|
||||
"scripts/record-environment.py"
|
||||
],
|
||||
"exit_code": 0,
|
||||
"seconds": 1.082
|
||||
}
|
||||
],
|
||||
"complete": true
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
python3 student-tests/attachment_resilience.py --mode s3-outage --base-url "http://localhost:8080"
|
||||
PASS: S3 outage gives 503 for readiness, download and upload; liveness stays 200
|
||||
PASS: original available and new upload accepted after S3 restart/bootstrap
|
||||
@@ -0,0 +1,2 @@
|
||||
python3 student-tests/s3_permissions.py --base-url "http://localhost:8080"
|
||||
PASS: API identity cannot create buckets; maintenance identity has separate admin access
|
||||
@@ -0,0 +1,2 @@
|
||||
python3 tests/smoke.py --base-url "http://localhost:8080"
|
||||
PASS: lab4 public API scenario; infrastructure and grading evidence remain separate.
|
||||
@@ -0,0 +1,2 @@
|
||||
python3 student-tests/attachment_resilience.py --mode failover --base-url "http://localhost:8080"
|
||||
PASS: uploaded via api-b; stopped that container; original downloaded through another replica
|
||||
@@ -0,0 +1,2 @@
|
||||
uv run python student-tests/upload_memory.py --base-url "http://localhost:8080"
|
||||
{"uploads": 10, "file_bytes": 5242880, "concurrency": 10, "api_upload_concurrency_limit": 1, "elapsed_seconds": 7.319, "baseline_memory_bytes": {"55cc3bd6323e": 82366464, "1af56e498842": 77262848}, "peak_memory_bytes": {"55cc3bd6323e": 95637504, "1af56e498842": 95907840}, "peak_growth_bytes": {"55cc3bd6323e": 13271040, "1af56e498842": 18644992}, "samples": 29, "sample_intervals_seconds": [0.251, 0.231, 0.246, 0.249, 0.256, 0.252, 0.262, 0.251, 0.232, 0.248, 0.26, 0.248, 0.261, 0.254, 0.262, 0.254, 0.267, 0.248, 0.271, 0.241, 0.236, 0.269, 0.227, 0.256, 0.26, 0.265, 0.271, 0.252], "method": "cgroup memory.current via Docker; 0.1s pause AFTER each poll, actual intervals include Docker latency; ten clients start at a barrier and send chunked 512 KiB blocks every 0.5s. Peak is sampled, not continuous."}
|
||||
@@ -0,0 +1,3 @@
|
||||
Container mtusi2026lab4-s3-init-run-459a847a8091 Creating
|
||||
Container mtusi2026lab4-s3-init-run-459a847a8091 Created
|
||||
PASS: private S3 bucket ready
|
||||
@@ -0,0 +1,4 @@
|
||||
.venv/bin/python scripts/check_contract.py
|
||||
PASS: offline skeleton structure, local refs and Python syntax; application NOT tested.
|
||||
.venv/bin/python scripts/validate_openapi.py
|
||||
PASS: full OpenAPI 3.1 and JSON Schema validation; application NOT tested.
|
||||
@@ -0,0 +1,114 @@
|
||||
{
|
||||
"recorded_at_utc": "2026-10-22T09:09:59.977765+00:00",
|
||||
"base_commit": "483d7eecb38eb4addc99143ad718417dd00582f8",
|
||||
"branch": "solution/BVT2301-Kozyrev",
|
||||
"note": "Results apply to this working tree, not only the base commit. Functional tests; no load benchmark.",
|
||||
"host": "macOS-26.1-arm64-arm-64bit-Mach-O",
|
||||
"docker": {
|
||||
"server": "29.8.0",
|
||||
"cpus": 10,
|
||||
"memory_bytes": 10416644096
|
||||
},
|
||||
"compose_version": "5.5.1",
|
||||
"sources_sha256": {
|
||||
"Dockerfile": "efede941e2ccf21cd1e70ebbf8af7647209bd030b2962f9446bee497a2ed6a8c",
|
||||
"Makefile": "2d8be77ed5368450e46a2ef2d67161e245bfaf3a941fd729dbc36012f241bc71",
|
||||
"compose.yaml": "b239915436be84c7b1000346669ae9a10c89e83c55555a5e9eac0e20828f6fb6",
|
||||
"infra/README.md": "0e804fa51debba4c38d3cc84abf4704897665e0335b272060363f03aadd6354f",
|
||||
"infra/filer.toml": "ae3c01bf7708f5d4a319fdb454f753be0f137fe7c31269f1c413cbccc860f5c7",
|
||||
"infra/haproxy.cfg": "23c9b869170633e3c6a8c41bbd3f1102bc97bf213e0d7cfed9d461af91216fd3",
|
||||
"migrations/001_initial.sql": "062e58f5535d1ab6cd89d2347479a2a6b08a09e04665f7428ce41f89b39a19d1",
|
||||
"migrations/002_history_cache_version.sql": "826c8243bc148caaa7339070826a7c2928073315a40dba7fa5a3d7421d980a4d",
|
||||
"migrations/003_idempotency.sql": "d650ea7c1379928a013e035977a77026d2b8b09ad5b2ea97eecb545e7450353a",
|
||||
"migrations/004_attachments.sql": "d760453ba130c94c403f5b04222649fc131ab4d091edd0267ede901fdf82a79e",
|
||||
"pyproject.toml": "d3962edc7a683a62c915c8edec91e85c647c8ae6fe6432603e30b595bd6c3804",
|
||||
"scripts/audit.py": "5c695c70058b24e975ceca310b2bdc879858081e5ce82b444ea9eab6b9c0d2ed",
|
||||
"scripts/check_contract.py": "7c4402c2a6ab80d3b4676e1866d6ecc87b6daea14c080bcb9be9a7e8b959d671",
|
||||
"scripts/init-secrets.py": "01232befe48b69933b5c6b7e4f29cb19a777030ffab00accc7999afb6c082cef",
|
||||
"scripts/record-environment.py": "716fa7b8edd05d7ab6781fc346338b2254f82186953c6dbf525785c723eee4a1",
|
||||
"scripts/restart.example.sh": "0328246ba75defbced992104e986fde973f63e3830d83251eced5953263e944b",
|
||||
"scripts/restart.sh": "a2710fc04976b28d0da4a8cd68bf2cc28735d01ec321ec95861f855900f9a42b",
|
||||
"scripts/stop-one.example.sh": "1bcf34394520b89d95b7605ec56675be799eea920e83cfbba306d5dc0a6d9811",
|
||||
"scripts/stop-one.sh": "c69fdb1891e0c49f41d3892f2d108ecd38b2f59d505c8fe991023bb5c9b08a5e",
|
||||
"scripts/validate_openapi.py": "4e981acbfc10dac58817bf922d5896e996798551fedc1b2385130e1cddb13d54",
|
||||
"scripts/verify-persistence.py": "6c366bf4d85802bcffe65ae3d45d00736b184033313dabb60b80e1270d8874f1",
|
||||
"src/__init__.py": "01ba4719c80b6fe911b091a7c05124b64eeece964e09c058ef8f9805daca546b",
|
||||
"src/attachments.py": "11cc27c6687b7e54321f1224f74fa0f9f4bab47eb5e2c68db28d2bc9e9659549",
|
||||
"src/bootstrap_s3.py": "2c43f5540e63f004a88e08961a72293546fbc5210f46bc719b90b9f5c0f3f9bd",
|
||||
"src/config.py": "62e214ceef5fcc24be11d23500de0fdaf6cf5efed1d913cdda0921fd34b088c3",
|
||||
"src/cursor.py": "a9192f2445042b8d4ddac57031718ef558990a52eb2922827074479b7f686775",
|
||||
"src/errors.py": "07f8860b45cadd242d0d9f268c4b806e35353f33b11bbde0ab3d50acda86a80a",
|
||||
"src/main.py": "6980cdbb09c3b356ff870ee7fc972d85e835c58228d3c0ea27de8a668dc41ece",
|
||||
"src/migrate.py": "1d164c8921df2b5369e30b1f8936c2b71858c5279070f0fd593f62f66e1f0b7d",
|
||||
"src/models.py": "b94e6b26559afc5fd90f58d34d906c77bf4b4a78c716ac552358795496ad1d1b",
|
||||
"src/reconcile.py": "83ecb6c83df77a9b5edc9f3e34d9cf54d39400076fec6bc00ee2648f6f393659",
|
||||
"src/routes.py": "3c21149a30ea7c2f695547c42133dcebcfbacbd6544bcb73c353be46fa35a2e6",
|
||||
"src/storage/__init__.py": "05ef66318c4c436eaafc493072640817219ab37bce464a265a2306233389064a",
|
||||
"src/storage/postgres.py": "a1009fc646c570ff181c05a00771c95a40896e0afa034eb5d8cf4d66952ca1a0",
|
||||
"src/storage/s3.py": "0779e6131c699055a1cff74e62addf207476819252e9a7aaf46c77af6d9044e6",
|
||||
"student-tests/attachment_resilience.py": "8a4ad367263a5d5a597fcd4a2a657c80946d19a3bbedeebdfffbf75f45531e5d",
|
||||
"student-tests/attachments.py": "a948fabfe83b73eb8e494c80fb9d1f2a949e2a95b7a21809a05975d65d68fc15",
|
||||
"student-tests/idempotency_concurrency.py": "db5d139009e4660ac1801af45d10e24665aa81cba737731e527c0f5b4152231e",
|
||||
"student-tests/readiness_failover.py": "0ef8355d85be66597d7d44eb7308dcb58c6c9a174d18f360b2d6d22fdcfbed14",
|
||||
"student-tests/readiness_unavailable.py": "46e3f680a3ff9cb79e95568004d97f1752dbdcd88fd4b5f160a9cc38af65a237",
|
||||
"student-tests/reconcile.py": "9c82be28eb5a41b38c9ddd63dbf65d3edc238ca09ffa4612fc4b679d64487173",
|
||||
"student-tests/reconcile_audit.py": "1bcca4da1030901e45c1369672c8363f9a5b08513c0270dc8a6f73b1f0b74221",
|
||||
"student-tests/reconcile_benchmark.py": "9ae60097cb70e63baf5653559e727e02da246827a256e02580f03b5d47e1ca15",
|
||||
"student-tests/review_regressions.py": "de58f63b2c794c2775247ddd3fccc523870ccbe673ffa404fdd566274d1d41de",
|
||||
"student-tests/s3_permissions.py": "f265a64f900952db79d545e6c058a7605870c2843ed2298f5c68ad4a177663ff",
|
||||
"student-tests/session_expiry.py": "ba8ead4356e4d12c4047ac2b5704d3d3342f71c37b3c13f65a0a9d7c37186ad6",
|
||||
"student-tests/upload_memory.py": "ed6c013b9e29a826191e1ca904e0546449f0e6ed9ecddbf5aa256d0768f64604",
|
||||
"uv.lock": "fdbeb5ba0c5eedced1a6e5b62c6a57b2d22f293cf77b9487a806c6e1a8b992a0"
|
||||
},
|
||||
"services": {
|
||||
"postgres": {
|
||||
"image": "postgres:17.6-alpine",
|
||||
"image_id": "sha256:ef257d85f76e48da1c64832459b59fcaba1a4dac97bf5d7450c77753542eee94",
|
||||
"state": "running",
|
||||
"health": "healthy",
|
||||
"memory_limit_bytes": 536870912,
|
||||
"nano_cpus_limit": 750000000,
|
||||
"volumes": [
|
||||
"mtusi2026lab4_postgres_data"
|
||||
]
|
||||
},
|
||||
"s3": {
|
||||
"image": "chrislusf/seaweedfs:4.17@sha256:186de7ef977a20343ee9a5544073f081976a29e2d29ecf8379891e7bf177fbe9",
|
||||
"image_id": "sha256:186de7ef977a20343ee9a5544073f081976a29e2d29ecf8379891e7bf177fbe9",
|
||||
"state": "running",
|
||||
"health": "healthy",
|
||||
"memory_limit_bytes": 536870912,
|
||||
"nano_cpus_limit": 1000000000,
|
||||
"volumes": [
|
||||
"mtusi2026lab4_s3_data"
|
||||
]
|
||||
},
|
||||
"api-a": {
|
||||
"image": "mtusi2026lab4-api-a",
|
||||
"image_id": "sha256:c658fea891d5262b78c3b417f6417737bd7dd2d204cd3b354bfbb652e0918707",
|
||||
"state": "running",
|
||||
"health": "healthy",
|
||||
"memory_limit_bytes": 536870912,
|
||||
"nano_cpus_limit": 500000000,
|
||||
"volumes": []
|
||||
},
|
||||
"api-b": {
|
||||
"image": "mtusi2026lab4-api-b",
|
||||
"image_id": "sha256:5f72ab070787d35e2f911f49b33a43da0a0f8148cb3737e0a9285846e308523e",
|
||||
"state": "running",
|
||||
"health": "healthy",
|
||||
"memory_limit_bytes": 536870912,
|
||||
"nano_cpus_limit": 500000000,
|
||||
"volumes": []
|
||||
},
|
||||
"load_balancer": {
|
||||
"image": "haproxy:3.0.11-alpine",
|
||||
"image_id": "sha256:e49b7beb96f4dba79f9a671515b469a6e516a2b88ff0681a820b184bba1effbd",
|
||||
"state": "running",
|
||||
"health": "healthy",
|
||||
"memory_limit_bytes": 134217728,
|
||||
"nano_cpus_limit": 250000000,
|
||||
"volumes": []
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,4 @@
|
||||
python3 tests/resilience.py --mode failover --action-script "scripts/stop-one.sh" --base-url "http://localhost:8080"
|
||||
Executing explicit failover hook; hook output suppressed to avoid leaking secrets.
|
||||
{"observed_instances_before": 2, "successful_writes": 93, "failed_attempts": 2, "first_recovery_seconds": 2.562}
|
||||
PASS: failover preserved confirmed data and existing session. Hook scope needs operator evidence.
|
||||
@@ -0,0 +1,4 @@
|
||||
python3 tests/resilience.py --mode failover --action-script "scripts/stop-one.sh" --base-url "http://localhost:8080"
|
||||
Executing explicit failover hook; hook output suppressed to avoid leaking secrets.
|
||||
{"observed_instances_before": 2, "successful_writes": 111, "failed_attempts": 1, "first_recovery_seconds": 2.791}
|
||||
PASS: failover preserved confirmed data and existing session. Hook scope needs operator evidence.
|
||||
@@ -0,0 +1,2 @@
|
||||
PASS: concurrent idempotency through load balancer
|
||||
PASS: non-ASCII Bearer returns 401/challenge; malformed JSON returns contract Error/400
|
||||
@@ -0,0 +1,5 @@
|
||||
Before: {"api-a": {"container": "fd7ade45cc98", "started_at": "2026-10-22T08:24:41.206791297Z"}, "api-b": {"container": "1bcbfe033cad", "started_at": "2026-10-22T08:24:41.125348256Z"}, "load_balancer": {"container": "3e69e9c37346", "started_at": "2026-10-22T08:24:41.017094297Z"}, "postgres": {"container": "b756a119c924", "started_at": "2026-10-22T08:24:32.576392335Z"}, "s3": {"container": "fe8f16b7a24d", "started_at": "2026-10-22T08:25:56.983675472Z"}}
|
||||
Executing explicit persistence hook; hook output suppressed to avoid leaking secrets.
|
||||
PASS: persistence preserved confirmed data and existing session. Hook scope needs operator evidence.
|
||||
After: {"api-a": {"container": "fd7ade45cc98", "started_at": "2026-10-22T08:29:52.364601219Z"}, "api-b": {"container": "1bcbfe033cad", "started_at": "2026-10-22T08:29:52.274115094Z"}, "load_balancer": {"container": "3e69e9c37346", "started_at": "2026-10-22T08:29:52.231563844Z"}, "postgres": {"container": "b756a119c924", "started_at": "2026-10-22T08:29:42.97697609Z"}, "s3": {"container": "fe8f16b7a24d", "started_at": "2026-10-22T08:29:46.000691966Z"}}
|
||||
PASS: PostgreSQL, S3, both API replicas and LB actually restarted; volumes preserved
|
||||
@@ -0,0 +1,5 @@
|
||||
Before: {"api-a": {"container": "eca67c29fa27", "started_at": "2026-10-20T14:17:13.97672451Z"}, "api-b": {"container": "71c5a224f05f", "started_at": "2026-10-20T14:19:07.971967673Z"}, "load_balancer": {"container": "3e69e9c37346", "started_at": "2026-10-20T14:17:19.597909846Z"}, "postgres": {"container": "b756a119c924", "started_at": "2026-10-20T14:17:06.843762048Z"}, "s3": {"container": "59fd3a3bca31", "started_at": "2026-10-20T14:19:38.783873424Z"}}
|
||||
Executing explicit persistence hook; hook output suppressed to avoid leaking secrets.
|
||||
PASS: persistence preserved confirmed data and existing session. Hook scope needs operator evidence.
|
||||
After: {"api-a": {"container": "eca67c29fa27", "started_at": "2026-10-20T14:20:18.95842697Z"}, "api-b": {"container": "71c5a224f05f", "started_at": "2026-10-20T14:20:18.82218322Z"}, "load_balancer": {"container": "3e69e9c37346", "started_at": "2026-10-20T14:20:18.598004429Z"}, "postgres": {"container": "b756a119c924", "started_at": "2026-10-20T14:20:10.227233258Z"}, "s3": {"container": "59fd3a3bca31", "started_at": "2026-10-20T14:20:13.232762718Z"}}
|
||||
PASS: PostgreSQL, S3, both API replicas and LB actually restarted; volumes preserved
|
||||
@@ -0,0 +1 @@
|
||||
PASS: anonymous S3 GET returns 403 for an existing object
|
||||
@@ -0,0 +1,2 @@
|
||||
{"method": "three dry-run inventories per controlled size", "results": [{"added_unreferenced_objects": 32, "median_seconds": 0.299804, "metadata_rows_scanned": 87, "runs": 3, "s3_list_pages": 1, "s3_objects_scanned": 119, "seconds": [0.299804, 0.20479, 0.321822]}, {"added_unreferenced_objects": 128, "median_seconds": 0.301204, "metadata_rows_scanned": 87, "runs": 3, "s3_list_pages": 1, "s3_objects_scanned": 215, "seconds": [0.311197, 0.301204, 0.220673]}]}
|
||||
PASS: reconciler cost measured for 32 and 128 added S3 objects; fixtures removed
|
||||
@@ -0,0 +1,31 @@
|
||||
Container mtusi2026lab4-s3-init-run-a56a6944b69f Creating
|
||||
Container mtusi2026lab4-s3-init-run-a56a6944b69f Created
|
||||
Container mtusi2026lab4-reconcile-run-2f379f07becf Creating
|
||||
Container mtusi2026lab4-reconcile-run-2f379f07becf Created
|
||||
Container mtusi2026lab4-reconcile-run-32de115488fc Creating
|
||||
Container mtusi2026lab4-reconcile-run-32de115488fc Created
|
||||
Container mtusi2026lab4-reconcile-run-8824578f5ed8 Creating
|
||||
Container mtusi2026lab4-reconcile-run-8824578f5ed8 Created
|
||||
Container mtusi2026lab4-s3-init-run-849f50d3d583 Creating
|
||||
Container mtusi2026lab4-s3-init-run-849f50d3d583 Created
|
||||
Container mtusi2026lab4-reconcile-run-cd1eb67e6a5f Creating
|
||||
Container mtusi2026lab4-reconcile-run-cd1eb67e6a5f Created
|
||||
Container mtusi2026lab4-s3-init-run-a50b80f3ae78 Creating
|
||||
Container mtusi2026lab4-s3-init-run-a50b80f3ae78 Created
|
||||
PASS: S3-side missing object, dry-run, grace period and idempotent orphan repair
|
||||
Container mtusi2026lab4-api-a-1 Recreate
|
||||
Container mtusi2026lab4-api-a-1 Recreated
|
||||
Container mtusi2026lab4-api-a-1 Starting
|
||||
Container mtusi2026lab4-api-a-1 Started
|
||||
Container mtusi2026lab4-api-a-1 Running
|
||||
Container mtusi2026lab4-api-a-1 Waiting
|
||||
Container mtusi2026lab4-api-a-1 Healthy
|
||||
Container mtusi2026lab4-reconcile-run-1c72990b1ddc Creating
|
||||
Container mtusi2026lab4-reconcile-run-1c72990b1ddc Created
|
||||
Container mtusi2026lab4-reconcile-run-2e902a56554d Creating
|
||||
Container mtusi2026lab4-reconcile-run-2e902a56554d Created
|
||||
PASS: PostgreSQL-side post-PUT/pre-DB failure is repaired without deleting references
|
||||
Container mtusi2026lab4-api-a-1 Recreate
|
||||
Container mtusi2026lab4-api-a-1 Recreated
|
||||
Container mtusi2026lab4-api-a-1 Starting
|
||||
Container mtusi2026lab4-api-a-1 Started
|
||||
@@ -0,0 +1,2 @@
|
||||
PASS: S3 outage gives 503 for readiness, download and upload; liveness stays 200
|
||||
PASS: original available again after S3 restart
|
||||
@@ -0,0 +1 @@
|
||||
PASS: API identity cannot create buckets; maintenance identity has separate admin access
|
||||
@@ -0,0 +1,2 @@
|
||||
python3 tests/smoke.py --base-url "http://localhost:8080"
|
||||
PASS: lab4 public API scenario; infrastructure and grading evidence remain separate.
|
||||
@@ -0,0 +1,2 @@
|
||||
python3 tests/smoke.py --base-url "http://localhost:8080"
|
||||
PASS: lab4 public API scenario; infrastructure and grading evidence remain separate.
|
||||
@@ -0,0 +1,51 @@
|
||||
{
|
||||
"uploads": 10,
|
||||
"file_bytes": 5242880,
|
||||
"concurrency": 10,
|
||||
"api_upload_concurrency_limit": 1,
|
||||
"elapsed_seconds": 7.319,
|
||||
"baseline_memory_bytes": {
|
||||
"55cc3bd6323e": 82366464,
|
||||
"1af56e498842": 77262848
|
||||
},
|
||||
"peak_memory_bytes": {
|
||||
"55cc3bd6323e": 95637504,
|
||||
"1af56e498842": 95907840
|
||||
},
|
||||
"peak_growth_bytes": {
|
||||
"55cc3bd6323e": 13271040,
|
||||
"1af56e498842": 18644992
|
||||
},
|
||||
"samples": 29,
|
||||
"sample_intervals_seconds": [
|
||||
0.251,
|
||||
0.231,
|
||||
0.246,
|
||||
0.249,
|
||||
0.256,
|
||||
0.252,
|
||||
0.262,
|
||||
0.251,
|
||||
0.232,
|
||||
0.248,
|
||||
0.26,
|
||||
0.248,
|
||||
0.261,
|
||||
0.254,
|
||||
0.262,
|
||||
0.254,
|
||||
0.267,
|
||||
0.248,
|
||||
0.271,
|
||||
0.241,
|
||||
0.236,
|
||||
0.269,
|
||||
0.227,
|
||||
0.256,
|
||||
0.26,
|
||||
0.265,
|
||||
0.271,
|
||||
0.252
|
||||
],
|
||||
"method": "cgroup memory.current via Docker; 0.1s pause AFTER each poll, actual intervals include Docker latency; ten clients start at a barrier and send chunked 512 KiB blocks every 0.5s. Peak is sampled, not continuous."
|
||||
}
|
||||
@@ -0,0 +1,2 @@
|
||||
uv run python student-tests/upload_memory.py --base-url "http://localhost:8080"
|
||||
{"uploads": 10, "file_bytes": 5242880, "concurrency": 10, "api_upload_concurrency_limit": 1, "elapsed_seconds": 5.529, "baseline_memory_bytes": {"7b09ecf19049": 84668416, "1bcbfe033cad": 86630400}, "peak_memory_bytes": {"7b09ecf19049": 105254912, "1bcbfe033cad": 101470208}, "peak_growth_bytes": {"7b09ecf19049": 20586496, "1bcbfe033cad": 14839808}, "samples": 22, "method": "cgroup memory.current sampled through Docker every 0.1 seconds while clients send chunked 512 KiB blocks every 0.5 seconds; peak is not a continuous profiler."}
|
||||
@@ -0,0 +1,3 @@
|
||||
[leveldb2]
|
||||
enabled = true
|
||||
dir = "/data/filer"
|
||||
@@ -0,0 +1,18 @@
|
||||
CREATE TABLE attachments (
|
||||
id uuid PRIMARY KEY,
|
||||
chat_id uuid NOT NULL REFERENCES chats(id),
|
||||
owner_id uuid NOT NULL REFERENCES users(id),
|
||||
filename varchar(255) NOT NULL,
|
||||
content_type text NOT NULL CHECK (content_type IN ('image/png', 'image/jpeg')),
|
||||
size_bytes integer NOT NULL CHECK (size_bytes BETWEEN 1 AND 10485760),
|
||||
sha256 char(64) NOT NULL,
|
||||
object_key text NOT NULL UNIQUE,
|
||||
created_at timestamptz NOT NULL DEFAULT now(),
|
||||
updated_at timestamptz NOT NULL DEFAULT now(),
|
||||
UNIQUE (id, chat_id)
|
||||
);
|
||||
ALTER TABLE messages DROP CONSTRAINT messages_text_check;
|
||||
ALTER TABLE messages ADD COLUMN attachment_ids uuid[] NOT NULL DEFAULT '{}';
|
||||
ALTER TABLE messages ADD CONSTRAINT messages_content_check
|
||||
CHECK (char_length(btrim(text)) > 0 OR cardinality(attachment_ids) > 0);
|
||||
CREATE INDEX attachments_chat_idx ON attachments(chat_id);
|
||||
@@ -7,6 +7,8 @@ requires-python = ">=3.12"
|
||||
dependencies = [
|
||||
"argon2-cffi==25.1.0",
|
||||
"asyncpg==0.31.0",
|
||||
"boto3==1.43.115",
|
||||
"fastapi==0.141.1",
|
||||
"pillow==13.0.0",
|
||||
"uvicorn==0.40.0",
|
||||
]
|
||||
|
||||
@@ -0,0 +1,70 @@
|
||||
#!/usr/bin/env python3
|
||||
"""Sequential lab3-5 verification; capture actual output and exit status, fail fast."""
|
||||
from datetime import datetime, timezone
|
||||
import argparse
|
||||
import json
|
||||
from pathlib import Path
|
||||
import subprocess
|
||||
import sys
|
||||
import time
|
||||
|
||||
ROOT = Path(__file__).resolve().parents[1]
|
||||
DESTINATION = ROOT / "evidence/audit"
|
||||
CHECKS = [
|
||||
("contracts", ["make", "check", "validate", "PYTHON=.venv/bin/python"]),
|
||||
("compose", ["docker", "compose", "config", "--quiet"]),
|
||||
("smoke", ["make", "test"]),
|
||||
("attachments", ["make", "test-attachments"]),
|
||||
("idempotency", [sys.executable, "student-tests/idempotency_concurrency.py"]),
|
||||
("regressions", [sys.executable, "student-tests/review_regressions.py"]),
|
||||
("private-bucket", ["make", "test-private"]),
|
||||
("s3-permissions", ["make", "test-s3-permissions"]),
|
||||
("bootstrap", ["docker", "compose", "run", "--rm", "--no-deps", "s3-init"]),
|
||||
("upload-failover", ["make", "test-upload-failover"]),
|
||||
("public-failover", ["make", "test-failover", "ACTION_SCRIPT=scripts/stop-one.sh"]),
|
||||
("restore-replicas", ["docker", "compose", "up", "-d", "--wait", "api-a", "api-b", "load_balancer"]),
|
||||
("s3-outage", ["make", "test-s3-outage"]),
|
||||
("persistence", [sys.executable, "scripts/verify-persistence.py"]),
|
||||
("reconcile", ["make", "test-reconcile"]),
|
||||
("reconcile-audit", ["make", "test-reconcile-audit"]),
|
||||
("upload-memory", ["make", "test-upload-memory"]),
|
||||
("reconcile-benchmark", ["make", "test-reconcile-benchmark"]),
|
||||
("final-smoke", ["make", "test"]),
|
||||
("environment", [sys.executable, "scripts/record-environment.py"]),
|
||||
]
|
||||
|
||||
|
||||
def main():
|
||||
parser = argparse.ArgumentParser(description=__doc__)
|
||||
parser.add_argument('--resume-from', choices=[name for name, _ in CHECKS])
|
||||
args = parser.parse_args()
|
||||
DESTINATION.mkdir(parents=True, exist_ok=True)
|
||||
results = []
|
||||
checks = CHECKS
|
||||
if args.resume_from:
|
||||
offset = [name for name, _ in CHECKS].index(args.resume_from)
|
||||
previous = json.loads((DESTINATION / 'results.json').read_text())['checks']
|
||||
results = previous[:offset]
|
||||
if [item['name'] for item in results] != [name for name, _ in CHECKS[:offset]] or any(item['exit_code'] for item in results):
|
||||
parser.error('resume requires successful evidence for every earlier step')
|
||||
checks = CHECKS[offset:]
|
||||
for name, command in checks:
|
||||
print(f"RUN {name}", flush=True)
|
||||
started = time.monotonic()
|
||||
with (DESTINATION / f"{name}.txt").open("w") as stream:
|
||||
result = subprocess.run(command, cwd=ROOT, stdout=stream, stderr=subprocess.STDOUT)
|
||||
results.append({"name": name, "command": command, "exit_code": result.returncode,
|
||||
"seconds": round(time.monotonic() - started, 3)})
|
||||
(DESTINATION / "results.json").write_text(json.dumps({
|
||||
"recorded_at_utc": datetime.now(timezone.utc).isoformat(),
|
||||
"checks": results, "complete": len(results) == len(CHECKS),
|
||||
}, indent=2) + "\n")
|
||||
print(f"{'PASS' if result.returncode == 0 else 'FAIL'} {name}: exit={result.returncode}", flush=True)
|
||||
if result.returncode:
|
||||
print((DESTINATION / f"{name}.txt").read_text()[-8000:], flush=True)
|
||||
return result.returncode
|
||||
return 0
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
raise SystemExit(main())
|
||||
@@ -0,0 +1,36 @@
|
||||
#!/usr/bin/env python3
|
||||
"""Create local credentials without printing or overwriting existing values."""
|
||||
import json
|
||||
from pathlib import Path
|
||||
import secrets
|
||||
|
||||
root = Path(__file__).resolve().parents[1] / "secrets"
|
||||
root.mkdir(mode=0o700, exist_ok=True)
|
||||
|
||||
|
||||
def write(name, value):
|
||||
path = root / name
|
||||
if path.exists():
|
||||
return path.read_text().strip()
|
||||
with path.open("x") as stream:
|
||||
path.chmod(0o600)
|
||||
stream.write(value + "\n")
|
||||
return value
|
||||
|
||||
|
||||
password = write("postgres_password", secrets.token_hex(32))
|
||||
write("database_url", f"postgresql://messenger:{password}@postgres:5432/messenger")
|
||||
write("cursor_secret", secrets.token_hex(32))
|
||||
admin_key = write("s3_admin_key", secrets.token_hex(16))
|
||||
admin_secret = write("s3_admin_secret", secrets.token_hex(32))
|
||||
app_key = write("s3_access_key_id", secrets.token_hex(16))
|
||||
app_secret = write("s3_secret_access_key", secrets.token_hex(32))
|
||||
config_path = root / "s3.json"
|
||||
config_path.write_text(json.dumps({"identities": [
|
||||
{"name": "bootstrap", "credentials": [{"accessKey": admin_key, "secretKey": admin_secret}],
|
||||
"actions": ["Admin", "Read", "Write", "List", "Tagging"]},
|
||||
{"name": "api", "credentials": [{"accessKey": app_key, "secretKey": app_secret}],
|
||||
"actions": ["Read:messenger-attachments", "Write:messenger-attachments", "List:messenger-attachments"]},
|
||||
]}, indent=2) + "\n")
|
||||
config_path.chmod(0o600)
|
||||
print("Local secrets ready; existing values preserved.")
|
||||
@@ -0,0 +1,44 @@
|
||||
#!/usr/bin/env python3
|
||||
"""Sanitized environment and source fingerprint for local test evidence."""
|
||||
from datetime import datetime, timezone
|
||||
from hashlib import sha256
|
||||
import json
|
||||
from pathlib import Path
|
||||
import platform
|
||||
import subprocess
|
||||
|
||||
root = Path(__file__).resolve().parents[1]
|
||||
|
||||
|
||||
def command(*args):
|
||||
return subprocess.check_output(args, cwd=root, text=True).strip()
|
||||
|
||||
|
||||
paths = [root / name for name in ('Dockerfile', 'compose.yaml', 'pyproject.toml', 'uv.lock', 'Makefile')]
|
||||
for directory in ('src', 'migrations', 'infra', 'scripts', 'student-tests'):
|
||||
paths.extend(path for path in (root / directory).rglob('*')
|
||||
if path.is_file() and '__pycache__' not in path.parts)
|
||||
report = {
|
||||
'recorded_at_utc': datetime.now(timezone.utc).isoformat(),
|
||||
'base_commit': command('git', 'rev-parse', 'HEAD'),
|
||||
'branch': command('git', 'branch', '--show-current'),
|
||||
'note': 'Results apply to this working tree, not only the base commit. Functional tests; no load benchmark.',
|
||||
'host': platform.platform(),
|
||||
'docker': json.loads(command('docker', 'info', '--format',
|
||||
'{"server":"{{.ServerVersion}}","cpus":{{.NCPU}},"memory_bytes":{{.MemTotal}}}')),
|
||||
'compose_version': command('docker', 'compose', 'version', '--short'),
|
||||
'sources_sha256': {str(path.relative_to(root)): sha256(path.read_bytes()).hexdigest() for path in sorted(paths)},
|
||||
'services': {},
|
||||
}
|
||||
for service in ('postgres', 's3', 'api-a', 'api-b', 'load_balancer'):
|
||||
container = command('docker', 'compose', 'ps', '-q', service)
|
||||
info = json.loads(command('docker', 'inspect', container))[0]
|
||||
report['services'][service] = {
|
||||
'image': info['Config']['Image'], 'image_id': info['Image'],
|
||||
'state': info['State']['Status'], 'health': info['State'].get('Health', {}).get('Status'),
|
||||
'memory_limit_bytes': info['HostConfig']['Memory'],
|
||||
'nano_cpus_limit': info['HostConfig']['NanoCpus'],
|
||||
'volumes': [mount['Name'] for mount in info['Mounts'] if mount['Type'] == 'volume'],
|
||||
}
|
||||
(root / 'evidence/environment.json').write_text(json.dumps(report, ensure_ascii=False, indent=2) + '\n')
|
||||
print('PASS: sanitized environment and source hashes saved')
|
||||
+3
-2
@@ -1,7 +1,8 @@
|
||||
#!/bin/sh
|
||||
set -eu
|
||||
cd "$(dirname "$0")/.."
|
||||
docker compose restart postgres
|
||||
docker compose up -d --wait postgres
|
||||
docker compose restart postgres s3
|
||||
docker compose up -d --wait postgres s3
|
||||
docker compose run --rm --no-deps s3-init
|
||||
docker compose restart api-a api-b load_balancer
|
||||
docker compose up -d --wait api-a api-b load_balancer
|
||||
|
||||
@@ -0,0 +1,27 @@
|
||||
#!/usr/bin/env python3
|
||||
"""Public persistence test plus proof of actual container restarts."""
|
||||
import json
|
||||
from pathlib import Path
|
||||
import subprocess
|
||||
import sys
|
||||
|
||||
ROOT = Path(__file__).resolve().parents[1]
|
||||
|
||||
|
||||
def snapshot():
|
||||
result = {}
|
||||
for service in ('postgres', 's3', 'api-a', 'api-b', 'load_balancer'):
|
||||
container = subprocess.check_output(['docker', 'compose', 'ps', '-q', service], cwd=ROOT, text=True).strip()
|
||||
started = subprocess.check_output(['docker', 'inspect', '--format', '{{.State.StartedAt}}', container], text=True).strip()
|
||||
result[service] = {'container': container[:12], 'started_at': started}
|
||||
return result
|
||||
|
||||
|
||||
before = snapshot()
|
||||
print('Before:', json.dumps(before, sort_keys=True), flush=True)
|
||||
subprocess.run([sys.executable, 'tests/resilience.py', '--mode', 'persistence',
|
||||
'--action-script', 'scripts/restart.sh'], cwd=ROOT, check=True)
|
||||
after = snapshot()
|
||||
print('After:', json.dumps(after, sort_keys=True), flush=True)
|
||||
assert all(before[key]['started_at'] != after[key]['started_at'] for key in before)
|
||||
print('PASS: PostgreSQL, S3, both API replicas and LB actually restarted; volumes preserved')
|
||||
@@ -0,0 +1,116 @@
|
||||
import asyncio
|
||||
from hashlib import sha256
|
||||
import os
|
||||
from tempfile import TemporaryFile
|
||||
import unicodedata
|
||||
from uuid import UUID, uuid4
|
||||
import warnings
|
||||
|
||||
from fastapi import APIRouter, Depends, Query, Request, Response
|
||||
from PIL import Image, UnidentifiedImageError
|
||||
from starlette.concurrency import run_in_threadpool
|
||||
from starlette.requests import ClientDisconnect
|
||||
|
||||
from .errors import ApiError
|
||||
from .models import Attachment
|
||||
from .routes import get_current_user, get_store
|
||||
from .storage.postgres import PostgresStore
|
||||
|
||||
router = APIRouter()
|
||||
Image.MAX_IMAGE_PIXELS = 40000000
|
||||
warnings.filterwarnings("error", category=Image.DecompressionBombWarning)
|
||||
|
||||
|
||||
def inspect_image(file, content_type, max_pixels):
|
||||
try:
|
||||
file.seek(0)
|
||||
with Image.open(file, formats=("PNG", "JPEG")) as image:
|
||||
if image.width * image.height > max_pixels:
|
||||
raise ApiError(413, "payload_too_large", "Слишком много пикселей")
|
||||
actual = {"PNG": "image/png", "JPEG": "image/jpeg"}[image.format]
|
||||
if actual != content_type or getattr(image, "n_frames", 1) != 1:
|
||||
raise ApiError(415, "unsupported_media_type", "Нужен обычный PNG или JPEG")
|
||||
image.verify()
|
||||
# verify checks PNG CRC; load also catches truncated pixel streams/JPEGs.
|
||||
file.seek(0)
|
||||
with Image.open(file, formats=("PNG", "JPEG")) as image:
|
||||
image.load()
|
||||
except (Image.DecompressionBombError, Image.DecompressionBombWarning) as error:
|
||||
raise ApiError(413, "payload_too_large", "Слишком много пикселей") from error
|
||||
except (UnidentifiedImageError, OSError, ValueError, SyntaxError) as error:
|
||||
raise ApiError(415, "unsupported_media_type", "Повреждённое изображение") from error
|
||||
file.seek(0)
|
||||
|
||||
|
||||
@router.post("/api/v1/chats/{chat_id}/attachments", response_model=Attachment, status_code=201)
|
||||
async def upload(chat_id: UUID, request: Request, filename: str = Query(...),
|
||||
user: dict = Depends(get_current_user), store: PostgresStore = Depends(get_store)):
|
||||
await store.get_chat_for_member(chat_id, user["id"])
|
||||
if (not 1 <= len(filename) <= 255 or not filename.strip() or
|
||||
any(c in "/\\" or unicodedata.category(c) in {"Cc", "Cs"} for c in filename)):
|
||||
raise ApiError(400, "invalid_request", "Некорректное имя файла")
|
||||
content_type = request.headers.get("content-type", "").lower()
|
||||
if content_type not in {"image/png", "image/jpeg"}:
|
||||
raise ApiError(415, "unsupported_media_type", "Нужен PNG или JPEG")
|
||||
s3 = request.app.state.s3
|
||||
limit = s3.settings.max_bytes
|
||||
if "content-length" in request.headers:
|
||||
try:
|
||||
length = int(request.headers["content-length"])
|
||||
if length < 0:
|
||||
raise ValueError()
|
||||
except ValueError:
|
||||
raise ApiError(400, "invalid_request", "Некорректная длина") from None
|
||||
if length > limit:
|
||||
raise ApiError(413, "payload_too_large", "Файл больше лимита")
|
||||
try:
|
||||
timeout = int(os.environ.get("UPLOAD_TIMEOUT_SECONDS", "30"))
|
||||
if not 1 <= timeout <= 120:
|
||||
raise ApiError(503, "unavailable", "Некорректный лимит времени загрузки")
|
||||
async with asyncio.timeout(timeout):
|
||||
async with request.app.state.upload_slot:
|
||||
# Temporary scratch space only; deleted on every exit, never used for downloads.
|
||||
with TemporaryFile() as file:
|
||||
size = 0
|
||||
digest = sha256()
|
||||
async for chunk in request.stream():
|
||||
size += len(chunk)
|
||||
if size > limit:
|
||||
raise ApiError(413, "payload_too_large", "Файл больше лимита")
|
||||
digest.update(chunk)
|
||||
await run_in_threadpool(file.write, chunk)
|
||||
await run_in_threadpool(inspect_image, file, content_type, s3.settings.max_pixels)
|
||||
attachment_id = uuid4()
|
||||
key = f"originals/{attachment_id}"
|
||||
async with store.attachment_transaction() as connection:
|
||||
await s3.put(key, file, size, content_type)
|
||||
# Disabled by default; models a crash after PUT, before INSERT.
|
||||
if os.environ.get("UPLOAD_FAULT_AFTER_S3_PUT") == "1":
|
||||
raise ApiError(503, "unavailable", "Инъецирован отказ после S3 PUT")
|
||||
attachment = await store.create_attachment(
|
||||
attachment_id, chat_id, user["id"], filename, content_type,
|
||||
size, digest.hexdigest(), key, connection=connection,
|
||||
)
|
||||
return attachment # Transaction has committed before 201.
|
||||
except ClientDisconnect:
|
||||
raise ApiError(400, "invalid_request", "Загрузка прервана") from None
|
||||
except TimeoutError:
|
||||
raise ApiError(503, "unavailable", "Время загрузки истекло") from None
|
||||
|
||||
|
||||
@router.get("/api/v1/attachments/{attachment_id}", response_model=Attachment)
|
||||
async def metadata(attachment_id: UUID, user: dict = Depends(get_current_user),
|
||||
store: PostgresStore = Depends(get_store)):
|
||||
return await store.attachment_for_member(attachment_id, user["id"])
|
||||
|
||||
|
||||
@router.get("/api/v1/attachments/{attachment_id}/content")
|
||||
async def download(attachment_id: UUID, request: Request,
|
||||
variant: str = Query("original", pattern="^(original|thumbnail|crop|optimized)$"),
|
||||
user: dict = Depends(get_current_user), store: PostgresStore = Depends(get_store)):
|
||||
attachment = await store.attachment_for_member(attachment_id, user["id"])
|
||||
if variant != "original":
|
||||
raise ApiError(404, "not_found", "Вариант не найден")
|
||||
data = await request.app.state.s3.download(attachment)
|
||||
return Response(data, media_type=attachment["content_type"],
|
||||
headers={"X-Content-Type-Options": "nosniff", "Cache-Control": "private, no-store"})
|
||||
@@ -0,0 +1,51 @@
|
||||
"""Idempotent private bucket bootstrap; executed with separate admin credentials."""
|
||||
import time
|
||||
from uuid import uuid4
|
||||
from botocore.exceptions import BotoCoreError, ClientError
|
||||
from .storage.s3 import S3Settings, S3Store
|
||||
|
||||
|
||||
def main():
|
||||
store = S3Store(S3Settings.load())
|
||||
try:
|
||||
for attempt in range(60):
|
||||
try:
|
||||
store.client.list_buckets()
|
||||
break
|
||||
except (BotoCoreError, ClientError):
|
||||
if attempt == 59:
|
||||
raise RuntimeError("S3 startup timed out") from None
|
||||
time.sleep(1)
|
||||
bucket = store.settings.bucket
|
||||
try:
|
||||
store.client.head_bucket(Bucket=bucket)
|
||||
except ClientError as error:
|
||||
if str(error.response["Error"]["Code"]) not in {"404", "NoSuchBucket", "NotFound"}:
|
||||
raise
|
||||
store.client.create_bucket(Bucket=bucket)
|
||||
# No anonymous identity; revoke any previously configured public grants/policy.
|
||||
store.client.put_bucket_acl(Bucket=bucket, ACL="private")
|
||||
try:
|
||||
store.client.delete_bucket_policy(Bucket=bucket)
|
||||
except ClientError as error:
|
||||
if error.response["Error"]["Code"] != "NoSuchBucketPolicy":
|
||||
raise
|
||||
# The master health endpoint can become available before a volume accepts
|
||||
# writes after a restart. Verify the actual data path before APIs start.
|
||||
probe_key = f"_bootstrap/write-probe-{uuid4()}"
|
||||
for attempt in range(30):
|
||||
try:
|
||||
store.client.put_object(Bucket=bucket, Key=probe_key, Body=b"ready")
|
||||
store.client.delete_object(Bucket=bucket, Key=probe_key)
|
||||
break
|
||||
except (BotoCoreError, ClientError):
|
||||
if attempt == 29:
|
||||
raise RuntimeError("S3 write path startup timed out") from None
|
||||
time.sleep(1)
|
||||
print("PASS: private S3 bucket ready")
|
||||
finally:
|
||||
store.client.close()
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
@@ -15,6 +15,11 @@ _CONFIGURATION_KEYS = {
|
||||
"INSTANCE_ID",
|
||||
"CURSOR_SECRET",
|
||||
"CURSOR_SECRET_FILE",
|
||||
"S3_ENDPOINT", "S3_REGION", "S3_BUCKET",
|
||||
"S3_ACCESS_KEY_ID", "S3_ACCESS_KEY_ID_FILE",
|
||||
"S3_SECRET_ACCESS_KEY", "S3_SECRET_ACCESS_KEY_FILE",
|
||||
"MAX_UPLOAD_BYTES", "MAX_IMAGE_PIXELS",
|
||||
"UPLOAD_CONCURRENCY", "UPLOAD_TIMEOUT_SECONDS", "UPLOAD_FAULT_AFTER_S3_PUT",
|
||||
}
|
||||
|
||||
|
||||
|
||||
+12
-1
@@ -1,4 +1,6 @@
|
||||
import asyncio
|
||||
import logging
|
||||
import os
|
||||
import sys
|
||||
import time
|
||||
from contextlib import asynccontextmanager
|
||||
@@ -15,6 +17,8 @@ from .cursor import configure_secret
|
||||
from .models import ErrorDetails, ErrorResponse
|
||||
from .config import load_settings
|
||||
from .routes import router
|
||||
from .attachments import router as attachment_router
|
||||
from .storage.s3 import S3Settings, S3Store
|
||||
from .storage.postgres import PostgresStore
|
||||
|
||||
|
||||
@@ -41,17 +45,23 @@ async def lifespan(application: FastAPI):
|
||||
await store.connect()
|
||||
application.state.store = store
|
||||
application.state.settings = settings
|
||||
application.state.s3 = S3Store(S3Settings.load())
|
||||
concurrency = int(os.environ.get("UPLOAD_CONCURRENCY", "1"))
|
||||
if not 1 <= concurrency <= 8:
|
||||
raise ValueError("UPLOAD_CONCURRENCY must be 1..8")
|
||||
application.state.upload_slot = asyncio.Semaphore(concurrency)
|
||||
application.state.accepting_requests = True
|
||||
try:
|
||||
yield
|
||||
finally:
|
||||
application.state.accepting_requests = False
|
||||
application.state.s3.client.close()
|
||||
await store.close()
|
||||
|
||||
|
||||
app = FastAPI(
|
||||
title="MTUSI Messenger",
|
||||
version="1.3.0",
|
||||
version="1.4.0",
|
||||
redoc_url=None,
|
||||
lifespan=lifespan,
|
||||
)
|
||||
@@ -144,6 +154,7 @@ async def handle_unexpected_error(request: Request, error: Exception) -> JSONRes
|
||||
|
||||
|
||||
app.include_router(router)
|
||||
app.include_router(attachment_router)
|
||||
|
||||
|
||||
def main() -> None:
|
||||
|
||||
+32
-8
@@ -1,7 +1,7 @@
|
||||
from datetime import datetime
|
||||
from uuid import UUID
|
||||
|
||||
from pydantic import BaseModel, ConfigDict, Field, field_validator
|
||||
from pydantic import BaseModel, ConfigDict, Field, field_validator, model_validator
|
||||
|
||||
class CreateUserRequest(BaseModel):
|
||||
model_config = ConfigDict(extra="forbid", strict=True)
|
||||
@@ -46,16 +46,22 @@ class ChatPageResponse(BaseModel):
|
||||
class CreateMessageRequest(BaseModel):
|
||||
model_config = ConfigDict(extra="forbid", strict=True)
|
||||
|
||||
text: str = Field(min_length=1, max_length=4000)
|
||||
text: str = Field(max_length=4000)
|
||||
attachment_ids: list[str] = Field(default_factory=list, max_length=10)
|
||||
|
||||
@field_validator("text")
|
||||
@field_validator("attachment_ids")
|
||||
@classmethod
|
||||
def text_must_not_be_whitespace(cls, value: str) -> str:
|
||||
"""Не допускает сообщение, состоящее только из пробельных символов."""
|
||||
def valid_ids(cls, values: list[str]) -> list[str]:
|
||||
normalized = [str(UUID(value)) for value in values]
|
||||
if len(normalized) != len(set(normalized)):
|
||||
raise ValueError("Повторяющиеся attachment_ids")
|
||||
return normalized
|
||||
|
||||
if not value.strip():
|
||||
raise ValueError("text не может состоять только из пробелов")
|
||||
return value
|
||||
@model_validator(mode="after")
|
||||
def has_content(self):
|
||||
if not self.text.strip() and not self.attachment_ids:
|
||||
raise ValueError("Сообщение без содержимого")
|
||||
return self
|
||||
|
||||
|
||||
class MessagePageResponse(BaseModel):
|
||||
@@ -104,6 +110,7 @@ class Message(BaseModel):
|
||||
chat_id: UUID
|
||||
sender_id: UUID
|
||||
text: str
|
||||
attachment_ids: list[UUID] = Field(default_factory=list)
|
||||
created_at: datetime
|
||||
|
||||
|
||||
@@ -114,3 +121,20 @@ class Session(BaseModel):
|
||||
token_type: str = "Bearer"
|
||||
expires_at: datetime
|
||||
user: User
|
||||
|
||||
|
||||
class Attachment(BaseModel):
|
||||
model_config = ConfigDict(extra="ignore")
|
||||
|
||||
id: UUID
|
||||
chat_id: UUID
|
||||
owner_id: UUID
|
||||
filename: str
|
||||
content_type: str
|
||||
size_bytes: int
|
||||
sha256: str
|
||||
status: str = "ready"
|
||||
variants: list = Field(default_factory=list)
|
||||
error_code: str | None = None
|
||||
created_at: datetime
|
||||
updated_at: datetime
|
||||
|
||||
@@ -0,0 +1,89 @@
|
||||
"""Safely reconcile attachment metadata and original S3 objects.
|
||||
|
||||
The command is dry-run by default. It only deletes unreferenced objects older
|
||||
than a configured grace period; missing objects are reported and never cause a
|
||||
metadata delete. That keeps a delayed PostgreSQL commit and active attachment
|
||||
records safe from a maintenance run.
|
||||
"""
|
||||
import argparse
|
||||
import asyncio
|
||||
from datetime import datetime, timedelta, timezone
|
||||
import json
|
||||
from time import perf_counter
|
||||
|
||||
from .config import load_settings
|
||||
from .storage.postgres import PostgresStore
|
||||
from .storage.s3 import S3Settings, S3Store
|
||||
|
||||
|
||||
async def run(args) -> dict:
|
||||
settings = load_settings()
|
||||
db = PostgresStore(settings.database_url)
|
||||
s3 = S3Store(S3Settings.load())
|
||||
try:
|
||||
await db.connect()
|
||||
async with db.attachment_transaction(maintenance=True):
|
||||
return await scan(args, db, s3)
|
||||
finally:
|
||||
s3.client.close()
|
||||
await db.close()
|
||||
|
||||
|
||||
async def scan(args, db, s3) -> dict:
|
||||
# Age is measured at scan start, not after a potentially slow inventory.
|
||||
cutoff = datetime.now(timezone.utc) - timedelta(seconds=args.grace_seconds)
|
||||
started = perf_counter()
|
||||
objects, s3_pages = await s3.list_with_pages("originals/")
|
||||
listed_at = perf_counter()
|
||||
metadata = await db.attachment_keys()
|
||||
metadata_at = perf_counter()
|
||||
orphan = sorted(key for key, modified in objects.items()
|
||||
if key not in metadata and modified <= cutoff)
|
||||
fresh = sorted(key for key, modified in objects.items()
|
||||
if key not in metadata and modified > cutoff)
|
||||
missing = sorted({str(attachment_id): key for key, attachment_id in metadata.items()
|
||||
if key not in objects}.items())
|
||||
deleted = []
|
||||
selected = set(args.object_key) if args.object_key else None
|
||||
if args.apply:
|
||||
for key in orphan:
|
||||
if selected is not None and key not in selected:
|
||||
continue
|
||||
await s3.delete(key)
|
||||
deleted.append(key)
|
||||
finished = perf_counter()
|
||||
return {
|
||||
"mode": "apply" if args.apply else "dry-run",
|
||||
"grace_seconds": args.grace_seconds,
|
||||
"s3_objects": len(objects),
|
||||
"metadata_rows": len(metadata),
|
||||
"orphan_candidates": orphan,
|
||||
"fresh_unreferenced": fresh,
|
||||
"missing_objects": [{"attachment_id": item[0], "object_key": item[1]} for item in missing],
|
||||
"deleted": deleted,
|
||||
"selected_keys": sorted(selected) if selected is not None else None,
|
||||
"scan_metrics": {
|
||||
"s3_list_pages": s3_pages,
|
||||
"s3_list_seconds": round(listed_at - started, 6),
|
||||
"postgres_metadata_seconds": round(metadata_at - listed_at, 6),
|
||||
"total_seconds": round(finished - started, 6),
|
||||
},
|
||||
}
|
||||
|
||||
|
||||
def main() -> None:
|
||||
parser = argparse.ArgumentParser(description=__doc__)
|
||||
parser.add_argument("--apply", action="store_true", help="delete only aged orphan objects")
|
||||
parser.add_argument("--grace-seconds", type=int, default=3600)
|
||||
parser.add_argument("--object-key", action="append", default=[],
|
||||
help="restrict apply to these exact keys; repeatable, inventory stays complete")
|
||||
args = parser.parse_args()
|
||||
if not 0 <= args.grace_seconds <= 7 * 24 * 3600:
|
||||
parser.error("--grace-seconds must be 0..604800")
|
||||
if any(not key.startswith("originals/") for key in args.object_key):
|
||||
parser.error("--object-key must start with originals/")
|
||||
print(json.dumps(asyncio.run(run(args)), ensure_ascii=False, sort_keys=True))
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
@@ -83,6 +83,7 @@ async def readiness(request: Request, store: PostgresStore = Depends(get_store))
|
||||
if not request.app.state.accepting_requests:
|
||||
raise ApiError(503, "unavailable", "API завершает работу")
|
||||
await store.ready()
|
||||
await request.app.state.s3.ready()
|
||||
return {"status": "ok"}
|
||||
|
||||
@router.post("/api/v1/users", response_model=User, status_code=201)
|
||||
@@ -164,6 +165,7 @@ async def create_message(
|
||||
payload.text,
|
||||
idempotency_key,
|
||||
request.app.state.settings.idempotency_ttl_seconds,
|
||||
[UUID(value) for value in payload.attachment_ids],
|
||||
)
|
||||
|
||||
@router.get("/api/v1/chats/{chat_id}/messages", response_model=MessagePageResponse)
|
||||
|
||||
+72
-8
@@ -1,4 +1,5 @@
|
||||
from datetime import datetime
|
||||
from contextlib import asynccontextmanager
|
||||
from hashlib import sha256
|
||||
import json
|
||||
from pathlib import Path
|
||||
@@ -15,7 +16,7 @@ from ..errors import ApiError
|
||||
ROOT = Path(__file__).resolve().parents[2]
|
||||
MIGRATIONS = ROOT / "migrations"
|
||||
PASSWORD_HASHER = PasswordHasher()
|
||||
DB_ERRORS = (asyncpg.PostgresError, asyncpg.InterfaceError, OSError)
|
||||
DB_ERRORS = (asyncpg.PostgresError, asyncpg.InterfaceError, OSError, TimeoutError)
|
||||
|
||||
|
||||
class PostgresStore:
|
||||
@@ -83,6 +84,7 @@ class PostgresStore:
|
||||
"chat_id": row["chat_id"],
|
||||
"sender_id": row["sender_id"],
|
||||
"text": row["text"],
|
||||
"attachment_ids": row["attachment_ids"],
|
||||
"created_at": row["created_at"],
|
||||
}
|
||||
|
||||
@@ -216,12 +218,17 @@ class PostgresStore:
|
||||
return [self._chat(row) for row in rows]
|
||||
|
||||
async def create_message_idempotent(
|
||||
self, chat_id: UUID, sender_id: UUID, text: str, idempotency_key: str, ttl_seconds: int
|
||||
self, chat_id: UUID, sender_id: UUID, text: str, idempotency_key: str, ttl_seconds: int, attachment_ids: list[UUID] | None = None
|
||||
) -> dict:
|
||||
"""Создаёт сообщение и фиксирует результат retry в одной транзакции."""
|
||||
path = f"/api/v1/chats/{chat_id}/messages"
|
||||
attachment_ids = attachment_ids or []
|
||||
# Preserve hashes of text-only requests already accepted by lab3.
|
||||
canonical = {"text": text}
|
||||
if attachment_ids:
|
||||
canonical["attachment_ids"] = [str(value) for value in attachment_ids]
|
||||
request_hash = sha256(
|
||||
json.dumps({"text": text}, ensure_ascii=False, separators=(",", ":"), sort_keys=True).encode("utf-8")
|
||||
json.dumps(canonical, ensure_ascii=False, separators=(",", ":"), sort_keys=True).encode("utf-8")
|
||||
).hexdigest()
|
||||
try:
|
||||
async with self.pool.acquire() as connection, connection.transaction():
|
||||
@@ -233,6 +240,13 @@ class PostgresStore:
|
||||
await connection.execute(
|
||||
"DELETE FROM idempotency_records WHERE created_at <= now() - $1 * interval '1 second'", ttl_seconds
|
||||
)
|
||||
if attachment_ids:
|
||||
count = await connection.fetchval(
|
||||
"SELECT count(*) FROM attachments WHERE chat_id = $1 AND id = ANY($2::uuid[])",
|
||||
chat_id, attachment_ids,
|
||||
)
|
||||
if count != len(attachment_ids):
|
||||
raise ApiError(404, "not_found", "Вложение не найдено")
|
||||
claimed = await connection.fetchrow(
|
||||
"INSERT INTO idempotency_records (user_id, method, path, idempotency_key, request_hash) "
|
||||
"VALUES ($1, 'POST', $2, $3, $4) ON CONFLICT DO NOTHING RETURNING message_id",
|
||||
@@ -251,15 +265,15 @@ class PostgresStore:
|
||||
if recorded["message_id"] is None:
|
||||
raise ApiError(503, "unavailable", "Не удалось получить результат идемпотентного запроса")
|
||||
row = await connection.fetchrow(
|
||||
"SELECT id, chat_id, sender_id, text, created_at FROM messages WHERE id = $1", recorded["message_id"]
|
||||
"SELECT id, chat_id, sender_id, text, attachment_ids, created_at FROM messages WHERE id = $1", recorded["message_id"]
|
||||
)
|
||||
if row is None:
|
||||
raise ApiError(503, "unavailable", "Не удалось получить сохранённое сообщение")
|
||||
return self._message(row)
|
||||
row = await connection.fetchrow(
|
||||
"INSERT INTO messages (id, chat_id, sender_id, text) VALUES ($1, $2, $3, $4) "
|
||||
"RETURNING id, chat_id, sender_id, text, created_at",
|
||||
uuid4(), chat_id, sender_id, text,
|
||||
"INSERT INTO messages (id, chat_id, sender_id, text, attachment_ids) VALUES ($1, $2, $3, $4, $5) "
|
||||
"RETURNING id, chat_id, sender_id, text, attachment_ids, created_at",
|
||||
uuid4(), chat_id, sender_id, text, attachment_ids,
|
||||
)
|
||||
await connection.execute(
|
||||
"UPDATE idempotency_records SET message_id = $1 WHERE user_id = $2 AND method = 'POST' "
|
||||
@@ -274,7 +288,7 @@ class PostgresStore:
|
||||
self, chat_id: UUID, user_id: UUID, after: tuple[datetime, UUID] | None, limit: int
|
||||
) -> list[dict]:
|
||||
await self.get_chat_for_member(chat_id, user_id)
|
||||
query = "SELECT id, chat_id, sender_id, text, created_at FROM messages WHERE chat_id = $1"
|
||||
query = "SELECT id, chat_id, sender_id, text, attachment_ids, created_at FROM messages WHERE chat_id = $1"
|
||||
args: list = [chat_id]
|
||||
if after is not None:
|
||||
query += " AND (created_at, id) > ($2, $3)"
|
||||
@@ -286,3 +300,53 @@ class PostgresStore:
|
||||
except DB_ERRORS as error:
|
||||
raise ApiError(503, "unavailable", "PostgreSQL недоступен") from error
|
||||
return [self._message(row) for row in rows]
|
||||
|
||||
|
||||
@asynccontextmanager
|
||||
async def attachment_transaction(self, *, maintenance=False):
|
||||
"""Shared writer / exclusive reconciler lock across all API replicas.
|
||||
|
||||
Writers hold the transaction from before PUT through metadata COMMIT.
|
||||
Maintenance holds the exclusive lock through inventory and deletion.
|
||||
All attachment writers must participate in this protocol.
|
||||
"""
|
||||
try:
|
||||
async with self.pool.acquire() as connection, connection.transaction():
|
||||
await connection.execute("SET LOCAL lock_timeout = '5s'")
|
||||
lock = "pg_advisory_xact_lock" if maintenance else "pg_advisory_xact_lock_shared"
|
||||
await connection.execute(f"SELECT {lock}(41004, 1)")
|
||||
yield connection
|
||||
except DB_ERRORS as error:
|
||||
raise ApiError(503, "unavailable", "PostgreSQL недоступен") from error
|
||||
|
||||
async def create_attachment(self, attachment_id, chat_id, owner_id, filename,
|
||||
content_type, size_bytes, digest, object_key, *, connection=None) -> dict:
|
||||
try:
|
||||
row = await (connection or self.pool).fetchrow(
|
||||
"INSERT INTO attachments (id, chat_id, owner_id, filename, content_type, size_bytes, sha256, object_key) "
|
||||
"VALUES ($1,$2,$3,$4,$5,$6,$7,$8) RETURNING *",
|
||||
attachment_id, chat_id, owner_id, filename, content_type, size_bytes, digest, object_key,
|
||||
)
|
||||
except DB_ERRORS as error:
|
||||
raise ApiError(503, "unavailable", "PostgreSQL недоступен") from error
|
||||
return dict(row)
|
||||
|
||||
async def attachment_for_member(self, attachment_id: UUID, user_id: UUID) -> dict:
|
||||
try:
|
||||
row = await self.pool.fetchrow(
|
||||
"SELECT a.* FROM attachments a JOIN chat_members m ON m.chat_id = a.chat_id "
|
||||
"WHERE a.id = $1 AND m.user_id = $2", attachment_id, user_id,
|
||||
)
|
||||
except DB_ERRORS as error:
|
||||
raise ApiError(503, "unavailable", "PostgreSQL недоступен") from error
|
||||
if row is None:
|
||||
raise ApiError(404, "not_found", "Вложение не найдено")
|
||||
return dict(row)
|
||||
|
||||
async def attachment_keys(self) -> dict[str, UUID]:
|
||||
"""Inventory used only by the maintenance reconciler."""
|
||||
try:
|
||||
rows = await self.pool.fetch("SELECT object_key, id FROM attachments")
|
||||
except DB_ERRORS as error:
|
||||
raise RuntimeError("PostgreSQL is unavailable") from error
|
||||
return {row["object_key"]: row["id"] for row in rows}
|
||||
|
||||
@@ -0,0 +1,110 @@
|
||||
"""Bounded S3 operations; synchronous SDK calls run outside the event loop."""
|
||||
from dataclasses import dataclass
|
||||
from hashlib import sha256
|
||||
import os
|
||||
from pathlib import Path
|
||||
|
||||
import boto3
|
||||
from botocore.config import Config
|
||||
from botocore.exceptions import BotoCoreError, ClientError
|
||||
from starlette.concurrency import run_in_threadpool
|
||||
|
||||
from ..errors import ApiError
|
||||
|
||||
|
||||
@dataclass(frozen=True)
|
||||
class S3Settings:
|
||||
endpoint: str
|
||||
region: str
|
||||
bucket: str
|
||||
access_key: str
|
||||
secret_key: str
|
||||
max_bytes: int
|
||||
max_pixels: int
|
||||
|
||||
@classmethod
|
||||
def load(cls):
|
||||
def secret(name):
|
||||
path = os.environ.get(name + "_FILE")
|
||||
result = Path(path).read_text().strip() if path else os.environ.get(name, "")
|
||||
if not result:
|
||||
raise ValueError(f"Missing {name}")
|
||||
return result
|
||||
|
||||
max_bytes = int(os.environ.get("MAX_UPLOAD_BYTES", "10485760"))
|
||||
max_pixels = int(os.environ.get("MAX_IMAGE_PIXELS", "40000000"))
|
||||
if not 1 <= max_bytes <= 10485760 or not 1 <= max_pixels <= 40000000:
|
||||
raise ValueError("Image limits exceed contract")
|
||||
return cls(os.environ.get("S3_ENDPOINT", "http://s3:8333"),
|
||||
os.environ.get("S3_REGION", "us-east-1"),
|
||||
os.environ.get("S3_BUCKET", "messenger-attachments"),
|
||||
secret("S3_ACCESS_KEY_ID"), secret("S3_SECRET_ACCESS_KEY"),
|
||||
max_bytes, max_pixels)
|
||||
|
||||
|
||||
class S3Store:
|
||||
def __init__(self, settings):
|
||||
self.settings = settings
|
||||
self.client = boto3.client(
|
||||
"s3", endpoint_url=settings.endpoint, region_name=settings.region,
|
||||
aws_access_key_id=settings.access_key, aws_secret_access_key=settings.secret_key,
|
||||
config=Config(signature_version="s3v4", connect_timeout=2, read_timeout=5,
|
||||
retries={"total_max_attempts": 1},
|
||||
s3={"addressing_style": "path"},
|
||||
request_checksum_calculation="when_required",
|
||||
response_checksum_validation="when_required"),
|
||||
)
|
||||
|
||||
async def call(self, method, **kwargs):
|
||||
try:
|
||||
return await run_in_threadpool(getattr(self.client, method), **kwargs)
|
||||
except (BotoCoreError, ClientError, OSError) as error:
|
||||
raise ApiError(503, "unavailable", "S3 недоступно") from error
|
||||
|
||||
async def ready(self):
|
||||
await self.call("head_bucket", Bucket=self.settings.bucket)
|
||||
|
||||
async def put(self, key, file, size, content_type):
|
||||
file.seek(0)
|
||||
await self.call("put_object", Bucket=self.settings.bucket, Key=key,
|
||||
Body=file, ContentLength=size, ContentType=content_type)
|
||||
|
||||
async def list(self, prefix: str) -> dict[str, object]:
|
||||
"""Return every object under a controlled prefix, handling S3 pagination."""
|
||||
objects, _ = await self.list_with_pages(prefix)
|
||||
return objects
|
||||
|
||||
async def list_with_pages(self, prefix: str) -> tuple[dict[str, object], int]:
|
||||
"""Return inventory and number of S3 ListObjectsV2 pages consumed."""
|
||||
result: dict[str, object] = {}
|
||||
token = None
|
||||
pages = 0
|
||||
while True:
|
||||
args = {"Bucket": self.settings.bucket, "Prefix": prefix}
|
||||
if token:
|
||||
args["ContinuationToken"] = token
|
||||
page = await self.call("list_objects_v2", **args)
|
||||
pages += 1
|
||||
for item in page.get("Contents", []):
|
||||
result[item["Key"]] = item["LastModified"]
|
||||
if not page.get("IsTruncated"):
|
||||
return result, pages
|
||||
token = page["NextContinuationToken"]
|
||||
|
||||
async def delete(self, key: str) -> None:
|
||||
await self.call("delete_object", Bucket=self.settings.bucket, Key=key)
|
||||
|
||||
async def download(self, attachment):
|
||||
response = await self.call("get_object", Bucket=self.settings.bucket,
|
||||
Key=attachment["object_key"])
|
||||
body = response["Body"]
|
||||
try:
|
||||
data = await run_in_threadpool(body.read, self.settings.max_bytes + 1)
|
||||
except (BotoCoreError, OSError) as error:
|
||||
raise ApiError(503, "unavailable", "S3 недоступно") from error
|
||||
finally:
|
||||
body.close()
|
||||
if (len(data) != attachment["size_bytes"] or
|
||||
sha256(data).hexdigest() != attachment["sha256"]):
|
||||
raise ApiError(503, "unavailable", "Оригинал недоступен")
|
||||
return data
|
||||
@@ -0,0 +1,120 @@
|
||||
#!/usr/bin/env python3
|
||||
"""Explicit local Docker tests: private bucket, uploader failover, S3 outage."""
|
||||
import json
|
||||
from pathlib import Path
|
||||
import subprocess
|
||||
import sys
|
||||
import time
|
||||
|
||||
ROOT = Path(__file__).resolve().parents[1]
|
||||
sys.path.insert(0, str(ROOT / 'tests'))
|
||||
from client import Client, Failure, arguments, check, run
|
||||
|
||||
|
||||
def compose(*args, input=None):
|
||||
return subprocess.check_output(['docker', 'compose', *args], cwd=ROOT, input=input,
|
||||
text=True, stderr=subprocess.DEVNULL)
|
||||
|
||||
|
||||
def wait_ready(c):
|
||||
deadline = time.monotonic() + 90
|
||||
while True:
|
||||
try:
|
||||
c.call('GET', '/health/ready', schema='Health')
|
||||
return
|
||||
except Failure:
|
||||
check(time.monotonic() < deadline, 'stack did not recover')
|
||||
time.sleep(1)
|
||||
|
||||
|
||||
def main():
|
||||
def configure(parser):
|
||||
parser.add_argument('--mode', required=True, choices=['private', 'failover', 's3-outage'])
|
||||
args = arguments(__doc__, configure)
|
||||
c = Client(args.base_url, args.ca_file)
|
||||
alice, bob, eve, chat = c.bootstrap()
|
||||
data = (ROOT / 'tests/fixtures/sample.png').read_bytes()
|
||||
uploaded = c.call('POST', '/api/v1/chats/' + chat['id'] + '/attachments?filename=sample.png',
|
||||
201, actor=alice, raw=data, headers={'Content-Type': 'image/png'}, schema='Attachment')
|
||||
att = uploaded['json']
|
||||
content_path = '/api/v1/attachments/' + att['id'] + '/content'
|
||||
if args.mode == 'private':
|
||||
script = '''import sys, urllib.request, urllib.error
|
||||
url = "http://s3:8333/messenger-attachments/originals/" + sys.stdin.read().strip()
|
||||
try:
|
||||
urllib.request.urlopen(url, timeout=5)
|
||||
except urllib.error.HTTPError as error:
|
||||
assert error.code == 403, error.code
|
||||
print("PASS: anonymous S3 GET returns 403 for an existing object")
|
||||
else:
|
||||
raise AssertionError("private object leaked")
|
||||
'''
|
||||
print(compose('exec', '-T', 'api-a', '/app/.venv/bin/python', '-c', script, input=att['id']).strip())
|
||||
elif args.mode == 'failover':
|
||||
target = uploaded['headers']['X-Instance-Id']
|
||||
service = None
|
||||
for candidate in ('api-a', 'api-b'):
|
||||
container = compose('ps', '-q', candidate).strip()
|
||||
hostname = subprocess.check_output(['docker', 'inspect', '--format', '{{.Config.Hostname}}', container], text=True).strip()
|
||||
if hostname == target:
|
||||
service = candidate
|
||||
check(service is not None, 'uploading replica not found')
|
||||
try:
|
||||
compose('stop', service)
|
||||
deadline = time.monotonic() + 15
|
||||
while True:
|
||||
try:
|
||||
download = c.call('GET', content_path, actor=bob)
|
||||
break
|
||||
except Failure:
|
||||
check(time.monotonic() < deadline, 'download did not recover')
|
||||
time.sleep(0.5)
|
||||
check(download['headers']['X-Instance-Id'] != target, 'download used stopped uploader')
|
||||
check(download['bytes'] == data, 'original changed after stopping uploader')
|
||||
print('PASS: uploaded via ' + service + '; stopped that container; original downloaded through another replica')
|
||||
finally:
|
||||
compose('start', service)
|
||||
wait_ready(c)
|
||||
else:
|
||||
try:
|
||||
compose('stop', 's3')
|
||||
# Direct API request inside the network: LB excludes unready backends.
|
||||
script = '''import json, sys, urllib.request, urllib.error
|
||||
payload = json.load(sys.stdin)
|
||||
for method, path, body, headers in [
|
||||
("GET", "/health/ready", None, {}),
|
||||
("GET", payload["path"], None, {"Authorization": "Bearer " + payload["token"]}),
|
||||
("POST", payload["upload_path"], bytes.fromhex(payload["bytes"]),
|
||||
{"Authorization": "Bearer " + payload["token"], "Content-Type": "image/png"}),
|
||||
]:
|
||||
req = urllib.request.Request("http://localhost:8080" + path, data=body, headers=headers, method=method)
|
||||
try:
|
||||
urllib.request.urlopen(req, timeout=15)
|
||||
except urllib.error.HTTPError as error:
|
||||
assert error.code == 503, error.code
|
||||
document = json.load(error)
|
||||
assert document["error"]["code"] == "unavailable"
|
||||
assert document["error"]["request_id"] == error.headers["X-Request-Id"]
|
||||
else:
|
||||
raise AssertionError("S3 outage was not reported")
|
||||
assert urllib.request.urlopen("http://localhost:8080/health/live").status == 200
|
||||
print("PASS: S3 outage gives 503 for readiness, download and upload; liveness stays 200")
|
||||
'''
|
||||
payload = {'path': content_path, 'token': bob['token'], 'bytes': data.hex(),
|
||||
'upload_path': '/api/v1/chats/' + chat['id'] + '/attachments?filename=outage.png'}
|
||||
print(compose('exec', '-T', 'api-a', '/app/.venv/bin/python', '-c', script,
|
||||
input=json.dumps(payload)).strip())
|
||||
finally:
|
||||
compose('start', 's3')
|
||||
# HeadBucket/read recovery alone does not prove the write path is ready.
|
||||
# Use the same write-probing bootstrap as the documented restart hook.
|
||||
compose('run', '--rm', '--no-deps', 's3-init')
|
||||
wait_ready(c)
|
||||
check(c.call('GET', content_path, actor=bob)['bytes'] == data, 'original lost after S3 outage')
|
||||
c.call('POST', '/api/v1/chats/' + chat['id'] + '/attachments?filename=after-recovery.png',
|
||||
201, actor=alice, raw=data, headers={'Content-Type': 'image/png'}, schema='Attachment')
|
||||
print('PASS: original available and new upload accepted after S3 restart/bootstrap')
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
run(main)
|
||||
@@ -0,0 +1,111 @@
|
||||
#!/usr/bin/env python3
|
||||
"""Attachment contract checks against the running lab4 stack."""
|
||||
import hashlib
|
||||
import http.client
|
||||
from io import BytesIO
|
||||
from pathlib import Path
|
||||
import struct
|
||||
import sys
|
||||
import uuid
|
||||
import zlib
|
||||
from urllib.parse import quote, urlsplit
|
||||
|
||||
from PIL import Image
|
||||
|
||||
sys.path.insert(0, str(Path(__file__).resolve().parents[1] / "tests"))
|
||||
from client import Client, arguments, check, run
|
||||
|
||||
|
||||
def main():
|
||||
args = arguments(__doc__)
|
||||
c = Client(args.base_url, args.ca_file, timeout=30)
|
||||
alice, bob, eve, chat = c.bootstrap()
|
||||
path = '/api/v1/chats/' + chat['id'] + '/attachments?filename='
|
||||
png = (Path(__file__).resolve().parents[1] / 'tests/fixtures/sample.png').read_bytes()
|
||||
|
||||
def upload(data, mime='image/png', filename='photo.png', status=201, actor=alice):
|
||||
return c.call('POST', path + quote(filename, safe=''), status, actor=actor, raw=data,
|
||||
headers={'Content-Type': mime}, schema='Attachment' if status == 201 else None)
|
||||
|
||||
for fmt, mime in [('PNG', 'image/png'), ('JPEG', 'image/jpeg')]:
|
||||
buf = BytesIO()
|
||||
Image.new('RGB', (32, 20), 'blue').save(buf, fmt)
|
||||
data = buf.getvalue()
|
||||
att = upload(data, mime)['json']
|
||||
check(att['variants'] == [] and att['status'] == 'ready', 'wrong attachment state')
|
||||
check(att['sha256'] == hashlib.sha256(data).hexdigest(), 'wrong checksum')
|
||||
content_path = '/api/v1/attachments/' + att['id']
|
||||
check(c.call('GET', content_path, actor=bob, schema='Attachment')['json'] == att,
|
||||
'metadata changed')
|
||||
check(c.call('GET', content_path + '/content', actor=bob)['bytes'] == data, 'bytes changed')
|
||||
c.call('GET', content_path, 404, actor=eve)
|
||||
c.call('GET', content_path + '/content', 404, actor=eve)
|
||||
c.call('GET', content_path + '/content', 401)
|
||||
c.call('GET', content_path + '/content?variant=thumbnail', 404, actor=bob)
|
||||
message = c.message(bob, chat, '', attachments=[att['id']])['json']
|
||||
history = c.call('GET', '/api/v1/chats/' + chat['id'] + '/messages',
|
||||
actor=alice, schema='MessagePage')['json']['items']
|
||||
check(message in history, 'attachment message missing in history')
|
||||
print('PASS: PNG/JPEG originals, metadata, attachment-only messages and ACL')
|
||||
|
||||
for name in ('../x.png', 'x/y.png', 'x\\y.png', 'x\x00.png', 'x\n.png', 'x\x7f.png', ' ', 'x' * 256):
|
||||
upload(png, filename=name, status=400)
|
||||
upload(png, mime='image/jpeg', status=415)
|
||||
upload(b'not an image', status=415)
|
||||
upload(png[:30], status=415)
|
||||
upload(png, mime='application/octet-stream', status=415)
|
||||
upload(png, status=404, actor=eve)
|
||||
upload(b'x' * (10485760 + 1), status=413)
|
||||
|
||||
# Valid PNG header with an oversized canvas: reject before attempting pixel decoding.
|
||||
def chunk(kind, data):
|
||||
return struct.pack('>I', len(data)) + kind + data + struct.pack('>I', zlib.crc32(kind + data))
|
||||
huge = b'\x89PNG\r\n\x1a\n' + chunk(b'IHDR', struct.pack('>IIBBBBB', 8001, 5000, 8, 2, 0, 0, 0))
|
||||
huge += chunk(b'IDAT', zlib.compress(b'')) + chunk(b'IEND', b'')
|
||||
upload(huge, status=413)
|
||||
|
||||
# No Content-Length: limits must also work for chunked requests.
|
||||
url = urlsplit(c.base)
|
||||
connection = http.client.HTTPConnection(url.hostname, url.port, timeout=30)
|
||||
connection.request('POST', path + 'chunked.png', body=iter([b'x' * 65536] * 161),
|
||||
headers={'Authorization': 'Bearer ' + alice['token'], 'Content-Type': 'image/png'},
|
||||
encode_chunked=True)
|
||||
response = connection.getresponse()
|
||||
check(response.status == 413, 'chunked upload bypassed byte limit')
|
||||
response.read()
|
||||
connection.close()
|
||||
print('PASS: filename, MIME, malformed image, byte/pixel and chunked limits')
|
||||
|
||||
att = upload(png)['json']
|
||||
other_chat = c.call('POST', '/api/v1/chats', 201, actor=alice,
|
||||
body={'title': 'other', 'member_ids': [alice['id']]}, schema='Chat')['json']
|
||||
for target, ids, code in ((chat, [str(uuid.uuid4())], 404),
|
||||
(other_chat, [att['id']], 404),
|
||||
(chat, [att['id'], att['id']], 400)):
|
||||
c.call('POST', '/api/v1/chats/' + target['id'] + '/messages', code, actor=alice,
|
||||
body={'text': '', 'attachment_ids': ids}, headers={'Idempotency-Key': uuid.uuid4().hex})
|
||||
key = uuid.uuid4().hex
|
||||
first = c.message(alice, chat, 'same', key=key)['json']
|
||||
check(c.message(alice, chat, 'same', key=key, attachments=[])['json'] == first,
|
||||
'omitted and empty attachment_ids differ')
|
||||
key = uuid.uuid4().hex
|
||||
first = c.message(alice, chat, '', key=key, attachments=[att['id']])['json']
|
||||
check(c.message(alice, chat, '', key=key, attachments=[att['id']])['json'] == first, 'replay differs')
|
||||
c.call('POST', '/api/v1/chats/' + chat['id'] + '/messages', 409, actor=alice,
|
||||
body={'text': 'changed', 'attachment_ids': [att['id']]}, headers={'Idempotency-Key': key})
|
||||
print('PASS: attachment scope, duplicates and idempotency normalization')
|
||||
|
||||
# Exact limits are accepted; original bytes (including PNG trailing data) survive.
|
||||
exact = png + b'\0' * (10485760 - len(png))
|
||||
att = upload(exact)['json']
|
||||
check(c.call('GET', '/api/v1/attachments/' + att['id'] + '/content', actor=bob)['bytes'] == exact,
|
||||
'10 MiB original changed')
|
||||
buf = BytesIO()
|
||||
Image.new('RGB', (8000, 5000)).save(buf, 'PNG')
|
||||
att = upload(buf.getvalue())['json']
|
||||
check(att['size_bytes'] == len(buf.getvalue()), '40M pixel upload failed')
|
||||
print('PASS: inclusive 10 MiB and 40 million pixel boundaries')
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
run(main)
|
||||
@@ -0,0 +1,152 @@
|
||||
#!/usr/bin/env python3
|
||||
"""Inject S3/DB disagreement and prove dry-run, grace period and safe repair."""
|
||||
import json
|
||||
import base64
|
||||
from pathlib import Path
|
||||
import subprocess
|
||||
import sys
|
||||
import time
|
||||
import uuid
|
||||
|
||||
ROOT = Path(__file__).resolve().parents[1]
|
||||
sys.path.insert(0, str(ROOT / "tests"))
|
||||
from client import Client, Failure, arguments, check, run
|
||||
|
||||
|
||||
def compose(*args, input=None, env=None) -> str:
|
||||
return subprocess.check_output(["docker", "compose", *args], cwd=ROOT, text=True,
|
||||
input=input, env=env)
|
||||
|
||||
|
||||
def reconcile(*args) -> dict:
|
||||
output = compose("--profile", "maintenance", "run", "--rm", "--no-deps", "reconcile", *args)
|
||||
return json.loads(next(line for line in reversed(output.splitlines()) if line.startswith("{")))
|
||||
|
||||
|
||||
def s3_code(action: str, key: str, data: bytes | None = None) -> None:
|
||||
code = """from src.storage.s3 import S3Settings, S3Store
|
||||
import base64, json, sys
|
||||
s3 = S3Store(S3Settings.load())
|
||||
payload = json.load(sys.stdin)
|
||||
key = payload['key']
|
||||
try:
|
||||
if sys.argv[1] == 'put':
|
||||
s3.client.put_object(Bucket=s3.settings.bucket, Key=key,
|
||||
Body=base64.b64decode(payload.get('data', 'b3JwaGFu')))
|
||||
else:
|
||||
s3.client.delete_object(Bucket=s3.settings.bucket, Key=key)
|
||||
finally:
|
||||
s3.client.close()
|
||||
"""
|
||||
payload = {"key": key}
|
||||
if data is not None:
|
||||
payload["data"] = base64.b64encode(data).decode()
|
||||
compose("run", "--rm", "--no-deps", "s3-init", "/app/.venv/bin/python", "-c", code, action,
|
||||
input=json.dumps(payload))
|
||||
|
||||
|
||||
def wait_ready(client: Client, env=None) -> None:
|
||||
subprocess.run(["docker", "compose", "up", "-d", "--wait", "--no-deps", "api-a"],
|
||||
cwd=ROOT, env=env, check=True, stdout=subprocess.DEVNULL)
|
||||
deadline = time.monotonic() + 15
|
||||
while True:
|
||||
try:
|
||||
client.call("GET", "/health/ready", schema="Health")
|
||||
return
|
||||
except Failure:
|
||||
check(time.monotonic() < deadline, "stack did not recover")
|
||||
time.sleep(.5)
|
||||
|
||||
|
||||
def main():
|
||||
args = arguments(__doc__)
|
||||
client = Client(args.base_url, args.ca_file, timeout=30)
|
||||
alice, bob, _eve, chat = client.bootstrap()
|
||||
image = (ROOT / "tests/fixtures/sample.png").read_bytes()
|
||||
path = "/api/v1/chats/" + chat["id"] + "/attachments?filename="
|
||||
|
||||
def upload(name, expected=201):
|
||||
return client.call("POST", path + name, expected, actor=alice, raw=image,
|
||||
headers={"Content-Type": "image/png"},
|
||||
schema="Attachment" if expected == 201 else None)
|
||||
|
||||
# A reference object must survive an apply sweep, even with zero grace.
|
||||
protected = upload("protected.png")["json"]
|
||||
message = client.message(alice, chat, "protected", attachments=[protected["id"]])["json"]
|
||||
orphan = "originals/test-orphan-" + uuid.uuid4().hex
|
||||
s3_code("put", orphan)
|
||||
|
||||
report = reconcile("--grace-seconds", "3600")
|
||||
check(orphan in report["fresh_unreferenced"], "fresh orphan missing from dry-run")
|
||||
check(not report["deleted"], "dry-run deleted an object")
|
||||
report = reconcile("--apply", "--grace-seconds", "3600", "--object-key", orphan)
|
||||
check(orphan in report["fresh_unreferenced"] and not report["deleted"], "grace period ignored")
|
||||
report = reconcile("--apply", "--grace-seconds", "0", "--object-key", orphan)
|
||||
check(report["deleted"] == [orphan], "aged orphan was not deleted safely")
|
||||
report = reconcile("--apply", "--grace-seconds", "0", "--object-key", orphan)
|
||||
check(orphan not in report["deleted"] and orphan not in report["orphan_candidates"],
|
||||
"second repair run was not idempotent")
|
||||
check(client.call("GET", "/api/v1/attachments/" + protected["id"] + "/content", actor=bob)["bytes"] == image,
|
||||
"reconciler deleted a referenced object")
|
||||
|
||||
# This models loss after metadata has committed: report it, do not delete metadata.
|
||||
missing = upload("missing.png")["json"]
|
||||
missing_key = "originals/" + missing["id"]
|
||||
s3_code("delete", missing_key)
|
||||
try:
|
||||
report = reconcile("--apply", "--grace-seconds", "0", "--object-key", missing_key)
|
||||
expected = {"attachment_id": missing["id"], "object_key": missing_key}
|
||||
check(expected in report["missing_objects"], "missing metadata/object pair not reported")
|
||||
client.call("GET", "/api/v1/attachments/" + missing["id"], actor=bob, schema="Attachment")
|
||||
client.call("GET", "/api/v1/attachments/" + missing["id"] + "/content", 503, actor=bob)
|
||||
finally:
|
||||
s3_code("put", missing_key, image)
|
||||
check(client.call("GET", "/api/v1/attachments/" + missing["id"] + "/content", actor=bob)["bytes"] == image,
|
||||
"test object was not restored")
|
||||
report = reconcile("--grace-seconds", "0")
|
||||
check(expected not in report["missing_objects"], "restored object remained missing on second scan")
|
||||
print("PASS: S3-side missing object, dry-run, grace period and idempotent orphan repair", flush=True)
|
||||
|
||||
# Inject a process-equivalent failure after PUT directly into the configured
|
||||
# replica. The public load balancer may correctly select the healthy peer,
|
||||
# which would not exercise this boundary.
|
||||
environment = dict(__import__("os").environ, UPLOAD_FAULT_AFTER_S3_PUT="1")
|
||||
before_fault = set(reconcile("--grace-seconds", "0")["orphan_candidates"])
|
||||
try:
|
||||
subprocess.run(["docker", "compose", "up", "-d", "--force-recreate", "--no-deps", "api-a"],
|
||||
cwd=ROOT, env=environment, check=True, stdout=subprocess.DEVNULL)
|
||||
wait_ready(client, environment)
|
||||
fault = """import base64, json, sys, urllib.error, urllib.request
|
||||
payload = json.load(sys.stdin)
|
||||
request = urllib.request.Request('http://127.0.0.1:8080/api/v1/chats/' + payload['chat_id'] +
|
||||
'/attachments?filename=fault-after-put.png', data=base64.b64decode(payload['image']),
|
||||
method='POST', headers={'Authorization': 'Bearer ' + payload['token'], 'Content-Type': 'image/png'})
|
||||
try:
|
||||
urllib.request.urlopen(request, timeout=30)
|
||||
except urllib.error.HTTPError as error:
|
||||
assert error.code == 503, error.code
|
||||
assert json.load(error)['error']['code'] == 'unavailable'
|
||||
else:
|
||||
raise AssertionError('fault injection unexpectedly returned success')
|
||||
"""
|
||||
compose("exec", "-T", "api-a", "/app/.venv/bin/python", "-c", fault,
|
||||
input=json.dumps({"chat_id": chat["id"], "token": alice["token"],
|
||||
"image": base64.b64encode(image).decode()}))
|
||||
report = reconcile("--grace-seconds", "0")
|
||||
injected = sorted(set(report["orphan_candidates"]) - before_fault)
|
||||
check(len(injected) == 1, "fault must create exactly one new orphan; run without other writers")
|
||||
report = reconcile("--apply", "--grace-seconds", "0", "--object-key", injected[0])
|
||||
check(set(injected).issubset(report["deleted"]), "reconciler did not clean injected orphan")
|
||||
history = client.call("GET", "/api/v1/chats/" + chat["id"] + "/messages", actor=bob, schema="MessagePage")["json"]
|
||||
check(message in history["items"], "message reference was lost")
|
||||
check(client.call("GET", "/api/v1/attachments/" + protected["id"] + "/content", actor=bob)["bytes"] == image,
|
||||
"used original was lost")
|
||||
print("PASS: injected pre-INSERT failure repaired; message and used original survive", flush=True)
|
||||
finally:
|
||||
environment["UPLOAD_FAULT_AFTER_S3_PUT"] = "0"
|
||||
subprocess.run(["docker", "compose", "up", "-d", "--wait", "--force-recreate", "--no-deps", "api-a"],
|
||||
cwd=ROOT, env=environment, check=True, stdout=subprocess.DEVNULL)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
run(main)
|
||||
@@ -0,0 +1,159 @@
|
||||
#!/usr/bin/env python3
|
||||
"""Real database rejection, concurrent commit, interrupted upload and pagination."""
|
||||
import base64
|
||||
import json
|
||||
from pathlib import Path
|
||||
import subprocess
|
||||
import sys
|
||||
|
||||
ROOT = Path(__file__).resolve().parents[1]
|
||||
sys.path.insert(0, str(ROOT / "tests"))
|
||||
from client import Client, arguments, run
|
||||
|
||||
PROBE = r'''
|
||||
import asyncio, base64, hashlib, http.client, json, sys, urllib.request, urllib.error
|
||||
from types import SimpleNamespace
|
||||
from uuid import UUID, uuid4
|
||||
from src.config import load_settings
|
||||
from src.storage.postgres import PostgresStore
|
||||
from src.storage.s3 import S3Store, S3Settings
|
||||
from src.reconcile import run as reconcile, scan
|
||||
|
||||
payload = json.load(sys.stdin)
|
||||
image = base64.b64decode(payload['image'])
|
||||
chat_id, user_id = UUID(payload['chat_id']), UUID(payload['user_id'])
|
||||
|
||||
def upload(filename):
|
||||
req = urllib.request.Request('http://api-a:8080/api/v1/chats/' + str(chat_id) +
|
||||
'/attachments?filename=' + filename, data=image, method='POST',
|
||||
headers={'Authorization': 'Bearer ' + payload['token'], 'Content-Type': 'image/png'})
|
||||
try:
|
||||
with urllib.request.urlopen(req, timeout=30) as response:
|
||||
return response.status, json.load(response)
|
||||
except urllib.error.HTTPError as error:
|
||||
return error.code, json.load(error)
|
||||
|
||||
async def main():
|
||||
db = PostgresStore(load_settings().database_url)
|
||||
s3 = S3Store(S3Settings.load())
|
||||
await db.connect()
|
||||
def args(key):
|
||||
return SimpleNamespace(apply=True, grace_seconds=0, object_key=[key])
|
||||
try:
|
||||
# A failed metadata inventory must not authorize any S3 deletion.
|
||||
key = 'originals/audit-inventory-' + uuid4().hex
|
||||
await s3.call('put_object', Bucket=s3.settings.bucket, Key=key, Body=image)
|
||||
class BrokenInventory:
|
||||
async def attachment_keys(self):
|
||||
# Real SQL failure, not an empty inventory on error.
|
||||
return await db.pool.fetch('SELECT * FROM audit_missing_table_' + uuid4().hex)
|
||||
try:
|
||||
async with db.attachment_transaction(maintenance=True):
|
||||
try:
|
||||
await scan(args(key), BrokenInventory(), s3)
|
||||
except Exception:
|
||||
pass
|
||||
else:
|
||||
raise AssertionError('failed inventory did not abort')
|
||||
assert key in await s3.list('originals/')
|
||||
finally:
|
||||
await s3.delete(key)
|
||||
print('PASS: failed PostgreSQL inventory aborts apply without deleting the orphan', flush=True)
|
||||
|
||||
# An actual PostgreSQL trigger rejects only this test chat's INSERT.
|
||||
suffix = uuid4().hex
|
||||
name = 'audit_reject_' + suffix
|
||||
before = await s3.list('originals/')
|
||||
await db.pool.execute(f"""CREATE FUNCTION {name}() RETURNS trigger LANGUAGE plpgsql AS $$
|
||||
BEGIN IF NEW.chat_id = '{chat_id}'::uuid THEN
|
||||
RAISE EXCEPTION 'synthetic audit rejection' USING ERRCODE = '23514';
|
||||
END IF; RETURN NEW; END $$""")
|
||||
try:
|
||||
await db.pool.execute(f'CREATE TRIGGER {name} BEFORE INSERT ON attachments FOR EACH ROW EXECUTE FUNCTION {name}()')
|
||||
status, body = await asyncio.to_thread(upload, 'db-failure.png')
|
||||
assert status == 503 and body['error']['code'] == 'unavailable', (status, body)
|
||||
assert await db.pool.fetchval('SELECT count(*) FROM attachments WHERE chat_id=$1', chat_id) == 0
|
||||
finally:
|
||||
await db.pool.execute(f'DROP TRIGGER IF EXISTS {name} ON attachments')
|
||||
await db.pool.execute(f'DROP FUNCTION {name}()')
|
||||
created = set(await s3.list('originals/')) - set(before)
|
||||
assert len(created) == 1, created
|
||||
key = created.pop()
|
||||
report = await reconcile(SimpleNamespace(apply=False, grace_seconds=0, object_key=[key]))
|
||||
assert key in report['orphan_candidates'] and not report['deleted']
|
||||
assert (await reconcile(args(key)))['deleted'] == [key]
|
||||
assert not (await reconcile(args(key)))['deleted']
|
||||
print('PASS: actual PostgreSQL INSERT rejection -> 503, dry-run detection, scoped repair, repeat no-op', flush=True)
|
||||
|
||||
# Writer holds a shared lock after PUT; cleanup must wait for COMMIT.
|
||||
identifier = uuid4()
|
||||
key = 'originals/' + str(identifier)
|
||||
async with db.attachment_transaction() as connection:
|
||||
await s3.call('put_object', Bucket=s3.settings.bucket, Key=key, Body=image)
|
||||
sweep = asyncio.create_task(reconcile(args(key)))
|
||||
for _ in range(40):
|
||||
waiting = await db.pool.fetchval("SELECT count(*) FROM pg_locks WHERE locktype='advisory' AND classid=41004 AND objid=1 AND NOT granted")
|
||||
if waiting:
|
||||
break
|
||||
await asyncio.sleep(.05)
|
||||
assert waiting and not sweep.done(), 'maintenance failed to wait for active writer'
|
||||
await db.create_attachment(identifier, chat_id, user_id, 'concurrent.png', 'image/png',
|
||||
len(image), hashlib.sha256(image).hexdigest(), key, connection=connection)
|
||||
report = await sweep
|
||||
assert key not in report['deleted'] and key not in report['orphan_candidates']
|
||||
row = await db.attachment_for_member(identifier, user_id)
|
||||
assert await s3.download(row) == image
|
||||
print('PASS: apply with zero grace waits for in-flight PUT/COMMIT; committed original survives', flush=True)
|
||||
|
||||
# Abrupt client close before all bytes arrive must not persist a file.
|
||||
before = await s3.list('originals/')
|
||||
rows = await db.attachment_keys()
|
||||
def interrupt():
|
||||
conn = http.client.HTTPConnection('api-a', 8080, timeout=10)
|
||||
conn.putrequest('POST', '/api/v1/chats/' + str(chat_id) + '/attachments?filename=interrupted.png')
|
||||
conn.putheader('Authorization', 'Bearer ' + payload['token'])
|
||||
conn.putheader('Content-Type', 'image/png')
|
||||
conn.putheader('Content-Length', str(len(image) + 100000))
|
||||
conn.endheaders()
|
||||
conn.send(image[:32])
|
||||
conn.close()
|
||||
await asyncio.to_thread(interrupt)
|
||||
await asyncio.sleep(1)
|
||||
assert await db.attachment_keys() == rows
|
||||
assert await s3.list('originals/') == before
|
||||
status, body = await asyncio.to_thread(upload, 'after-disconnect.png')
|
||||
assert status == 201, (status, body)
|
||||
print('PASS: interrupted upload leaves no metadata/object and next upload succeeds', flush=True)
|
||||
|
||||
# Exercise pagination on real S3 without adding thousands of fixtures.
|
||||
original_call = s3.call
|
||||
async def small_pages(method, **kwargs):
|
||||
if method == 'list_objects_v2':
|
||||
kwargs['MaxKeys'] = 7
|
||||
return await original_call(method, **kwargs)
|
||||
expected = await s3.list('originals/')
|
||||
s3.call = small_pages
|
||||
actual, pages = await s3.list_with_pages('originals/')
|
||||
assert actual == expected and pages > 1
|
||||
print(f'PASS: S3 pagination: {len(actual)} keys across {pages} pages, no missing/duplicate keys', flush=True)
|
||||
finally:
|
||||
s3.client.close()
|
||||
await db.close()
|
||||
|
||||
asyncio.run(main())
|
||||
'''
|
||||
|
||||
|
||||
def main():
|
||||
args = arguments(__doc__)
|
||||
client = Client(args.base_url, args.ca_file, timeout=30)
|
||||
alice, _, _, chat = client.bootstrap()
|
||||
payload = {"chat_id": chat["id"], "user_id": alice["id"], "token": alice["token"],
|
||||
"image": base64.b64encode((ROOT / "tests/fixtures/sample.png").read_bytes()).decode()}
|
||||
subprocess.run(["docker", "compose", "--profile", "maintenance", "run", "--rm", "--no-deps",
|
||||
"--entrypoint", "/app/.venv/bin/python", "reconcile", "-c", PROBE],
|
||||
cwd=ROOT, input=json.dumps(payload), text=True, check=True)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
run(main)
|
||||
@@ -0,0 +1,74 @@
|
||||
#!/usr/bin/env python3
|
||||
"""Measure repeatable reconciler inventory cost for two controlled S3 sizes."""
|
||||
import json
|
||||
from pathlib import Path
|
||||
import statistics
|
||||
import subprocess
|
||||
import sys
|
||||
import uuid
|
||||
|
||||
ROOT = Path(__file__).resolve().parents[1]
|
||||
sys.path.insert(0, str(ROOT / "tests"))
|
||||
from client import arguments, check, run
|
||||
|
||||
|
||||
def compose(*args, input=None) -> str:
|
||||
return subprocess.check_output(["docker", "compose", *args], cwd=ROOT, text=True, input=input)
|
||||
|
||||
|
||||
def reconcile() -> dict:
|
||||
output = compose("--profile", "maintenance", "run", "--rm", "--no-deps", "reconcile",
|
||||
"--grace-seconds", "3600")
|
||||
return json.loads(next(line for line in reversed(output.splitlines()) if line.startswith("{")))
|
||||
|
||||
|
||||
def mutate(action: str, keys: list[str]) -> None:
|
||||
code = """from src.storage.s3 import S3Settings, S3Store
|
||||
import json, sys
|
||||
s3 = S3Store(S3Settings.load())
|
||||
try:
|
||||
for key in json.load(sys.stdin):
|
||||
if sys.argv[1] == 'put':
|
||||
s3.client.put_object(Bucket=s3.settings.bucket, Key=key, Body=b'track-2-benchmark')
|
||||
else:
|
||||
s3.client.delete_object(Bucket=s3.settings.bucket, Key=key)
|
||||
finally:
|
||||
s3.client.close()
|
||||
"""
|
||||
compose("run", "--rm", "--no-deps", "s3-init", "/app/.venv/bin/python", "-c", code, action,
|
||||
input=json.dumps(keys))
|
||||
|
||||
|
||||
def main() -> None:
|
||||
arguments(__doc__) # Keeps the common --base-url/--ca-file command interface.
|
||||
results = []
|
||||
for requested in (32, 128):
|
||||
prefix = f"originals/track2-benchmark-{uuid.uuid4().hex}-"
|
||||
keys = [prefix + str(index) for index in range(requested)]
|
||||
try:
|
||||
mutate("put", keys)
|
||||
reports = [reconcile() for _ in range(3)]
|
||||
for report in reports:
|
||||
check(set(keys).issubset(report["fresh_unreferenced"]),
|
||||
"benchmark objects were not included in the inventory")
|
||||
check(not set(keys) & set(report["orphan_candidates"]),
|
||||
"grace period classified fresh benchmark objects as deletable")
|
||||
seconds = [report["scan_metrics"]["total_seconds"] for report in reports]
|
||||
results.append({
|
||||
"added_unreferenced_objects": requested,
|
||||
"runs": 3,
|
||||
"s3_objects_scanned": reports[-1]["s3_objects"],
|
||||
"metadata_rows_scanned": reports[-1]["metadata_rows"],
|
||||
"s3_list_pages": reports[-1]["scan_metrics"]["s3_list_pages"],
|
||||
"seconds": seconds,
|
||||
"median_seconds": round(statistics.median(seconds), 6),
|
||||
})
|
||||
finally:
|
||||
mutate("delete", keys)
|
||||
print(json.dumps({"method": "three dry-run inventories per controlled size", "results": results},
|
||||
sort_keys=True))
|
||||
print("PASS: reconciler cost measured for 32 and 128 added S3 objects; fixtures removed")
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
run(main)
|
||||
@@ -0,0 +1,54 @@
|
||||
#!/usr/bin/env python3
|
||||
"""Prove that the API identity is bucket-scoped and lacks admin operations."""
|
||||
import subprocess
|
||||
from pathlib import Path
|
||||
import sys
|
||||
import uuid
|
||||
|
||||
ROOT = Path(__file__).resolve().parents[1]
|
||||
sys.path.insert(0, str(ROOT / "tests"))
|
||||
from client import Client, arguments, check, run
|
||||
|
||||
|
||||
def compose(*args, input=None):
|
||||
return subprocess.check_output(["docker", "compose", *args], cwd=ROOT, text=True,
|
||||
input=input, stderr=subprocess.DEVNULL)
|
||||
|
||||
|
||||
def main():
|
||||
args = arguments(__doc__)
|
||||
client = Client(args.base_url, args.ca_file)
|
||||
alice, _bob, _eve, chat = client.bootstrap()
|
||||
data = (ROOT / "tests/fixtures/sample.png").read_bytes()
|
||||
client.call("POST", "/api/v1/chats/" + chat["id"] + "/attachments?filename=permission.png", 201,
|
||||
actor=alice, raw=data, headers={"Content-Type": "image/png"}, schema="Attachment")
|
||||
bucket = "permission-probe-" + uuid.uuid4().hex
|
||||
code = """from botocore.exceptions import ClientError
|
||||
from src.storage.s3 import S3Settings, S3Store
|
||||
import sys
|
||||
s3 = S3Store(S3Settings.load())
|
||||
try:
|
||||
try:
|
||||
s3.client.create_bucket(Bucket=sys.stdin.read().strip())
|
||||
except ClientError as error:
|
||||
assert error.response['Error']['Code'] in {'AccessDenied', 'Unauthorized'}, error.response
|
||||
else:
|
||||
raise AssertionError('API S3 identity unexpectedly has admin bucket creation')
|
||||
finally:
|
||||
s3.client.close()
|
||||
"""
|
||||
compose("exec", "-T", "api-a", "/app/.venv/bin/python", "-c", code, input=bucket)
|
||||
admin = """from src.storage.s3 import S3Settings, S3Store
|
||||
import sys
|
||||
s3 = S3Store(S3Settings.load())
|
||||
try:
|
||||
s3.client.list_buckets()
|
||||
finally:
|
||||
s3.client.close()
|
||||
"""
|
||||
compose("run", "--rm", "--no-deps", "s3-init", "/app/.venv/bin/python", "-c", admin)
|
||||
print("PASS: API identity cannot create buckets; maintenance identity has separate admin access")
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
run(main)
|
||||
@@ -0,0 +1,106 @@
|
||||
#!/usr/bin/env python3
|
||||
"""Ten concurrent bounded uploads, with API-container peak memory sampling."""
|
||||
from concurrent.futures import ThreadPoolExecutor
|
||||
import json
|
||||
import http.client
|
||||
from pathlib import Path
|
||||
import subprocess
|
||||
import sys
|
||||
import threading
|
||||
import time
|
||||
from urllib.parse import quote
|
||||
from urllib.parse import urlsplit
|
||||
|
||||
ROOT = Path(__file__).resolve().parents[1]
|
||||
sys.path.insert(0, str(ROOT / "tests"))
|
||||
from client import Client, arguments, check, run
|
||||
|
||||
|
||||
def api_memory() -> dict[str, int]:
|
||||
ids = subprocess.check_output(["docker", "compose", "ps", "-q", "api-a", "api-b"], cwd=ROOT, text=True).split()
|
||||
return {container[:12]: int(subprocess.check_output(
|
||||
["docker", "exec", container, "cat", "/sys/fs/cgroup/memory.current"], text=True))
|
||||
for container in ids}
|
||||
|
||||
|
||||
def main():
|
||||
def configure(parser):
|
||||
parser.add_argument("--output", default="evidence/upload-memory.json")
|
||||
parser.add_argument("--size-mib", type=int, default=5)
|
||||
args = arguments(__doc__, configure)
|
||||
check(1 <= args.size_mib <= 10, "--size-mib must be 1..10")
|
||||
client = Client(args.base_url, args.ca_file, timeout=60)
|
||||
alice, _bob, _eve, chat = client.bootstrap()
|
||||
seed = (ROOT / "tests/fixtures/sample.png").read_bytes()
|
||||
payload = seed + b"\0" * (args.size_mib * 1024 * 1024 - len(seed))
|
||||
baseline, peak, samples, stop = api_memory(), {}, [], threading.Event()
|
||||
check(len(baseline) == 2, "memory experiment requires two running APIs")
|
||||
sampling_errors = []
|
||||
timestamps = []
|
||||
barrier = threading.Barrier(10)
|
||||
|
||||
def sampler():
|
||||
while not stop.is_set():
|
||||
try:
|
||||
values = api_memory()
|
||||
check(set(values) == set(baseline), "API containers changed during measurement")
|
||||
except Exception as error:
|
||||
sampling_errors.append(type(error).__name__)
|
||||
return
|
||||
timestamps.append(time.monotonic())
|
||||
samples.append(values)
|
||||
for name, value in values.items():
|
||||
peak[name] = max(peak.get(name, 0), value)
|
||||
time.sleep(.1)
|
||||
|
||||
def upload(index):
|
||||
barrier.wait(timeout=15)
|
||||
parsed = urlsplit(client.base)
|
||||
connection = http.client.HTTPConnection(parsed.hostname, parsed.port, timeout=60)
|
||||
|
||||
def chunks():
|
||||
for offset in range(0, len(payload), 512 * 1024):
|
||||
yield payload[offset:offset + 512 * 1024]
|
||||
# Keep all ten client streams open long enough for multiple memory samples.
|
||||
time.sleep(.5)
|
||||
|
||||
connection.request("POST", "/api/v1/chats/" + chat["id"] + "/attachments?filename=" + quote(f"load-{index}.png"),
|
||||
body=chunks(), encode_chunked=True,
|
||||
headers={"Authorization": "Bearer " + alice["token"], "Content-Type": "image/png"})
|
||||
response = connection.getresponse()
|
||||
body = response.read()
|
||||
connection.close()
|
||||
check(response.status == 201, "upload %s returned %s: %s" % (index, response.status, body[:200]))
|
||||
return json.loads(body)
|
||||
|
||||
started = time.monotonic()
|
||||
thread = threading.Thread(target=sampler, daemon=True)
|
||||
thread.start()
|
||||
try:
|
||||
with ThreadPoolExecutor(max_workers=10) as pool:
|
||||
attachments = list(pool.map(upload, range(10)))
|
||||
finally:
|
||||
stop.set()
|
||||
thread.join(timeout=5)
|
||||
elapsed = time.monotonic() - started
|
||||
check(len({item["id"] for item in attachments}) == 10, "uploads were not distinct")
|
||||
check(not sampling_errors and len(samples) >= 2 and not thread.is_alive(),
|
||||
"memory sampler failed or did not collect enough samples: " + repr(sampling_errors))
|
||||
report = {
|
||||
"uploads": 10, "file_bytes": len(payload), "concurrency": 10,
|
||||
"api_upload_concurrency_limit": 1, "elapsed_seconds": round(elapsed, 3),
|
||||
"baseline_memory_bytes": baseline, "peak_memory_bytes": peak,
|
||||
"peak_growth_bytes": {name: peak.get(name, 0) - baseline.get(name, 0) for name in baseline},
|
||||
"samples": len(samples),
|
||||
"sample_intervals_seconds": [round(b-a, 3) for a, b in zip(timestamps, timestamps[1:])],
|
||||
"method": "cgroup memory.current via Docker; 0.1s pause AFTER each poll, actual intervals include Docker latency; ten clients start at a barrier and send chunked 512 KiB blocks every 0.5s. Peak is sampled, not continuous.",
|
||||
}
|
||||
destination = ROOT / args.output
|
||||
destination.parent.mkdir(parents=True, exist_ok=True)
|
||||
destination.write_text(json.dumps(report, ensure_ascii=False, indent=2) + "\n")
|
||||
print(json.dumps(report, ensure_ascii=False))
|
||||
check(all(value <= 512 * 1024 * 1024 for value in peak.values()), "API exceeded configured memory limit")
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
run(main)
|
||||
@@ -132,6 +132,34 @@ wheels = [
|
||||
{ url = "https://files.pythonhosted.org/packages/3c/d7/8fb3044eaef08a310acfe23dae9a8e2e07d305edc29a53497e52bc76eca7/asyncpg-0.31.0-cp314-cp314t-win_amd64.whl", hash = "sha256:bd4107bb7cdd0e9e65fae66a62afd3a249663b844fa34d479f6d5b3bef9c04c3", size = 706062, upload-time = "2025-11-24T23:26:44.086Z" },
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "boto3"
|
||||
version = "1.43.115"
|
||||
source = { registry = "https://pypi.org/simple" }
|
||||
dependencies = [
|
||||
{ name = "botocore" },
|
||||
{ name = "jmespath" },
|
||||
{ name = "s3transfer" },
|
||||
]
|
||||
sdist = { url = "https://files.pythonhosted.org/packages/0e/4a/b0ce191492a1724be73d8aacaf70d508bc8cbb9674c046d2ff7181dc51fb/boto3-1.43.115.tar.gz", hash = "sha256:c0f35e5f9cdf0edb365195e306d5586d3970b224660a11a87a4ec361ec3d7168", size = 112677, upload-time = "2026-10-19T19:19:53.093Z" }
|
||||
wheels = [
|
||||
{ url = "https://files.pythonhosted.org/packages/be/bc/40dffae3238ef8d3415393132751fe2c88e8663ef84a31f0950e439ed2d5/boto3-1.43.115-py3-none-any.whl", hash = "sha256:6667a0c21d48dc125dbba88444bc8a601ce881a99341a0e6169f9333898e620d", size = 140044, upload-time = "2026-10-19T19:19:51.444Z" },
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "botocore"
|
||||
version = "1.43.115"
|
||||
source = { registry = "https://pypi.org/simple" }
|
||||
dependencies = [
|
||||
{ name = "jmespath" },
|
||||
{ name = "python-dateutil" },
|
||||
{ name = "urllib3" },
|
||||
]
|
||||
sdist = { url = "https://files.pythonhosted.org/packages/6f/10/ca525e88db50f5153ddad2a3d55908b5ace915d10f443d5e5135ba808d8d/botocore-1.43.115.tar.gz", hash = "sha256:aa4d9c4e7ef99988b7347e0cd276ba84e1eb1625510557b0e36cd57ecb19bbf2", size = 16383796, upload-time = "2026-10-19T19:19:45.382Z" }
|
||||
wheels = [
|
||||
{ url = "https://files.pythonhosted.org/packages/77/2d/4b6b6f5704d1ec9b412c1dd9700bda0c315619dbac4a21418180a81a2780/botocore-1.43.115-py3-none-any.whl", hash = "sha256:9ceda640c868bc15f5399129e8cfdef8cbb4b350e8a99547c9b5f477cfb9619a", size = 16085101, upload-time = "2026-10-19T19:19:42.203Z" },
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "cffi"
|
||||
version = "2.1.1"
|
||||
@@ -260,6 +288,15 @@ wheels = [
|
||||
{ url = "https://files.pythonhosted.org/packages/58/a2/bb081bab032533a855d44de1d56f8e8426114ff1ba5d1f07a438a0a654f8/idna-3.20-py3-none-any.whl", hash = "sha256:ab7ae7122974553370f0bdb919e1a960b2cd1bc1ef0276416d896db81c14582c", size = 69583, upload-time = "2026-09-17T14:11:03.168Z" },
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "jmespath"
|
||||
version = "1.1.0"
|
||||
source = { registry = "https://pypi.org/simple" }
|
||||
sdist = { url = "https://files.pythonhosted.org/packages/d3/59/322338183ecda247fb5d1763a6cbe46eff7222eaeebafd9fa65d4bf5cb11/jmespath-1.1.0.tar.gz", hash = "sha256:472c87d80f36026ae83c6ddd0f1d05d4e510134ed462851fd5f754c8c3cbb88d", size = 27377, upload-time = "2026-01-22T16:35:26.279Z" }
|
||||
wheels = [
|
||||
{ url = "https://files.pythonhosted.org/packages/14/2f/967ba146e6d58cf6a652da73885f52fc68001525b4197effc174321d70b4/jmespath-1.1.0-py3-none-any.whl", hash = "sha256:a5663118de4908c91729bea0acadca56526eb2698e83de10cd116ae0f4e97c64", size = 20419, upload-time = "2026-01-22T16:35:24.919Z" },
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "mtusi2026lab4"
|
||||
version = "0.1.0"
|
||||
@@ -267,7 +304,9 @@ source = { virtual = "." }
|
||||
dependencies = [
|
||||
{ name = "argon2-cffi" },
|
||||
{ name = "asyncpg" },
|
||||
{ name = "boto3" },
|
||||
{ name = "fastapi" },
|
||||
{ name = "pillow" },
|
||||
{ name = "uvicorn" },
|
||||
]
|
||||
|
||||
@@ -275,10 +314,88 @@ dependencies = [
|
||||
requires-dist = [
|
||||
{ name = "argon2-cffi", specifier = "==25.1.0" },
|
||||
{ name = "asyncpg", specifier = "==0.31.0" },
|
||||
{ name = "boto3", specifier = "==1.43.115" },
|
||||
{ name = "fastapi", specifier = "==0.141.1" },
|
||||
{ name = "pillow", specifier = "==13.0.0" },
|
||||
{ name = "uvicorn", specifier = "==0.40.0" },
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "pillow"
|
||||
version = "13.0.0"
|
||||
source = { registry = "https://pypi.org/simple" }
|
||||
sdist = { url = "https://files.pythonhosted.org/packages/ce/a4/9cc30690a394a8305e8be4c9036aa16d0dfddadd09079860b582f562496d/pillow-13.0.0.tar.gz", hash = "sha256:cdcd1ba258178f7356d74170c9a81ba4eab6a5d55748bc402a5a2a6fe6be3510", size = 47058631, upload-time = "2026-10-16T22:18:09.718Z" }
|
||||
wheels = [
|
||||
{ url = "https://files.pythonhosted.org/packages/7a/b8/58d79332229482eb0d27c82973850808c19d37e5bdc14443d3417bd373f5/pillow-13.0.0-cp312-cp312-macosx_10_13_x86_64.whl", hash = "sha256:67c8d44ad89fa7eb88de5d6ef6199b1e03dd24974f85a67639fc8badb801fe79", size = 5568643, upload-time = "2026-10-16T22:15:44.474Z" },
|
||||
{ url = "https://files.pythonhosted.org/packages/39/4b/f2ed53d83aa44ac19599ac0a54897f867fafb95f406980d1e24083f8cbe3/pillow-13.0.0-cp312-cp312-macosx_11_0_arm64.whl", hash = "sha256:fc481f742ccda20e9ed760b8f978dff50f2a4e9bc253ac167fb0a05b0783ef52", size = 4852329, upload-time = "2026-10-16T22:15:46.284Z" },
|
||||
{ url = "https://files.pythonhosted.org/packages/3b/bb/9e30e8ed18c20800ee327a12107d5249ad8dc444867b3adfcc21654e3c71/pillow-13.0.0-cp312-cp312-manylinux_2_27_aarch64.manylinux_2_28_aarch64.whl", hash = "sha256:8bf295fe459343bc6093c8e5e0df60bfa189e0fcb775a22e2c2488fdeccc6c0d", size = 6519309, upload-time = "2026-10-16T22:15:48.14Z" },
|
||||
{ url = "https://files.pythonhosted.org/packages/e6/99/fdf65cc539e266ab93546c261bdf98411fe165c6e4e13f9dbf597097192b/pillow-13.0.0-cp312-cp312-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl", hash = "sha256:42d63be3af4f9b951b199b0a9d23365d37ab14687e6d77b74940432c8515c4ca", size = 7144542, upload-time = "2026-10-16T22:15:50.093Z" },
|
||||
{ url = "https://files.pythonhosted.org/packages/26/9b/f38b7c4d8f599537e2d1a6d546cec9beef7536ff8f5c49a3f9c78179d8ac/pillow-13.0.0-cp312-cp312-musllinux_1_2_aarch64.whl", hash = "sha256:4bd024d567eca931b668978d672dba914d4b8e2628e2c3073a2ad178de8a2620", size = 6618042, upload-time = "2026-10-16T22:15:52.054Z" },
|
||||
{ url = "https://files.pythonhosted.org/packages/a8/7c/45ee28531f89ee4582967d8a17f7a26d71ca64cd902b93c269590cd60a00/pillow-13.0.0-cp312-cp312-musllinux_1_2_x86_64.whl", hash = "sha256:23edf4ec4b6f4f240e8df6e4985e9ee2ced86474632433e55fb1e2548744bf40", size = 7228137, upload-time = "2026-10-16T22:15:54.009Z" },
|
||||
{ url = "https://files.pythonhosted.org/packages/01/bc/9c2a969cb1b70201d04fa17fd5aedf02a732870b8da86bceaaa30b0ca385/pillow-13.0.0-cp312-cp312-win32.whl", hash = "sha256:02464da86f561f410e13b061ec37c3068a9cb557a095494157742d07b3c24a27", size = 6515423, upload-time = "2026-10-16T22:15:56.25Z" },
|
||||
{ url = "https://files.pythonhosted.org/packages/ff/cd/73a79ecdc822076002eb24b5e1e4a530b0bb5310fcb6d239abbec877110b/pillow-13.0.0-cp312-cp312-win_amd64.whl", hash = "sha256:ff3fe9eb621fbb9db4c4be33ab946f6bac5f98ab50ca8d3260503653656c961b", size = 7272166, upload-time = "2026-10-16T22:15:58.597Z" },
|
||||
{ url = "https://files.pythonhosted.org/packages/4a/a3/be5a1236efd085b3984e4305da8f179ae9dab80c991d2ad78f2bd5c4c843/pillow-13.0.0-cp312-cp312-win_arm64.whl", hash = "sha256:c3bc8ee0271387e0b1e3ad0ff893645990a656e79bf9c42f4f734a3642b11d51", size = 2698943, upload-time = "2026-10-16T22:16:00.637Z" },
|
||||
{ url = "https://files.pythonhosted.org/packages/82/e2/9132d38df320e8099e2642d9fa538f18a7dfebf68a875a31725dc2a115aa/pillow-13.0.0-cp313-cp313-ios_13_0_arm64_iphoneos.whl", hash = "sha256:e98b4f91f99b24b1da72e10621ba181f7281922384a7403094debb4199de6c00", size = 4190620, upload-time = "2026-10-16T22:16:02.527Z" },
|
||||
{ url = "https://files.pythonhosted.org/packages/cb/be/436dac0996876f65ef1916ffb711c5ef4af2ebc57414b6f16642e07f6b47/pillow-13.0.0-cp313-cp313-ios_13_0_arm64_iphonesimulator.whl", hash = "sha256:34fb3db1149c879343861831728c243c432d4a5afc8f1878ca7612ef8de2a033", size = 4290286, upload-time = "2026-10-16T22:16:04.861Z" },
|
||||
{ url = "https://files.pythonhosted.org/packages/60/16/7c1007162e4169ea0d5bec47e2e0b2174f56c50cf5b8c02a1dc23e41037e/pillow-13.0.0-cp313-cp313-ios_13_0_x86_64_iphonesimulator.whl", hash = "sha256:2d50500a4a3bc6469adcdb319cf05d688b08ca3bf0f22a05339f3b25b433a599", size = 3723169, upload-time = "2026-10-16T22:16:06.956Z" },
|
||||
{ url = "https://files.pythonhosted.org/packages/08/bc/578ab2eaa04705a8978bd9be0fe15c3d43a8fc95097c4f7e39540e79e4fa/pillow-13.0.0-cp313-cp313-macosx_10_13_x86_64.whl", hash = "sha256:ef5fe6b7db3f501c56000ba8fe7c7e1a35ca1d45824fbeb95a67daa85cff4dbe", size = 5568469, upload-time = "2026-10-16T22:16:08.664Z" },
|
||||
{ url = "https://files.pythonhosted.org/packages/98/c8/ccede3dcc4f274b80fb49199eed1ef34ba05566c8b71976b9d1f111da2e3/pillow-13.0.0-cp313-cp313-macosx_11_0_arm64.whl", hash = "sha256:f11a3c1358bb3c68012a7b1f41b223c3db9f7bfde90b481df028cfe1c3363313", size = 4852187, upload-time = "2026-10-16T22:16:10.693Z" },
|
||||
{ url = "https://files.pythonhosted.org/packages/fb/3c/cd0770e96d20bfd990db024bcbd43897ff3e88da1f4782cf90ea231b1d4f/pillow-13.0.0-cp313-cp313-manylinux_2_27_aarch64.manylinux_2_28_aarch64.whl", hash = "sha256:19b66ca0a4d25cc0200b381ce824c7ea090db61427315e73cfb05dbf1b35c369", size = 6515908, upload-time = "2026-10-16T22:16:12.896Z" },
|
||||
{ url = "https://files.pythonhosted.org/packages/ef/fe/f5cdaa2d1c4086e757430f368c271a58ee29cfe7378e7ae7b9d964015c25/pillow-13.0.0-cp313-cp313-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl", hash = "sha256:5f56499c1a74d2b862beb0c33b8016f99d095858455df9d21583bbbc1c15b582", size = 7142544, upload-time = "2026-10-16T22:16:14.844Z" },
|
||||
{ url = "https://files.pythonhosted.org/packages/fb/b5/a54f6d44adbcd23737c8c12953f42be107e4cca64e247c0ca3a5b563061c/pillow-13.0.0-cp313-cp313-musllinux_1_2_aarch64.whl", hash = "sha256:a2a14cd73d5e6c927f644b0110ee81f59c4ef506259ec9183904747f2caacc81", size = 6613097, upload-time = "2026-10-16T22:16:16.893Z" },
|
||||
{ url = "https://files.pythonhosted.org/packages/e6/b4/9e6c1207c21b2e91db0d15c16d30f3701ce5add1bd4da0e787761e66cb6e/pillow-13.0.0-cp313-cp313-musllinux_1_2_x86_64.whl", hash = "sha256:08b826a9bf1265c76de04a42061d61ea6b109418b7826f28ff1ecdfaa26c5502", size = 7224846, upload-time = "2026-10-16T22:16:19.195Z" },
|
||||
{ url = "https://files.pythonhosted.org/packages/78/9f/d3c3cb0518f3dd1eee0ef501535f53d15597a53c5c4118d178086143397a/pillow-13.0.0-cp313-cp313-win32.whl", hash = "sha256:12b0fa15879fe5a9d9eebe66e4e2d74128a773b1a4448010c9c714f45e04b9d8", size = 6516013, upload-time = "2026-10-16T22:16:21.389Z" },
|
||||
{ url = "https://files.pythonhosted.org/packages/d7/ed/1b16fb66a37e1b9e41370b93b2c614c7da761a5b2a41dc333f7af4639962/pillow-13.0.0-cp313-cp313-win_amd64.whl", hash = "sha256:9dda0788a9932776a75d8bcc020076edc308ce2508b51f6739a45e3158b3fc42", size = 7284777, upload-time = "2026-10-16T22:16:23.393Z" },
|
||||
{ url = "https://files.pythonhosted.org/packages/87/7d/8d02eba9f7ecc87f8e90f731e032cc4773802f2a843763afd0c66a535ff4/pillow-13.0.0-cp313-cp313-win_arm64.whl", hash = "sha256:40a266371ece581e5de13b6635ef78d7487824af80561b6ca27694a88c19bc0f", size = 2698826, upload-time = "2026-10-16T22:16:25.382Z" },
|
||||
{ url = "https://files.pythonhosted.org/packages/8e/45/fbad9c7f5e2f1745c373a434d46072bc84eddfefaa28b852425ac957fda6/pillow-13.0.0-cp314-cp314-ios_13_0_arm64_iphoneos.whl", hash = "sha256:44629d4498c9cb6b2051806155f22141df0d8a929c56134b166655232dfb2f8c", size = 4190721, upload-time = "2026-10-16T22:16:27.524Z" },
|
||||
{ url = "https://files.pythonhosted.org/packages/a2/bf/2074902a259a90692c5dbf132885d21671644cbbd3f690047516243a55db/pillow-13.0.0-cp314-cp314-ios_13_0_arm64_iphonesimulator.whl", hash = "sha256:bf97ba1b5542050e9b0c74e632323b6d8136cc99d64e193abebee22fe6013c76", size = 4290236, upload-time = "2026-10-16T22:16:29.562Z" },
|
||||
{ url = "https://files.pythonhosted.org/packages/ff/a5/3d1bb93b8ea38d15d21356c1b8e9f50971ac592aaa248f7fb71739094c0e/pillow-13.0.0-cp314-cp314-ios_13_0_x86_64_iphonesimulator.whl", hash = "sha256:aa694c49787040943570d61c9b8fc01271bd2a2cfdd55f0d896f8aecdce1a981", size = 3723093, upload-time = "2026-10-16T22:16:31.249Z" },
|
||||
{ url = "https://files.pythonhosted.org/packages/84/a1/be060135d85187b25fa8b2573786c0e45c62ae27527fff5257675eb97f4a/pillow-13.0.0-cp314-cp314-macosx_10_15_x86_64.whl", hash = "sha256:49c12af515073e9bf511e4ef736743bf70d531a643668722279314b937742ba4", size = 5572253, upload-time = "2026-10-16T22:16:33.103Z" },
|
||||
{ url = "https://files.pythonhosted.org/packages/b5/f4/0bf6f1ac9ba7ee2ffe9914aeb410a1035a0c1a3c42f122388d7fc950bc4b/pillow-13.0.0-cp314-cp314-macosx_11_0_arm64.whl", hash = "sha256:d9b0a2bee3f3e03e9f29057aedb807dbf1e1d96ee1b9d0f422d9db6c8583271d", size = 4852269, upload-time = "2026-10-16T22:16:35.102Z" },
|
||||
{ url = "https://files.pythonhosted.org/packages/83/16/b603274617b3e6728da3a0133d4fba1ea8d7fbe0c4ea5fef9cbffa398b8b/pillow-13.0.0-cp314-cp314-manylinux_2_27_aarch64.manylinux_2_28_aarch64.whl", hash = "sha256:5933fcea5a5ba64c686f55c886a115cbfd92f2900460784a1e79909fdbafd7b6", size = 6516058, upload-time = "2026-10-16T22:16:37.228Z" },
|
||||
{ url = "https://files.pythonhosted.org/packages/1d/f2/1371707ce438ba9a43f9d24089828494ec6f9396e28cd7903aa704dd6306/pillow-13.0.0-cp314-cp314-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl", hash = "sha256:e91c2b1cbeae768c98752e67e717e283d68dae45717b41f2d91eaee648e37b7d", size = 7142574, upload-time = "2026-10-16T22:16:39.172Z" },
|
||||
{ url = "https://files.pythonhosted.org/packages/b9/a9/62cf68587f910bc87c5951bcb6e9430c7643a65076adf5f18b4bf350e2bd/pillow-13.0.0-cp314-cp314-musllinux_1_2_aarch64.whl", hash = "sha256:7f6299e494e46253d40c34653cac369412f44ca53b5f85d848d3f95b1ed0546c", size = 6614295, upload-time = "2026-10-16T22:16:41.117Z" },
|
||||
{ url = "https://files.pythonhosted.org/packages/6c/c9/9e9b48178649730299be0bafbf5f810a5b6977538f5a92d47e4ba5f5d608/pillow-13.0.0-cp314-cp314-musllinux_1_2_x86_64.whl", hash = "sha256:f9bd7d260d986f3553518c5d723544346fa48031f8aef3265d786aeb59845bc0", size = 7224841, upload-time = "2026-10-16T22:16:43.118Z" },
|
||||
{ url = "https://files.pythonhosted.org/packages/8f/48/c44e91384b1b6c072a714a63d00608acc16a6a968735e478e4be4384e5ac/pillow-13.0.0-cp314-cp314-win32.whl", hash = "sha256:2e31c4e68cffd7b1f116127626813b82fcba19edf6b940a7b0c266d6484d0055", size = 6508694, upload-time = "2026-10-16T22:16:45.883Z" },
|
||||
{ url = "https://files.pythonhosted.org/packages/50/e2/7ad17747517e4c813dca78257d6bb593466f8231baf1384bc98d92745edb/pillow-13.0.0-cp314-cp314-win_amd64.whl", hash = "sha256:f7cbb7a64e7ec664775195e4f81923bc8a93d9451b963f844e59118f63147a7a", size = 7281830, upload-time = "2026-10-16T22:16:47.725Z" },
|
||||
{ url = "https://files.pythonhosted.org/packages/41/9f/e5b51f2ce8ef4563215334035403ce61a244f93a2e65c24a940131618f87/pillow-13.0.0-cp314-cp314-win_arm64.whl", hash = "sha256:a6aaa7871aebca081eb5c45f83e845bbd9712ae99fa9286dbfdcee835e63f4b4", size = 2695468, upload-time = "2026-10-16T22:16:49.515Z" },
|
||||
{ url = "https://files.pythonhosted.org/packages/97/73/a53502f731f6c84805a4ce87a8881e86d07a65aee64728b900d112dc703e/pillow-13.0.0-cp314-cp314t-macosx_10_15_x86_64.whl", hash = "sha256:7b999816b5850a35ada08443e6e03945f1f6488144a83afe2d37b240a552aafa", size = 5578196, upload-time = "2026-10-16T22:16:51.291Z" },
|
||||
{ url = "https://files.pythonhosted.org/packages/21/50/7e949959a56b5559c78ef172b70fc6025706acb289f3f648a15329e4fa6f/pillow-13.0.0-cp314-cp314t-macosx_11_0_arm64.whl", hash = "sha256:67871a13cf47275201553b536c025da777f997fa562a19eb798af4ad4b97c18f", size = 4857276, upload-time = "2026-10-16T22:16:53.399Z" },
|
||||
{ url = "https://files.pythonhosted.org/packages/c9/52/43ded0ac08e77e39d17bd6d894162572201b5e8fdc4a022b14c55a1960a4/pillow-13.0.0-cp314-cp314t-manylinux_2_27_aarch64.manylinux_2_28_aarch64.whl", hash = "sha256:e8ca8f69b7c77fa96dad99f8638c1fc4f1c0bed4acaa1baf7a3c31bdb80a0ab1", size = 6607008, upload-time = "2026-10-16T22:16:55.525Z" },
|
||||
{ url = "https://files.pythonhosted.org/packages/0d/2e/4a57ed216d5bf877387cba4d44c02aa87abe51ad2e06404aa6b597c4da39/pillow-13.0.0-cp314-cp314t-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl", hash = "sha256:6bce6a29c3898191f4c9998e4d4e8f69790caeabde46e54da4bc235ce5bde683", size = 7224281, upload-time = "2026-10-16T22:16:57.738Z" },
|
||||
{ url = "https://files.pythonhosted.org/packages/5c/3d/2929b248e135752d63aaeabf53f6de797e905b7b6263f9c1e2adade20aba/pillow-13.0.0-cp314-cp314t-musllinux_1_2_aarch64.whl", hash = "sha256:816752a5ef76a80484c8c441c85593b7ea9304f6231fc5776ad1fbff7e773058", size = 6695600, upload-time = "2026-10-16T22:16:59.842Z" },
|
||||
{ url = "https://files.pythonhosted.org/packages/bc/33/fb0da992cf084ed1ee6ee05e96b6191e35c351eb707ca2df874feb24ce47/pillow-13.0.0-cp314-cp314t-musllinux_1_2_x86_64.whl", hash = "sha256:5bdb38ba220b61b4ec31dd1046dea6b016d3c6850a23f43ed8b58332b2fc668e", size = 7300589, upload-time = "2026-10-16T22:17:01.686Z" },
|
||||
{ url = "https://files.pythonhosted.org/packages/bb/af/c30dd9ef6a3dce84ecb1b2393cac629047a32e66279056c6cb46c3ffd65c/pillow-13.0.0-cp314-cp314t-win32.whl", hash = "sha256:06903aac074d00c988e77a1fc435286dc498506d4ca8d6f69df9babddf4ecc15", size = 6517204, upload-time = "2026-10-16T22:17:03.722Z" },
|
||||
{ url = "https://files.pythonhosted.org/packages/85/d5/ef3a8ae7609c8ab26570abf18194882534b480d245a9148b895a2262c004/pillow-13.0.0-cp314-cp314t-win_amd64.whl", hash = "sha256:9a635068d9793c7f0d929f39f18b58f1bd86c236e8e7b64167b86af9232ebca0", size = 7286695, upload-time = "2026-10-16T22:17:05.543Z" },
|
||||
{ url = "https://files.pythonhosted.org/packages/84/3c/0861db0c69a03689ebe3e7599d35668a414deb5aaafd8255215e4e62e3d3/pillow-13.0.0-cp314-cp314t-win_arm64.whl", hash = "sha256:0d1a9cf7bc6917538b20f8d06b9ab2147e542f68849e96fc58eb66bdf6acc692", size = 2698098, upload-time = "2026-10-16T22:17:07.674Z" },
|
||||
{ url = "https://files.pythonhosted.org/packages/6e/eb/e86a41962a3a31ad495a3d6a912d9002b01bba4a6fa71c28703abdca7f69/pillow-13.0.0-cp315-cp315-ios_13_0_arm64_iphoneos.whl", hash = "sha256:7d5e097eabd5d4915c27ac9f6e9325bb1e01a7c94d7348b5c4451d3fc30e8521", size = 4191213, upload-time = "2026-10-16T22:17:09.449Z" },
|
||||
{ url = "https://files.pythonhosted.org/packages/dd/04/7e7445e706afec84ef06dc25b2c77f9cecff242c23730c62928ad1089d4a/pillow-13.0.0-cp315-cp315-ios_13_0_arm64_iphonesimulator.whl", hash = "sha256:51ebb529fc5e8abdd55302f6c3f8943037348ec2384329a3e55677f69ae2fdfc", size = 4290650, upload-time = "2026-10-16T22:17:11.196Z" },
|
||||
{ url = "https://files.pythonhosted.org/packages/46/85/d534089068ac40c0f61f650389a296c812eab745a8a733f81feec39ae955/pillow-13.0.0-cp315-cp315-ios_13_0_x86_64_iphonesimulator.whl", hash = "sha256:c87a04e7f152ee4db5dbe15f0bfa3fe628a1aeedbe66b81c43b87f52c813f9ac", size = 3723078, upload-time = "2026-10-16T22:17:12.772Z" },
|
||||
{ url = "https://files.pythonhosted.org/packages/ce/2b/00b5c3b401df538b5dbe311d3899730fae5ba1e21cb8b80a128887ac6747/pillow-13.0.0-cp315-cp315-macosx_10_15_x86_64.whl", hash = "sha256:20722cd5375533ad754053363a80b8fb30c79d37930a6f7228030e237ce3bd5d", size = 5572292, upload-time = "2026-10-16T22:17:14.539Z" },
|
||||
{ url = "https://files.pythonhosted.org/packages/72/f5/a6b0610f946e9b54ae888ba7ad29d6e2f8d9b11f69e212d70416b7186c09/pillow-13.0.0-cp315-cp315-macosx_11_0_arm64.whl", hash = "sha256:04a63720f79e22fd54d897c233a68314c50ca0603360f54ce2bd5db8f0f43782", size = 4852222, upload-time = "2026-10-16T22:17:16.521Z" },
|
||||
{ url = "https://files.pythonhosted.org/packages/1e/d0/c0ff25bb0427ec70f32aac995453321fc3c4494a46c7292ff02d9d260b04/pillow-13.0.0-cp315-cp315-manylinux_2_27_aarch64.manylinux_2_28_aarch64.whl", hash = "sha256:4f8db54177035a2b5f717f94475b74907e12a96dc74f6d487f3966b0a4694071", size = 6527349, upload-time = "2026-10-16T22:17:18.534Z" },
|
||||
{ url = "https://files.pythonhosted.org/packages/85/11/e46fa0bcc0fc117f1eacc206b3d51f04d583fab328b4b740672d0438d83f/pillow-13.0.0-cp315-cp315-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl", hash = "sha256:8f36aa77f74b14a2103622b196402c71330e4e7cf4122ee45c854e9a01e0eecf", size = 7152873, upload-time = "2026-10-16T22:17:20.415Z" },
|
||||
{ url = "https://files.pythonhosted.org/packages/7c/53/2bdeca705f3a58679fa9201233193c86a30238340ca29b3a152c3fcc719b/pillow-13.0.0-cp315-cp315-musllinux_1_2_aarch64.whl", hash = "sha256:149a1c323ba366f90b48e6f1a6db6582eb50512df374588de56fc909abc0f0f3", size = 6626871, upload-time = "2026-10-16T22:17:22.361Z" },
|
||||
{ url = "https://files.pythonhosted.org/packages/14/de/3829030f209722ade3753bb456b805a0e7f885cf885b483407365c82e9ca/pillow-13.0.0-cp315-cp315-musllinux_1_2_x86_64.whl", hash = "sha256:e892354a424b1e82a78ba16785822bdd40de06f19446a3d4a28047df1a4f8932", size = 7236439, upload-time = "2026-10-16T22:17:24.352Z" },
|
||||
{ url = "https://files.pythonhosted.org/packages/44/b1/67fc37388382bc036a74f04da5bb6fcbf90ec3ac1f45893e06176c373fd3/pillow-13.0.0-cp315-cp315-win32.whl", hash = "sha256:8e459b613cf31f8980f584387b4fe47bf08e076e288d61aa8eba1f7fd4ddbb81", size = 6508688, upload-time = "2026-10-16T22:17:26.314Z" },
|
||||
{ url = "https://files.pythonhosted.org/packages/44/05/fdb6a79aee10861165526b41b7b440e36ee1ff58613b2fbefe3acbf06d4f/pillow-13.0.0-cp315-cp315-win_amd64.whl", hash = "sha256:d4737f50d23ddd11d6685faacbb9252887dde0bc7997127757247983d74399d6", size = 7281107, upload-time = "2026-10-16T22:17:28.198Z" },
|
||||
{ url = "https://files.pythonhosted.org/packages/e6/9c/6c6f7dc2a566467baf121394e83de25ac287cffe34cc030726beb4be0224/pillow-13.0.0-cp315-cp315-win_arm64.whl", hash = "sha256:2310e2adfc13c6d457d7d0f2ffdd5c56a74a317650cf765887df8d515a647ac0", size = 2695513, upload-time = "2026-10-16T22:17:30.013Z" },
|
||||
{ url = "https://files.pythonhosted.org/packages/23/16/e9120defdb8bff693b582d035312acc6f530cdc2bc5238a87f410efccd82/pillow-13.0.0-cp315-cp315t-macosx_10_15_x86_64.whl", hash = "sha256:21c32061a5512dc13f87cc7303e120e4d77c2f70df89a35af0e3ce246e5ac57f", size = 5578129, upload-time = "2026-10-16T22:17:31.642Z" },
|
||||
{ url = "https://files.pythonhosted.org/packages/47/22/76faf2bb2448f48a84cf894c1e2bb1090d7d2b1aa521ece131cb2f05d631/pillow-13.0.0-cp315-cp315t-macosx_11_0_arm64.whl", hash = "sha256:1c774b9c0ba0d0b356f71530677b39028878a2cae5a93e0a13779cfd17120f88", size = 4857428, upload-time = "2026-10-16T22:17:33.43Z" },
|
||||
{ url = "https://files.pythonhosted.org/packages/b3/64/0861ea4e03c50b14af9ed9dd8b9f388ab42f445c623a9fcbab19aef7aa55/pillow-13.0.0-cp315-cp315t-manylinux_2_27_aarch64.manylinux_2_28_aarch64.whl", hash = "sha256:20822140c9a2ba9c5e42df342b0a892ab2e102fc0e3db967a133bb9ce3f898bb", size = 6612582, upload-time = "2026-10-16T22:17:35.415Z" },
|
||||
{ url = "https://files.pythonhosted.org/packages/5c/20/cd1e9b3f60a9f3d5ebe46da36955c26004092a501f7f2c42f9fcc26611bc/pillow-13.0.0-cp315-cp315t-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl", hash = "sha256:ffea6b2986a797c84b6d1d27d4f43e0b83c73fc16281a930891cd237cf0d08fe", size = 7230176, upload-time = "2026-10-16T22:17:37.362Z" },
|
||||
{ url = "https://files.pythonhosted.org/packages/b6/ef/ffb0a2fc85690714fb7ac662956949645d57f15bf4426f520da361e7b6e3/pillow-13.0.0-cp315-cp315t-musllinux_1_2_aarch64.whl", hash = "sha256:05cd2cd39055d0b9650060e4513ef4a9a0aea870083950bd046a0d6490f93a22", size = 6703640, upload-time = "2026-10-16T22:17:39.313Z" },
|
||||
{ url = "https://files.pythonhosted.org/packages/e0/c2/6402ee3ccb3363aeed8fdb3f9fe56703ac5377a539f0b81b53999d7e121f/pillow-13.0.0-cp315-cp315t-musllinux_1_2_x86_64.whl", hash = "sha256:c6fd031333dedcad7ce3e03d244093f43504f209e86925ebdb2b868fa4037630", size = 7309231, upload-time = "2026-10-16T22:17:41.021Z" },
|
||||
{ url = "https://files.pythonhosted.org/packages/fc/96/d6b82e8b8c06ad143b66b12e0b31051e4bf489b4fabca1f390a14fe1ebde/pillow-13.0.0-cp315-cp315t-win32.whl", hash = "sha256:c50c80e3591e5cf9a8dfa6007d4f10732f02e32263850999286e56ccd650cfb2", size = 6517200, upload-time = "2026-10-16T22:17:42.886Z" },
|
||||
{ url = "https://files.pythonhosted.org/packages/60/d4/0062e6005e9b270b165015aafd343364ac378ec5a685431ea42baad33357/pillow-13.0.0-cp315-cp315t-win_amd64.whl", hash = "sha256:adb3c2124c68e480f4632d06cb7caa3b48a51678475f483b4edb1c6dee29ea43", size = 7287488, upload-time = "2026-10-16T22:17:45.56Z" },
|
||||
{ url = "https://files.pythonhosted.org/packages/e4/81/b8eb349746be7bce47dd95337c6634e84910af91b59aaa9159c034c614fa/pillow-13.0.0-cp315-cp315t-win_arm64.whl", hash = "sha256:4a25756244bdcce3b50580baadf320fa48297f0eeb8e114ba64139a40d4d0fc8", size = 2698073, upload-time = "2026-10-16T22:17:47.556Z" },
|
||||
{ url = "https://files.pythonhosted.org/packages/60/da/f6d644e631c5b370c5d0b899f3ccadd2780aab070b29a110527cf4e1fd2c/pillow-13.0.0-pp312-pypy312_pp80-macosx_10_15_x86_64.whl", hash = "sha256:8619685cad8efc4c38c66d3b36aad854523297c43d748b3b6f0cc03c90ba3463", size = 5523188, upload-time = "2026-10-16T22:17:59.334Z" },
|
||||
{ url = "https://files.pythonhosted.org/packages/e4/b0/2594f202d743a35d4fe80682bfd96f277e5ca7aecb27cf64ef5bfc1d000b/pillow-13.0.0-pp312-pypy312_pp80-macosx_11_0_arm64.whl", hash = "sha256:7e91e97a929232cdb828889ee6ad0e48d7f40f4ec38818f4e4a8968b2b1af22e", size = 4806808, upload-time = "2026-10-16T22:18:01.188Z" },
|
||||
{ url = "https://files.pythonhosted.org/packages/8e/ed/d504165ef79af6fafe25c76726cf30f544cc236002f7ed054f1d51adc4ff/pillow-13.0.0-pp312-pypy312_pp80-manylinux_2_27_aarch64.manylinux_2_28_aarch64.whl", hash = "sha256:93ff9c9c3663ce23aaa5d0b6b6abac55359e2a0c06c7e30f3771829af816be63", size = 5464358, upload-time = "2026-10-16T22:18:02.779Z" },
|
||||
{ url = "https://files.pythonhosted.org/packages/7b/fe/a10aba5503ca13e9e009b8bd0a1a4ce5584bdce246245fd6f3a83701369c/pillow-13.0.0-pp312-pypy312_pp80-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl", hash = "sha256:e65dd6e75de67b2362a4fa3e16aa627595f65054dc4ec73d64680c84d592fa61", size = 6043514, upload-time = "2026-10-16T22:18:04.538Z" },
|
||||
{ url = "https://files.pythonhosted.org/packages/c0/37/66b12dc476041fe523bca29c9d58fbf1ea92a4eaf73acfb9e993948f1191/pillow-13.0.0-pp312-pypy312_pp80-win_amd64.whl", hash = "sha256:567f20f1c75897d7663830da6ea8af719e03d712b1d9ee7f813319f9ece42e5a", size = 7366030, upload-time = "2026-10-16T22:18:06.638Z" },
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "pycparser"
|
||||
version = "3.1"
|
||||
@@ -378,6 +495,39 @@ wheels = [
|
||||
{ url = "https://files.pythonhosted.org/packages/fa/04/c81d4841331c2178b6fb09ae225425e110ed72d990c9fe556c4ec03d1013/pydantic_core-2.46.5-graalpy312-graalpy250_312_native-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:8e24d8f05fa2d28513d94e877e9c75ad66175376209b3977f916e240e623193c", size = 2111034, upload-time = "2026-08-28T10:01:07.345Z" },
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "python-dateutil"
|
||||
version = "2.9.0.post0"
|
||||
source = { registry = "https://pypi.org/simple" }
|
||||
dependencies = [
|
||||
{ name = "six" },
|
||||
]
|
||||
sdist = { url = "https://files.pythonhosted.org/packages/66/c0/0c8b6ad9f17a802ee498c46e004a0eb49bc148f2fd230864601a86dcf6db/python-dateutil-2.9.0.post0.tar.gz", hash = "sha256:37dd54208da7e1cd875388217d5e00ebd4179249f90fb72437e91a35459a0ad3", size = 342432, upload-time = "2024-03-01T18:36:20.211Z" }
|
||||
wheels = [
|
||||
{ url = "https://files.pythonhosted.org/packages/ec/57/56b9bcc3c9c6a792fcbaf139543cee77261f3651ca9da0c93f5c1221264b/python_dateutil-2.9.0.post0-py2.py3-none-any.whl", hash = "sha256:a8b2bc7bffae282281c8140a97d3aa9c14da0b136dfe83f850eea9a5f7470427", size = 229892, upload-time = "2024-03-01T18:36:18.57Z" },
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "s3transfer"
|
||||
version = "0.19.3"
|
||||
source = { registry = "https://pypi.org/simple" }
|
||||
dependencies = [
|
||||
{ name = "botocore" },
|
||||
]
|
||||
sdist = { url = "https://files.pythonhosted.org/packages/49/c5/0a5ce655109cb96b8dfad36908a4e108d15f5dc2eff8fbc3146c4312e704/s3transfer-0.19.3.tar.gz", hash = "sha256:8326acc3d056d7f7b8a37110c7d2aea41f67e83f6ae79cd3b5fbcca34c726406", size = 166087, upload-time = "2026-10-19T19:19:49.751Z" }
|
||||
wheels = [
|
||||
{ url = "https://files.pythonhosted.org/packages/e2/a4/88f9e10498759121060b8050a1554753dfc04df39bbbcc7aad9ecc8d9440/s3transfer-0.19.3-py3-none-any.whl", hash = "sha256:24eb7535804306355e31c952a90022bf5b2f9d760f9a11062c7493a217c08553", size = 90252, upload-time = "2026-10-19T19:19:48.309Z" },
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "six"
|
||||
version = "1.17.0"
|
||||
source = { registry = "https://pypi.org/simple" }
|
||||
sdist = { url = "https://files.pythonhosted.org/packages/94/e7/b2c673351809dca68a0e064b6af791aa332cf192da575fd474ed7d6f16a2/six-1.17.0.tar.gz", hash = "sha256:ff70335d468e7eb6ec65b95b99d3a2836546063f63acc5171de367e834932a81", size = 34031, upload-time = "2024-12-04T17:35:28.174Z" }
|
||||
wheels = [
|
||||
{ url = "https://files.pythonhosted.org/packages/b7/ce/149a00dd41f10bc29e5921b496af8b574d8413afcd5e30dfa0ed46c2cc5e/six-1.17.0-py2.py3-none-any.whl", hash = "sha256:4721f391ed90541fddacab5acf947aa0d3dc7d27b2e1e8eda2be8970586c3274", size = 11050, upload-time = "2024-12-04T17:35:26.475Z" },
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "starlette"
|
||||
version = "1.7.0"
|
||||
@@ -412,6 +562,15 @@ wheels = [
|
||||
{ url = "https://files.pythonhosted.org/packages/67/81/4add07e5172b7ac40d8ed5ff580409a7801a4fe26d529bdd915401dabfbe/typing_inspection-0.4.4-py3-none-any.whl", hash = "sha256:65b8397ba37ccbce054456aaccddfc91e6e3083c92824df348d96ca832f3f147", size = 14750, upload-time = "2026-08-12T12:37:24.648Z" },
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "urllib3"
|
||||
version = "2.8.0"
|
||||
source = { registry = "https://pypi.org/simple" }
|
||||
sdist = { url = "https://files.pythonhosted.org/packages/e3/05/b17359e1cefb4f909b5e40b1b90a496d987258916dbbf88e842c729f510e/urllib3-2.8.0.tar.gz", hash = "sha256:63bf2ead4c879426ebf22ef2a781eeb4aa3b4ae798a0435506f8687fd5bb9b63", size = 458972, upload-time = "2026-09-15T19:29:36.253Z" }
|
||||
wheels = [
|
||||
{ url = "https://files.pythonhosted.org/packages/92/9d/c4e665119135114480843e7ab388fa94d8480650450e6f8e26b70d323a4c/urllib3-2.8.0-py3-none-any.whl", hash = "sha256:0cf3cae568d36aa9576b28dfb35f11328f1cb974ca7647d9475ebb86c75ac6e3", size = 135717, upload-time = "2026-09-15T19:29:34.577Z" },
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "uvicorn"
|
||||
version = "0.40.0"
|
||||
|
||||
Reference in New Issue
Block a user