Files
polygon/README.md
T

96 lines
4.5 KiB
Markdown
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
# polygon v0.2.2
Эмулятор REST API облачной платформы Nubes для интеграционных тестов app-autotest.
Отдельный managed-сервис на Nubes pythonk8s: `polygon.pythonk8s.dev.nubes.ru`.
Притворяется реальным Nubes API (префикс `/api/v1/svc`).
## Архитектура
```
polygon/
├── requirements.txt # Flask>=3.0, gunicorn>=21.2, PyYAML>=6.0
├── tests/
│ ├── test_converter.py # 10 юнит-тестов from_stands.py
│ └── test_state_machine.py # 9 юнит-тестов state_machine.py
└── site/
├── app.py # Flask: только blueprint'ы + app.run() (57 строк)
├── routes/ # 6 blueprint-файлов по доменам
│ ├── root.py # /health, /
│ ├── services_routes.py# /api/v1/svc/services
│ ├── instances_routes.py# /api/v1/svc/instances
│ ├── operations_routes.py# /api/v1/svc/instanceOperations/*
│ ├── run.py # /api/v1/svc/instanceOperations/<uid>/run
│ └── mock_routes.py # /api/v1/svc/_mock/*
├── mock_state.py # MockState: instances, operations, op_params
├── state_machine.py # apply_effect() — мутация состояния
├── config/
│ └── loader.py # загрузка YAML + SERVICES/OPS_INDEX/DELAY/VERSION
├── utils/
│ ├── now.py # now() — UTC ISO с 'Z'
│ └── pluralize.py # pluralize() — плюрализация
├── from_stands.py # конвертер STANDS YAML → polygon config
├── static/
│ └── style.css # тёмная тема
├── templates/
│ └── index.html # Jinja2-шаблон
└── services/ # YAML-конфиги (сгенерированы from_stands.py)
```
**Ровно 1 gunicorn-воркер.** Состояние в памяти, не shared.
## Запуск
```bash
# Локально
cd site && python app.py # порт 5000
# Тесты
pytest tests/ -v # 19 тестов
# Генерация конфигов из STANDS YAML
cd site && python from_stands.py <STANDS_DIR> services/
```
## API (17 эндпоинтов)
| Метод | Путь | Назначение |
|-------|------|------------|
| GET | `/health` | Healthcheck |
| GET | `/` | HTML с версией |
| GET | `/api/v1/svc/services` | Список сервисов |
| GET | `/api/v1/svc/services/<id>` | Операции сервиса |
| GET | `/api/v1/svc/instances` | Пагинация |
| GET | `/api/v1/svc/instances/<uid>` | Инстанс + state |
| POST | `/api/v1/svc/instances` | Создать → 201 + Location |
| GET | `/api/v1/svc/instanceOperations/default/<id>` | cfsParams |
| POST | `/api/v1/svc/instanceOperations` | Создать операцию → 201 + Location |
| GET | `/api/v1/svc/instanceOperations/<uid>` | Статус + cfsParams |
| POST | `/api/v1/svc/instanceOperationCfsParams` | param → value |
| GET | `/api/v1/svc/instanceOperations/<uid>/validate-cfs` | 200, пустое тело |
| POST | `/api/v1/svc/instanceOperations/<uid>/run` | Выполнить |
| POST | `/api/v1/svc/_mock/reset` | Сброс |
| GET | `/api/v1/svc/_mock/state` | Отладка: состояние |
| GET | `/api/v1/svc/_mock/services` | Отладка: сервисы |
| POST | `/api/v1/svc/_mock/delay/<s>` | MOCK_OP_DELAY |
## Переменные окружения
| Переменная | По умолчанию | Описание |
|------------|-------------|----------|
| `MOCK_OP_DELAY` | `0.1` | Задержка операции в секундах |
| `WEB_CONCURRENCY` | `1` | ⛔ Не менять — ровно 1 воркер |
## Деплой
- Репозиторий: `https://gitea.services.ngcloud.ru/forcloud/polygon.git`
- URL: `https://polygon.pythonk8s.dev.nubes.ru/`
- Nubes pythonk8s managed service
## Связанные документы
- [DOCS/polygon-plan.md](../DOCS/polygon-plan.md) — план реализации
- [polygon-docs/sonnet-code-review-prompt.md](../polygon-docs/sonnet-code-review-prompt.md) — промпт code review
- [polygon-docs/tf-provider-refs.md](../polygon-docs/tf-provider-refs.md) — ссылки на генератор YAML