Compare commits
42
Commits
aff27e8f7b
...
v1.5.6
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
880d77810a | ||
|
|
8ebce28e34 | ||
|
|
dd7d43c2c2 | ||
|
|
a8c5e9701f | ||
|
|
be3d73f374 | ||
|
|
5fca165c69 | ||
|
|
293115e0e1 | ||
|
|
6d2051f813 | ||
|
|
b51a9ae3b3 | ||
|
|
4d4cd2301f | ||
|
|
d687881eaa | ||
|
|
87e756f34f | ||
|
|
27864fad58 | ||
|
|
dc5e777d07 | ||
|
|
23910c3393 | ||
|
|
0e90bbee4e | ||
|
|
55bc87cbc4 | ||
|
|
e68f034966 | ||
|
|
e06ee880b2 | ||
|
|
33fe8fdd18 | ||
|
|
6fa693156d | ||
|
|
5858d0889e | ||
|
|
bfe20c1fe0 | ||
|
|
c66cc9317d | ||
|
|
9ea4a68ccf | ||
|
|
8204105fd6 | ||
|
|
0c11ecfa48 | ||
|
|
ab8660ac42 | ||
|
|
ce747673fd | ||
|
|
e558570967 | ||
|
|
b6b081b04f | ||
|
|
13b4c20148 | ||
|
|
700d415422 | ||
|
|
6ca34b9008 | ||
|
|
bb334b10f5 | ||
|
|
4c23232c4e | ||
|
|
c263fd5c7e | ||
|
|
6bee5adc34 | ||
|
|
64516c316d | ||
|
|
ea65451160 | ||
|
|
250cdea35d | ||
|
|
1dd713514c |
No files matched your search
@@ -0,0 +1,3 @@
|
|||||||
|
{
|
||||||
|
"extends": ["@commitlint/config-conventional"]
|
||||||
|
}
|
||||||
@@ -0,0 +1,37 @@
|
|||||||
|
# Сгенерировать commit message (EvoBGP)
|
||||||
|
|
||||||
|
Сгенерируй сообщение коммита для **текущих staged-изменений**. Не выполняй `git commit`, если пользователь явно не просил закоммитить.
|
||||||
|
|
||||||
|
## Обязательный workflow (MUST)
|
||||||
|
|
||||||
|
1. Прочитай скилл [`.cursor/skills/commit-message/SKILL.md`](../skills/commit-message/SKILL.md).
|
||||||
|
2. Следуй правилу [`.cursor/rules/conventional-commits.mdc`](../rules/conventional-commits.mdc).
|
||||||
|
3. **Первым вызовом Shell** из корня репозитория:
|
||||||
|
|
||||||
|
```powershell
|
||||||
|
powershell -NoProfile -File scripts/commit/staged-context.ps1
|
||||||
|
```
|
||||||
|
|
||||||
|
4. Строй текст **только** по JSON stdout (`groups`, `stat`, `diff_excerpt`). Exit `1` → index пуст, сообщи пользователю.
|
||||||
|
5. **Запрещено** обходить скрипт через один `git diff --cached`.
|
||||||
|
|
||||||
|
## Формат вывода
|
||||||
|
|
||||||
|
Для каждого коммита (при auto-split — по одному блоку):
|
||||||
|
|
||||||
|
```
|
||||||
|
<type>(<scope>): <summary in English>
|
||||||
|
|
||||||
|
<тело на русском>
|
||||||
|
```
|
||||||
|
|
||||||
|
Плюс пояснение (RU): semver impact (`minor`|`patch`|`none`|`major`), почему выбран type, был ли split.
|
||||||
|
|
||||||
|
## Semver (кратко)
|
||||||
|
|
||||||
|
- Новая пользовательская возможность → `feat` (minor)
|
||||||
|
- Починка ожидаемого поведения / баг → `fix` (patch)
|
||||||
|
- Follow-up баги после недавнего `feat` в том же scope → **`fix`**, не `feat`
|
||||||
|
- Только перестройка без нового поведения → `refactor` (patch, без новых функций)
|
||||||
|
|
||||||
|
Заголовок — EN, императив, ≤72 символов. Тело — RU.
|
||||||
@@ -0,0 +1,178 @@
|
|||||||
|
---
|
||||||
|
description: >-
|
||||||
|
Conventional Commits EvoBGP. Триггеры commit/коммит/закоммить/staged/commit message —
|
||||||
|
ОБЯЗАТЕЛЬНО сначала Shell scripts/commit/staged-context.ps1, скилл commit-message.
|
||||||
|
alwaysApply: false
|
||||||
|
---
|
||||||
|
|
||||||
|
# Conventional Commits (EvoBGP)
|
||||||
|
|
||||||
|
Полное описание релизного пайплайна: [docs/releasing.md](../../docs/releasing.md).
|
||||||
|
|
||||||
|
## Триггеры (применить правило + скилл)
|
||||||
|
|
||||||
|
Любой запрос на коммит или сообщение коммита: `commit`, `коммит`, `закоммить`, `git commit`, `commit message`, `conventional commit`, `staged`, «сгенерируй коммит», **`/commit-message`** — в т.ч. если это указано в плане или [AGENTS.md](../../AGENTS.md).
|
||||||
|
|
||||||
|
### Не путать с кнопкой ✨ в Source Control
|
||||||
|
|
||||||
|
Команда **`cursor.generateGitCommitMessage`** (sparkle в поле commit message) **не** читает Rules, Skills и `staged-context.ps1` — только staged diff и история коммитов ([ограничение Cursor](https://forum.cursor.com/t/how-to-set-prompt-for-generate-commit-message/148606)).
|
||||||
|
|
||||||
|
**Замена для EvoBGP:** Agent → `/commit-message` или команда [`.cursor/commands/commit-message.md`](../commands/commit-message.md).
|
||||||
|
|
||||||
|
## Обязательный запуск скрипта (MUST)
|
||||||
|
|
||||||
|
1. Прочитать скилл [`.cursor/skills/commit-message/SKILL.md`](../skills/commit-message/SKILL.md).
|
||||||
|
2. **Первым действием** выполнить Shell (из корня репо):
|
||||||
|
|
||||||
|
```powershell
|
||||||
|
powershell -NoProfile -File scripts/commit/staged-context.ps1
|
||||||
|
```
|
||||||
|
|
||||||
|
3. Сообщение коммита строить **только** по JSON из stdout скрипта (`groups`, `diff_excerpt`, `stat`).
|
||||||
|
4. **Запрещено** генерировать commit message без успешного (exit 0) запуска скрипта; не заменять скрипт одним `git diff --cached`.
|
||||||
|
|
||||||
|
## Формат (строго)
|
||||||
|
|
||||||
|
```
|
||||||
|
<type>(<scope>): <short summary in English>
|
||||||
|
|
||||||
|
<тело на русском: что изменено и зачем>
|
||||||
|
```
|
||||||
|
|
||||||
|
- **Заголовок** — только английский; императив, без точки в конце; ≤72 символов.
|
||||||
|
- **Тело** — только русский; полные предложения; пустая строка после заголовка.
|
||||||
|
- Запрещены vague-сообщения: `fix bug`, `update code`, `wip`, `misc`.
|
||||||
|
|
||||||
|
## Типы (semantic-release)
|
||||||
|
|
||||||
|
| type | Когда | Версия |
|
||||||
|
|------|--------|--------|
|
||||||
|
| `feat` | **новая** пользовательская возможность (раньше нельзя было) | minor |
|
||||||
|
| `fix` | восстановление **ожидаемого** поведения; баг, регрессия, падение UI | patch |
|
||||||
|
| `perf` | ускорение без смены API | patch |
|
||||||
|
| `refactor` | реструктуризация **без** новой возможности и **без** исправления бага | patch |
|
||||||
|
| `docs` | только документация | — |
|
||||||
|
| `test` | тесты | — |
|
||||||
|
| `ci` | CI/CD (`.gitea/`, workflows); правки, из‑за которых нужны новые образы | patch |
|
||||||
|
| `chore` | обслуживание, deps, `.cursor/` | — |
|
||||||
|
|
||||||
|
### Выбор type: semver, а не «красивые слова»
|
||||||
|
|
||||||
|
**Главный вопрос:** что изменится для пользователя после релиза?
|
||||||
|
|
||||||
|
1. Появилось **новое** действие / экран / API / настройка, которых не было → `feat`
|
||||||
|
2. То, что **должно было работать**, не работало (кнопки, диалоги, сохранение, 500) → `fix`
|
||||||
|
3. Только перестройка кода или UI на другой паттерн, поведение для пользователя то же → `refactor` (patch, без новых функций)
|
||||||
|
4. Ускорение без изменения контракта → `perf`
|
||||||
|
|
||||||
|
**Не путать с формулировкой diff:**
|
||||||
|
|
||||||
|
| В diff / задаче часто пишут | Неверный type | Верный type, если… |
|
||||||
|
|-----------------------------|---------------|---------------------|
|
||||||
|
| enhance, improve, polish UI | `feat` | …только чиним сломанное после прошлого PR → `fix` |
|
||||||
|
| refactor pages, unify tables | `feat` | …новой возможности нет, лишь перенос на AppDataTable → `refactor` |
|
||||||
|
| follow-up после feat(web) | `feat` | …исправляем баги того же экрана → `fix` |
|
||||||
|
|
||||||
|
**Follow-up rule:** коммит сразу после `feat` в той же области, который **не добавляет** новую возможность, а устраняет дефект (effect loop, не открывается dialog, confirm не срабатывает) — **`fix`**, не `feat`.
|
||||||
|
|
||||||
|
**Split при смешанном diff:** новая страница/flow → `feat`; отдельным коммитом правки багов → `fix`. Не объединять в один `feat`.
|
||||||
|
|
||||||
|
**Breaking changes** — только `feat!` / `fix!` / `BREAKING CHANGE:` когда пользователь **обязан** менять конфиг, API или привычный workflow.
|
||||||
|
|
||||||
|
### Обязательно в пояснении агенту
|
||||||
|
|
||||||
|
При каждом предложении коммита указать:
|
||||||
|
|
||||||
|
- **Semver impact:** `minor` | `patch` | `none` | `major`
|
||||||
|
- **Почему не другой type** (одно предложение), если diff большой или формулировка двусмысленная
|
||||||
|
|
||||||
|
Пример неправильно / правильно:
|
||||||
|
|
||||||
|
```
|
||||||
|
# Плохо — patch-фикс, minor-bump
|
||||||
|
feat(web): enhance module entry dialogs and selection handling
|
||||||
|
|
||||||
|
# Хорошо
|
||||||
|
fix(web): stop effect loop breaking module action buttons
|
||||||
|
|
||||||
|
Исправлен effect_update_depth_exceeded и bind:open у Dialog; кнопки редактирования/удаления снова работают.
|
||||||
|
```
|
||||||
|
|
||||||
|
```
|
||||||
|
# Плохо — рефакторинг без новой фичи
|
||||||
|
feat(web): migrate modules list to AppDataTable
|
||||||
|
|
||||||
|
# Хорошо — если не было нового user-facing
|
||||||
|
refactor(web): migrate modules list to AppDataTable
|
||||||
|
|
||||||
|
Единый паттерн таблиц; поведение списка модулей без изменений. Semver: patch.
|
||||||
|
```
|
||||||
|
|
||||||
|
```
|
||||||
|
# Хорошо feat — действительно новое
|
||||||
|
feat(web): add module create dialog on /modules
|
||||||
|
|
||||||
|
Диалог создания модуля с POST /v1/modules; раньше создание было только через API.
|
||||||
|
```
|
||||||
|
|
||||||
|
## Breaking changes
|
||||||
|
|
||||||
|
- Заголовок: `feat!` / `fix!` **или** в теле строка `BREAKING CHANGE:` (на английском ключевое слово) + описание impact **на русском**.
|
||||||
|
|
||||||
|
## Scope (EvoBGP)
|
||||||
|
|
||||||
|
Выбирать по доминирующему пути из staged diff:
|
||||||
|
|
||||||
|
| Префикс | scope |
|
||||||
|
|---------|-------|
|
||||||
|
| `internal/httpapi/` | `httpapi` |
|
||||||
|
| `internal/store/`, `internal/repository/`, `internal/db/` | `store` |
|
||||||
|
| `internal/jobs/` | `jobs` |
|
||||||
|
| `internal/pipeline/` | `pipeline` |
|
||||||
|
| `internal/birdfmt/` | `birdfmt` |
|
||||||
|
| `internal/birddeploy/` | `birddeploy` |
|
||||||
|
| `internal/bundle/`, `internal/signing/` | `bundle` |
|
||||||
|
| `cmd/` | `cmd` |
|
||||||
|
| `web/` | `web` |
|
||||||
|
| `docs/openapi.yaml`, `redocly.yaml` | `openapi` |
|
||||||
|
| `docs/` (остальное) | `docs` |
|
||||||
|
| `migrations/` | `db` |
|
||||||
|
| `.gitea/` | `ci` |
|
||||||
|
| `deploy/` | `deploy` |
|
||||||
|
| `.cursor/` | `chore` |
|
||||||
|
| прочее в корне | `chore` |
|
||||||
|
|
||||||
|
`type` определять по **содержимому diff**, не только по пути.
|
||||||
|
|
||||||
|
## Multi-change
|
||||||
|
|
||||||
|
- Несвязанные области → **отдельные коммиты** (auto-split по скиллу).
|
||||||
|
- Одна логическая фича через несколько scope (OpenAPI + httpapi + web) → **один** коммит, scope по главной области.
|
||||||
|
|
||||||
|
## Обязательный вывод агенту
|
||||||
|
|
||||||
|
Для каждого коммита:
|
||||||
|
|
||||||
|
**1. Готовое сообщение** (копировать в `git commit -m` / HEREDOC):
|
||||||
|
|
||||||
|
```
|
||||||
|
<type>(<scope>): <summary>
|
||||||
|
|
||||||
|
<тело RU>
|
||||||
|
```
|
||||||
|
|
||||||
|
**2. Пояснение (RU):** semver impact (`minor`|`patch`|`none`|`major`); почему выбран type; риск/impact; был ли split.
|
||||||
|
|
||||||
|
## Примеры
|
||||||
|
|
||||||
|
```
|
||||||
|
feat(httpapi): add version endpoint and wire web footer
|
||||||
|
|
||||||
|
Добавлен GET /v1/version. В Web UI версия в footer берётся из API вместо захардкоженного значения.
|
||||||
|
```
|
||||||
|
|
||||||
|
```
|
||||||
|
fix(auth): correct token validation edge case
|
||||||
|
|
||||||
|
Исправлена ложная 401 при истёкшем refresh-токене с валидной сессией.
|
||||||
|
```
|
||||||
@@ -15,7 +15,7 @@ alwaysApply: true
|
|||||||
|
|
||||||
**ARCH-01** | MUST | Новая persistence-логика — метод `store.Backend` + реализации в `repository` и `store.Memory`; SQL не в `httpapi`.
|
**ARCH-01** | MUST | Новая persistence-логика — метод `store.Backend` + реализации в `repository` и `store.Memory`; SQL не в `httpapi`.
|
||||||
*Rationale:* единая абстракция данных.
|
*Rationale:* единая абстракция данных.
|
||||||
*Проверка:* grep SQL в `internal/httpapi` — отсутствие; review.
|
*Проверка:* CI `scripts/lint-httpapi.sh`; grep SQL в `internal/httpapi` — отсутствие.
|
||||||
|
|
||||||
**ARCH-02** | MUST | HTTP-маршруты только в `internal/httpapi`; регистрация через `http.ServeMux` с паттернами `METHOD /v1/...`.
|
**ARCH-02** | MUST | HTTP-маршруты только в `internal/httpapi`; регистрация через `http.ServeMux` с паттернами `METHOD /v1/...`.
|
||||||
*Rationale:* один слой REST.
|
*Rationale:* один слой REST.
|
||||||
@@ -75,7 +75,7 @@ alwaysApply: true
|
|||||||
|
|
||||||
**STYLE-05** | MUST | HTTP-ошибки — `writeProblem` / `writeJSON` (`application/problem+json` для 4xx/5xx).
|
**STYLE-05** | MUST | HTTP-ошибки — `writeProblem` / `writeJSON` (`application/problem+json` для 4xx/5xx).
|
||||||
*Rationale:* RFC 9457, OpenAPI.
|
*Rationale:* RFC 9457, OpenAPI.
|
||||||
*Проверка:* `problem.go`.
|
*Проверка:* `problem.go`; CI `scripts/lint-httpapi.sh` (5xx и 4xx store/cdn/csv).
|
||||||
|
|
||||||
**STYLE-06** | MUST | JSON полей HTTP DTO согласованы с `docs/openapi.yaml`.
|
**STYLE-06** | MUST | JSON полей HTTP DTO согласованы с `docs/openapi.yaml`.
|
||||||
*Rationale:* контракт API.
|
*Rationale:* контракт API.
|
||||||
@@ -123,7 +123,7 @@ alwaysApply: true
|
|||||||
**TEST-03** | MUST | Новые BIRD-сценарии в `internal/birdfmt/testdata/scenarios/*/bird.conf` + `bird -p`.
|
**TEST-03** | MUST | Новые BIRD-сценарии в `internal/birdfmt/testdata/scenarios/*/bird.conf` + `bird -p`.
|
||||||
*Проверка:* CI job `bird2`.
|
*Проверка:* CI job `bird2`.
|
||||||
|
|
||||||
**TEST-04** | MUST | Изменения `web/` — локально `npm run check` и `npm run lint` (CI web пока не в scope).
|
**TEST-04** | MUST | Изменения `web/` — локально `npm run check` и `npm run lint`; CI job `web` в `.gitea/workflows/ci.yaml`.
|
||||||
*Проверка:* локальные команды.
|
*Проверка:* локальные команды.
|
||||||
|
|
||||||
**TEST-05** | MUST | Изменения OpenAPI — `npx @redocly/cli lint docs/openapi.yaml`.
|
**TEST-05** | MUST | Изменения OpenAPI — `npx @redocly/cli lint docs/openapi.yaml`.
|
||||||
@@ -234,7 +234,9 @@ npx @redocly/cli lint docs/openapi.yaml
|
|||||||
# birdfmt: go test ./internal/birdfmt/... -count=1
|
# birdfmt: go test ./internal/birdfmt/... -count=1
|
||||||
```
|
```
|
||||||
|
|
||||||
**Рекомендуется (не внедрено):** CI job `web`; `.golangci.yml`; pre-commit gofmt/prettier.
|
**CI (Gitea):** job `web` (check + lint); job `go`: `go vet`, `scripts/lint-httpapi.sh` (ARCH-01, ERR-01), `scripts/check-migrations-pair.sh` (DEP-03), `golangci-lint`, `go test -race`, build `cmd/*`.
|
||||||
|
|
||||||
|
**Рекомендуется локально:** `.golangci.yml`; `.pre-commit-config.yaml` (gofmt + prettier web).
|
||||||
|
|
||||||
**Только code review:** слои SQL; роли; idempotency; OpenAPI bodies; secrets в compose.
|
**Только code review:** слои SQL; роли; idempotency; OpenAPI bodies; secrets в compose.
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,143 @@
|
|||||||
|
---
|
||||||
|
name: commit-message
|
||||||
|
description: >-
|
||||||
|
ОБЯЗАТЕЛЬНО при commit, коммит, закоммить, commit message, conventional commit,
|
||||||
|
staged, semantic-release, «сгенерируй коммит», git commit, /commit-message: ПЕРВЫМ
|
||||||
|
делом Shell — scripts/commit/staged-context.ps1; затем Conventional Commit (заголовок EN, тело RU).
|
||||||
|
---
|
||||||
|
|
||||||
|
> **Кнопка ✨ Generate commit message в Source Control** не использует этот скилл и Rules.
|
||||||
|
> Эквивалент: Agent Chat → **`/commit-message`** или «сгенерируй коммит по staged».
|
||||||
|
> См. [docs/README.md](../../docs/README.md#сообщения-коммитов-cursor).
|
||||||
|
|
||||||
|
# Commit message (EvoBGP)
|
||||||
|
|
||||||
|
## Когда применять (сразу читать этот скилл)
|
||||||
|
|
||||||
|
Триггеры в промпте пользователя или в плане/AGENTS.md:
|
||||||
|
|
||||||
|
- `commit`, `коммит`, `закоммить`, `commit message`, `conventional commit`
|
||||||
|
- `git commit`, `staged`, `сообщение коммита`, `сгенерируй коммит`
|
||||||
|
- агент собирается выполнить `git commit` или предложить текст коммита
|
||||||
|
|
||||||
|
## Шаг 0 — ОБЯЗАТЕЛЬНО (до любого текста коммита)
|
||||||
|
|
||||||
|
**Первый вызов инструментов** в этой задаче — Shell из корня репозитория:
|
||||||
|
|
||||||
|
```powershell
|
||||||
|
powershell -NoProfile -File scripts/commit/staged-context.ps1
|
||||||
|
```
|
||||||
|
|
||||||
|
| Правило | Деталь |
|
||||||
|
|---------|--------|
|
||||||
|
| **MUST** | Запустить скрипт до генерации заголовка/тела коммита |
|
||||||
|
| **MUST NOT** | Строить сообщение только по `git diff --cached` / `git status` без скрипта |
|
||||||
|
| **MUST NOT** | Пропускать скрипт, даже если diff «и так понятен» |
|
||||||
|
| Exit `1` | Index пуст — сообщить пользователю, **не коммитить** |
|
||||||
|
| Exit `0` | Разобрать JSON stdout: `staged_count`, `groups[]` (`scope`, `files`, `stat`, `diff_excerpt`) |
|
||||||
|
|
||||||
|
Дополнительно: [.cursor/rules/conventional-commits.mdc](../../rules/conventional-commits.mdc).
|
||||||
|
|
||||||
|
## Слияние групп (одна фича)
|
||||||
|
|
||||||
|
Скрипт группирует **только по путям**. Перед split проверьте логическую связность:
|
||||||
|
|
||||||
|
**Объединить в один коммит**, если это одна задача:
|
||||||
|
|
||||||
|
- `docs/openapi.yaml` + `internal/httpapi/` (+ опционально `web/`) — один endpoint/контракт;
|
||||||
|
- `migrations/` + `internal/store/` / `repository/` — одна схема;
|
||||||
|
- правки теста рядом с кодом той же фичи.
|
||||||
|
|
||||||
|
При объединении: один scope (доминирующий пакет, часто `httpapi` или `openapi`), один type, одно тело RU.
|
||||||
|
|
||||||
|
**Auto-split** — если группы **не связаны** (например `web/` + `internal/birdfmt/` без общего смысла): **отдельный коммит на группу**, без вопроса пользователю.
|
||||||
|
|
||||||
|
## Порядок коммитов при split
|
||||||
|
|
||||||
|
1. `openapi`
|
||||||
|
2. `httpapi`, `store`, `jobs`
|
||||||
|
3. `pipeline`, `birdfmt`, `birddeploy`, `bundle`
|
||||||
|
4. `web`
|
||||||
|
5. `ci`, `deploy`, `db`
|
||||||
|
6. `docs`
|
||||||
|
7. `chore`, `cmd`
|
||||||
|
|
||||||
|
## Алгоритм auto-split (уровень файлов)
|
||||||
|
|
||||||
|
1. `git status` и `git diff --cached --stat` — зафиксировать полный список staged-файлов.
|
||||||
|
2. `git reset HEAD` — снять всё из index (working tree не трогать).
|
||||||
|
3. Для каждой (объединённой) группы по порядку выше:
|
||||||
|
- `git add -- <paths…>`
|
||||||
|
- Сгенерировать сообщение по правилу conventional-commits.
|
||||||
|
- Закоммитить (см. ниже).
|
||||||
|
4. После всех коммитов — `git status` для проверки.
|
||||||
|
|
||||||
|
**Ограничение:** частичный stage одного файла с разной семантикой — предупредить; split по hunk'ам не делать; предложить разнести правки по файлам.
|
||||||
|
|
||||||
|
## Создание коммита
|
||||||
|
|
||||||
|
Только если пользователь **явно** просил закоммитить. Иначе — только вывести готовые сообщения.
|
||||||
|
|
||||||
|
```powershell
|
||||||
|
git commit -m "$( @'
|
||||||
|
<type>(<scope>): <summary in English>
|
||||||
|
|
||||||
|
<Тело на русском.>
|
||||||
|
'@ )"
|
||||||
|
```
|
||||||
|
|
||||||
|
В PowerShell для многострочного тела используйте here-string как выше или `-m` для заголовка и `-m` для тела.
|
||||||
|
|
||||||
|
Перед коммитом: `git status`, `git diff --cached` для группы — убедиться, что stage соответствует сообщению.
|
||||||
|
|
||||||
|
## Генерация текста
|
||||||
|
|
||||||
|
По `groups[].diff_excerpt`, `stat`, `files`:
|
||||||
|
|
||||||
|
### Шаг A — semver (до выбора type)
|
||||||
|
|
||||||
|
| Вопрос | Если «да» → |
|
||||||
|
|--------|-------------|
|
||||||
|
| Пользователь получает **новую** возможность? | `feat` (minor) |
|
||||||
|
| Восстанавливается **ожидаемое** поведение / устранён баг? | `fix` (patch) |
|
||||||
|
| Только скорость, контракт тот же? | `perf` (patch) |
|
||||||
|
| Только структура кода/UI, поведение то же? | `refactor` (patch) |
|
||||||
|
|
||||||
|
**Follow-up:** правки сразу после `feat` в том же scope без новой возможности → **`fix`**, не `feat` (слова *enhance/improve/refactor* в задаче не делают commit `feat`).
|
||||||
|
|
||||||
|
**Запрещено** по умолчанию ставить `feat` для «большого diff» в `web/` — type по **semver impact**, не по объёму.
|
||||||
|
|
||||||
|
### Шаг B — type, scope, текст
|
||||||
|
|
||||||
|
- **type** — результат шага A, не «chore по умолчанию» и не `feat` из-за слова enhance.
|
||||||
|
- **scope** — из JSON группы или доминирующий при merge.
|
||||||
|
- **summary** — конкретный, английский, императив; для `fix` — что **починено** (`fix broken …`, `prevent … loop`).
|
||||||
|
- **body** — русский: что, зачем, edge cases, breaking impact.
|
||||||
|
|
||||||
|
## Вывод пользователю
|
||||||
|
|
||||||
|
Для **каждого** коммита:
|
||||||
|
|
||||||
|
### 1. Готовое сообщение
|
||||||
|
|
||||||
|
```
|
||||||
|
<type>(<scope>): <summary>
|
||||||
|
|
||||||
|
<тело>
|
||||||
|
```
|
||||||
|
|
||||||
|
### 2. Пояснение (RU)
|
||||||
|
|
||||||
|
- **Semver impact:** `minor` | `patch` | `none` | `major` — и почему не другой type.
|
||||||
|
- Риски и impact.
|
||||||
|
- Split: сколько коммитов и почему.
|
||||||
|
|
||||||
|
## Не смешивать
|
||||||
|
|
||||||
|
Один commit message — одна primary intent. Не объединять несвязанный `fix` и `feat` в один заголовок.
|
||||||
|
|
||||||
|
## Ссылки
|
||||||
|
|
||||||
|
- Правило: `.cursor/rules/conventional-commits.mdc`
|
||||||
|
- Скрипт: `scripts/commit/staged-context.ps1`
|
||||||
|
- Просмотр групп: `powershell -File scripts/commit/staged-context.ps1 | ConvertFrom-Json`
|
||||||
+29
-51
@@ -1,75 +1,53 @@
|
|||||||
# Gitea Actions
|
# Gitea Actions
|
||||||
|
|
||||||
В репозитории включён workflow [workflows/ci.yaml](workflows/ci.yaml).
|
Workflow: [workflows/ci.yaml](workflows/ci.yaml).
|
||||||
|
|
||||||
Job **changes** вычисляет два флага:
|
| Job | PR | push в main |
|
||||||
|
|-----|-----|-------------|
|
||||||
|
| changes, openapi, web, go, bird2 | quality gates | quality gates |
|
||||||
|
| commitlint | да | — |
|
||||||
|
| **release** | — | semantic-release + docker push (один run) |
|
||||||
|
|
||||||
- **`openapi`** — в диффе есть `docs/openapi.yaml` или `redocly.yaml` → запускается **openapi** (Redocly lint).
|
Подробнее: [docs/releasing.md](../docs/releasing.md).
|
||||||
- **`code`** — в диффе есть **хотя бы один файл вне «только документация»** → запускаются **go**, **bird2** и при push в main/master **docker-images**.
|
|
||||||
|
|
||||||
Если изменены **только** файлы из списка ниже, **`code=false`**: Go-тесты, bird2 и сборка образов **не** запускаются; при необходимости всё ещё выполняется **openapi**, если трогали OpenAPI или `redocly.yaml`.
|
## CI (quality gates)
|
||||||
|
|
||||||
**Список путей «только документация» (без полной сборки):** всё под `docs/`, корневой `README.md`, `web/README.md`, `.gitea/README.md`, `redocly.yaml`.
|
Job **changes** вычисляет флаги по путям в diff. Полный прогон (все узлы openapi / web / go / bird2 в графе): `.gitea/workflows/*`, `scripts/*`, `.golangci.yml`, `.pre-commit-config.yaml`, корневой `package.json` / `.releaserc.json`. Отдельно: `migrations/*`, `docs/openapi.yaml` → `go` / `openapi` и т.д. (см. `ci.yaml`).
|
||||||
|
|
||||||
Любой другой путь (в т.ч. `.gitea/workflows/ci.yaml`, `go.mod`, `web/package.json`, `deploy/**`, `**/*.go`) включает полный пайплайн.
|
На **pull request** — **commitlint** (Conventional Commits).
|
||||||
|
|
||||||
Требования к runner:
|
Runner: `ubuntu-latest`, **bird2** из apt, Docker для job **release**.
|
||||||
|
|
||||||
- Метка `ubuntu-latest` (или измените `runs-on` под свои labels).
|
## Release (job в ci.yaml)
|
||||||
- Job `bird2` ставит пакет **bird2** из репозитория **Ubuntu** на runner (как образ `evobgp-bird2` на `ubuntu:noble`) и вызывает `bird -c … -p` по файлам в checkout (без вложенного Docker: иначе bind-mount `/workspace/...` часто не виден демону Docker на хосте).
|
|
||||||
- Job **docker-images** требует **Docker** и (для push) доступ к Container Registry Gitea с runner’а.
|
|
||||||
|
|
||||||
## Сборка и публикация образов (`docker-images`)
|
После успешных quality gates на **push в main** job **release**:
|
||||||
|
|
||||||
Запускается только при **push** в ветки `main` или `master` (после успешного job `go`). Собираются образы из `deploy/docker/*` (все бинарники через `gobinary`, плюс `evobgp-web`, `evobgp-agent`, `evobgp-bird2`).
|
1. `npx semantic-release` — тег `vX.Y.Z` на **текущий commit** (без дополнительного commit в main).
|
||||||
|
2. Gitea Release + `CHANGELOG.md` как attachment (не в git).
|
||||||
|
3. `docker buildx bake default --push` с `VERSION=X.Y.Z` — в том же job.
|
||||||
|
|
||||||
### Секреты репозитория (для push в реестр)
|
Если releasable-коммитов нет — semantic-release no-op, образы не публикуются.
|
||||||
|
|
||||||
Хост Container Registry в workflow **зашит**: **`git.shts.su`** (`docker/login-action` и теги образов).
|
### Секреты
|
||||||
|
|
||||||
В настройках репозитория Gitea: **Settings → Actions → Secrets** (или аналог):
|
**`ACTIONS_PAT`**: push tags, releases, Container Registry. Fallback: **`gitea.token`**.
|
||||||
|
|
||||||
| Секрет | Назначение |
|
### Теги образов
|
||||||
|--------|------------|
|
|
||||||
| `ACTIONS_PAT` | (Опционально) PAT с правом **записи пакетов**. Если не задан, для `docker login` используется **`gitea.token`** (нужны права у workflow на пакеты). |
|
|
||||||
|
|
||||||
Вход в реестр в workflow:
|
|
||||||
|
|
||||||
- **registry:** `git.shts.su`;
|
|
||||||
- **username:** `${{ gitea.actor }}`;
|
|
||||||
- **password:** `${{ secrets.ACTIONS_PAT || gitea.token }}`.
|
|
||||||
|
|
||||||
### Почему шаг «Log in to Gitea Registry» мог быть skipped
|
|
||||||
|
|
||||||
Раньше в `if:` стояло **`secrets.ACTIONS_PAT != ''`**. В **Gitea act_runner** такая проверка секрета в условии шага часто **всегда ложна**, из‑за этого логин **всегда skipped**. Сейчас условие только `docker_push == 'true'` (всегда при нормальном шаге **Prepare**), пароль: **`secrets.ACTIONS_PAT || gitea.token`**.
|
|
||||||
|
|
||||||
Если после правки `docker login` падает с 401/403 — выдайте job-токену или PAT право **записи в Container Registry** (в настройках Gitea / организации / репозитория, в зависимости от версии).
|
|
||||||
|
|
||||||
Если **`gitea.token`** в выражениях недоступен, в [ci.yaml](workflows/ci.yaml) замените пароль на `${{ secrets.ACTIONS_PAT || github.token }}`.
|
|
||||||
|
|
||||||
### Имена образов и теги
|
|
||||||
|
|
||||||
Формат:
|
|
||||||
|
|
||||||
```text
|
```text
|
||||||
git.shts.su/<owner_lowercase>/<имя>:<тег>
|
git.shts.su/<owner>/<имя>:latest
|
||||||
|
git.shts.su/<owner>/<имя>:v1.2.3
|
||||||
|
git.shts.su/<owner>/<имя>:1.2.3
|
||||||
|
git.shts.su/<owner>/<имя>:<short-sha>
|
||||||
|
git.shts.su/<owner>/<имя>:sha-<full-sha>
|
||||||
```
|
```
|
||||||
|
|
||||||
где `<имя>` — одно из: `evobgp-api`, `evobgp-all`, `evobgp-scheduler`, `evobgp-ingest`, `evobgp-render`, `evobgp-deploy`, `evobgp-node`, `evobgp-web`, `evobgp-web-all` (UI с прокси на `evobgp-all` для профиля Compose `microvps-full`), `evobgp-agent`, `evobgp-bird2`.
|
Имена образов: `evobgp-api`, `evobgp-all`, `evobgp-scheduler`, `evobgp-ingest`, `evobgp-render`, `evobgp-deploy`, `evobgp-node`, `evobgp-web`, `evobgp-web-all`, `evobgp-agent`, `evobgp-bird2`.
|
||||||
|
|
||||||
Теги: `latest`, короткий SHA (7 символов), `sha-<полный_commit_sha>`.
|
Пример:
|
||||||
|
|
||||||
Пример pull:
|
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
docker pull git.shts.su/myuser/evobgp-api:latest
|
docker pull git.shts.su/myuser/evobgp-api:1.2.3
|
||||||
```
|
```
|
||||||
|
|
||||||
Полная таблица образов, тегов, ссылок на страницы пакетов в Gitea и минимальный `docker run` для сервера без сборки — в [docs/quickstart.md](../docs/quickstart.md) (раздел «Готовые образы без сборки»).
|
См. [deploy/docker/README.md](../deploy/docker/README.md), [docs/quickstart.md](../docs/quickstart.md).
|
||||||
|
|
||||||
Убедитесь, что в **Gitea** включены пакеты (Container Registry) и у токена есть права на создание/обновление образов. Другой хост реестра — правьте **`registry:`** и префикс **`IMG=`** в [ci.yaml](workflows/ci.yaml).
|
|
||||||
|
|
||||||
### Примечания
|
|
||||||
|
|
||||||
- Сборка с платформой `linux/amd64`. При необходимости добавьте `linux/arm64` и multi-arch в `docker buildx build`.
|
|
||||||
- Для PR job **docker-images** не выполняется (только push в main/master), чтобы не публиковать образы из чужих форков без явной политики.
|
|
||||||
+164
-128
@@ -8,10 +8,9 @@ on:
|
|||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
# ---------------------------------------------------------------------------
|
# ---------------------------------------------------------------------------
|
||||||
# Гранулярная детекция изменений по модулям.
|
# Детекция изменений по модулям (флаги → downstream-джобы в графе CI).
|
||||||
# Каждый флаг соответствует группе файлов; downstream-джобы запускаются
|
# Полный прогон (все флаги true): .gitea/workflows/*, scripts/*, .golangci.yml,
|
||||||
# только когда их группа затронута. Изменение CI-конфигурации (.gitea/workflows/*)
|
# .pre-commit-config.yaml — чтобы при правках CI/CD пересобирались все узлы.
|
||||||
# поднимает все флаги, чтобы гарантировать полный прогон.
|
|
||||||
# ---------------------------------------------------------------------------
|
# ---------------------------------------------------------------------------
|
||||||
changes:
|
changes:
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
@@ -40,6 +39,23 @@ jobs:
|
|||||||
docker_web=false
|
docker_web=false
|
||||||
docker_bird=false
|
docker_bird=false
|
||||||
|
|
||||||
|
# Все флаги true → openapi, web, go, bird2 (и release на main) в графе CI.
|
||||||
|
set_all_flags_true() {
|
||||||
|
openapi=true
|
||||||
|
go=true
|
||||||
|
web=true
|
||||||
|
bird_conf=true
|
||||||
|
docker_go=true
|
||||||
|
docker_web=true
|
||||||
|
docker_bird=true
|
||||||
|
}
|
||||||
|
|
||||||
|
write_outputs() {
|
||||||
|
for v in openapi go web bird_conf docker_go docker_web docker_bird; do
|
||||||
|
eval "echo \"\$v=\$$v\"" >> "$GITHUB_OUTPUT"
|
||||||
|
done
|
||||||
|
}
|
||||||
|
|
||||||
if [ "${{ github.event_name }}" = "pull_request" ]; then
|
if [ "${{ github.event_name }}" = "pull_request" ]; then
|
||||||
base="${{ github.event.pull_request.base.sha }}"
|
base="${{ github.event.pull_request.base.sha }}"
|
||||||
head="${{ github.event.pull_request.head.sha }}"
|
head="${{ github.event.pull_request.head.sha }}"
|
||||||
@@ -52,61 +68,84 @@ jobs:
|
|||||||
elif git rev-parse --verify HEAD~1 >/dev/null 2>&1; then
|
elif git rev-parse --verify HEAD~1 >/dev/null 2>&1; then
|
||||||
FILES="$(git diff --name-only HEAD~1 HEAD)"
|
FILES="$(git diff --name-only HEAD~1 HEAD)"
|
||||||
else
|
else
|
||||||
openapi=true; go=true; web=true; bird_conf=true
|
set_all_flags_true
|
||||||
docker_go=true; docker_web=true; docker_bird=true
|
write_outputs
|
||||||
for v in openapi go web bird_conf docker_go docker_web docker_bird; do
|
echo "No parent commit — full pipeline (all modules)"
|
||||||
echo "$v=true" >> "$GITHUB_OUTPUT"
|
|
||||||
done
|
|
||||||
echo "No parent commit — full pipeline"
|
|
||||||
exit 0
|
exit 0
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if [ -z "$(printf '%s' "$FILES" | tr -d '[:space:]')" ]; then
|
if [ -z "$(printf '%s' "$FILES" | tr -d '[:space:]')" ]; then
|
||||||
go=true; web=true
|
set_all_flags_true
|
||||||
for v in openapi go web bird_conf docker_go docker_web docker_bird; do
|
write_outputs
|
||||||
eval "echo \"\$v=\$$v\"" >> "$GITHUB_OUTPUT"
|
echo "Empty diff — full pipeline fallback"
|
||||||
done
|
|
||||||
echo "Empty diff — safe fallback: go=true web=true"
|
|
||||||
exit 0
|
exit 0
|
||||||
fi
|
fi
|
||||||
|
|
||||||
ci_changed=false
|
full_pipeline=false
|
||||||
|
|
||||||
while IFS= read -r f || [ -n "${f:-}" ]; do
|
while IFS= read -r f || [ -n "${f:-}" ]; do
|
||||||
[ -z "${f:-}" ] && continue
|
[ -z "${f:-}" ] && continue
|
||||||
case "$f" in
|
case "$f" in
|
||||||
.gitea/workflows/*) ci_changed=true ;;
|
# CI/CD инфраструктура — все узлы quality gates
|
||||||
docs/openapi.yaml|redocly.yaml) openapi=true ;;
|
.gitea/workflows/*|.golangci.yml|.pre-commit-config.yaml|scripts/*)
|
||||||
web/README.md) ;; # doc-only
|
full_pipeline=true
|
||||||
web/*) web=true ;;
|
;;
|
||||||
deploy/bird/*) bird_conf=true ;;
|
docs/openapi.yaml|redocly.yaml)
|
||||||
deploy/docker/bird/*) docker_bird=true; docker_go=true ;;
|
openapi=true
|
||||||
deploy/docker/gobinary/*) docker_go=true ;;
|
;;
|
||||||
deploy/docker/docker-bake.hcl) docker_go=true; docker_web=true ;;
|
docs/api.md|docs/access.md)
|
||||||
deploy/docker/evobgp-agent/*) docker_go=true ;;
|
openapi=true
|
||||||
deploy/docker/evobgp-web/*) docker_web=true ;;
|
go=true
|
||||||
deploy/docker/bird2/*) docker_bird=true ;;
|
;;
|
||||||
go.mod|go.sum|go.work) go=true ;;
|
web/README.md|web/components.json)
|
||||||
*.go) go=true ;;
|
;;
|
||||||
cmd/*|internal/*) go=true ;;
|
web/*)
|
||||||
|
web=true
|
||||||
|
;;
|
||||||
|
deploy/bird/*)
|
||||||
|
bird_conf=true
|
||||||
|
go=true
|
||||||
|
;;
|
||||||
|
deploy/compose/*|deploy/docker/*)
|
||||||
|
docker_go=true
|
||||||
|
docker_web=true
|
||||||
|
docker_bird=true
|
||||||
|
go=true
|
||||||
|
;;
|
||||||
|
go.mod|go.sum|go.work)
|
||||||
|
go=true
|
||||||
|
;;
|
||||||
|
migrations/*)
|
||||||
|
go=true
|
||||||
|
;;
|
||||||
|
cmd/*|internal/*|*.go)
|
||||||
|
go=true
|
||||||
|
bird_conf=true
|
||||||
|
;;
|
||||||
|
docs/*)
|
||||||
|
go=true
|
||||||
|
;;
|
||||||
|
package.json|package-lock.json|.releaserc.json)
|
||||||
|
full_pipeline=true
|
||||||
|
;;
|
||||||
|
*)
|
||||||
|
go=true
|
||||||
|
;;
|
||||||
esac
|
esac
|
||||||
done <<< "$FILES"
|
done <<< "$FILES"
|
||||||
|
|
||||||
if $ci_changed; then
|
if $full_pipeline; then
|
||||||
go=true; web=true; bird_conf=true
|
set_all_flags_true
|
||||||
docker_go=true; docker_web=true; docker_bird=true
|
|
||||||
fi
|
fi
|
||||||
|
|
||||||
for v in openapi go web bird_conf docker_go docker_web docker_bird; do
|
write_outputs
|
||||||
eval "echo \"\$v=\$$v\"" >> "$GITHUB_OUTPUT"
|
|
||||||
done
|
|
||||||
|
|
||||||
echo "Changed files (first 30):"
|
echo "Changed files (first 30):"
|
||||||
printf '%s\n' "$FILES" | head -n 30
|
printf '%s\n' "$FILES" | head -n 30
|
||||||
echo "--- flags ---"
|
echo "--- flags ---"
|
||||||
echo "openapi=$openapi go=$go web=$web bird_conf=$bird_conf"
|
echo "openapi=$openapi go=$go web=$web bird_conf=$bird_conf"
|
||||||
echo "docker_go=$docker_go docker_web=$docker_web docker_bird=$docker_bird ci=$ci_changed"
|
echo "docker_go=$docker_go docker_web=$docker_web docker_bird=$docker_bird full_pipeline=$full_pipeline"
|
||||||
|
|
||||||
# ---------------------------------------------------------------------------
|
# ---------------------------------------------------------------------------
|
||||||
openapi:
|
openapi:
|
||||||
@@ -121,6 +160,26 @@ jobs:
|
|||||||
- name: Lint OpenAPI (Redocly)
|
- name: Lint OpenAPI (Redocly)
|
||||||
run: npx --yes @redocly/cli@1 lint docs/openapi.yaml
|
run: npx --yes @redocly/cli@1 lint docs/openapi.yaml
|
||||||
|
|
||||||
|
# ---------------------------------------------------------------------------
|
||||||
|
web:
|
||||||
|
needs: [changes]
|
||||||
|
if: needs.changes.outputs.web == 'true'
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
steps:
|
||||||
|
- uses: actions/checkout@v4
|
||||||
|
- uses: actions/setup-node@v4
|
||||||
|
with:
|
||||||
|
node-version: "20"
|
||||||
|
cache: npm
|
||||||
|
cache-dependency-path: web/package-lock.json
|
||||||
|
- name: npm ci, check, lint
|
||||||
|
run: |
|
||||||
|
set -euxo pipefail
|
||||||
|
cd web
|
||||||
|
npm ci
|
||||||
|
npm run check
|
||||||
|
npm run lint
|
||||||
|
|
||||||
# ---------------------------------------------------------------------------
|
# ---------------------------------------------------------------------------
|
||||||
go:
|
go:
|
||||||
needs: [changes]
|
needs: [changes]
|
||||||
@@ -135,6 +194,16 @@ jobs:
|
|||||||
cache-dependency-path: go.sum
|
cache-dependency-path: go.sum
|
||||||
- name: Vet
|
- name: Vet
|
||||||
run: go vet ./...
|
run: go vet ./...
|
||||||
|
- name: Lint httpapi (ERR-01 / ARCH-01)
|
||||||
|
run: sh scripts/lint-httpapi.sh
|
||||||
|
- name: Check migration pairs (DEP-03)
|
||||||
|
run: sh scripts/check-migrations-pair.sh
|
||||||
|
# go.mod: go 1.24 — бинарник golangci-lint < v1.64.2 (сборка на Go 1.23) не запускается.
|
||||||
|
- name: golangci-lint
|
||||||
|
uses: golangci/golangci-lint-action@v6
|
||||||
|
with:
|
||||||
|
version: v1.64.8
|
||||||
|
install-mode: goinstall
|
||||||
- name: Test
|
- name: Test
|
||||||
run: go test ./... -race -count=1
|
run: go test ./... -race -count=1
|
||||||
- name: Build all commands
|
- name: Build all commands
|
||||||
@@ -186,88 +255,99 @@ jobs:
|
|||||||
done
|
done
|
||||||
|
|
||||||
# ---------------------------------------------------------------------------
|
# ---------------------------------------------------------------------------
|
||||||
# Docker: все Go-образы одним buildx bake (один go mod download, одна компиляция cmd/*,
|
commitlint:
|
||||||
# birdc собирается один раз для api/all). Registry cache: evobgp-buildcache:go-buildcache.
|
if: github.event_name == 'pull_request'
|
||||||
# ---------------------------------------------------------------------------
|
|
||||||
docker-go:
|
|
||||||
needs: [changes, go]
|
|
||||||
if: >-
|
|
||||||
always() &&
|
|
||||||
needs.changes.result == 'success' &&
|
|
||||||
needs.go.result != 'failure' &&
|
|
||||||
github.event_name == 'push' &&
|
|
||||||
(github.ref == 'refs/heads/main' || github.ref == 'refs/heads/master') &&
|
|
||||||
(needs.changes.outputs.go == 'true' || needs.changes.outputs.docker_go == 'true')
|
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v4
|
- uses: actions/checkout@v4
|
||||||
- name: Set up Docker Buildx
|
|
||||||
uses: docker/setup-buildx-action@v3
|
|
||||||
- name: Prepare image metadata
|
|
||||||
id: meta
|
|
||||||
run: |
|
|
||||||
set -euo pipefail
|
|
||||||
owner_lc="$(echo '${{ github.repository_owner }}' | tr '[:upper:]' '[:lower:]')"
|
|
||||||
echo "owner_lc=$owner_lc" >> "$GITHUB_OUTPUT"
|
|
||||||
short_sha="$(echo '${{ github.sha }}' | cut -c1-7)"
|
|
||||||
echo "short_sha=$short_sha" >> "$GITHUB_OUTPUT"
|
|
||||||
- name: Log in to Gitea Registry
|
|
||||||
uses: docker/login-action@v3
|
|
||||||
with:
|
with:
|
||||||
registry: git.shts.su
|
fetch-depth: 0
|
||||||
username: ${{ gitea.actor }}
|
- uses: actions/setup-node@v4
|
||||||
password: ${{ secrets.ACTIONS_PAT || gitea.token }}
|
with:
|
||||||
- name: Build and push Go images (bake)
|
node-version: "22"
|
||||||
env:
|
cache: npm
|
||||||
REGISTRY: git.shts.su/${{ steps.meta.outputs.owner_lc }}
|
cache-dependency-path: package-lock.json
|
||||||
IMAGE_TAG: latest
|
- name: Lint commit messages
|
||||||
SHORT_SHA: ${{ steps.meta.outputs.short_sha }}
|
|
||||||
SHA_FULL: ${{ github.sha }}
|
|
||||||
CACHE_REF_GO: git.shts.su/${{ steps.meta.outputs.owner_lc }}/evobgp-buildcache:go-buildcache
|
|
||||||
CACHE_REF_WEB: ""
|
|
||||||
BUILDX_BAKE_ENTITLEMENTS_FS: "0"
|
|
||||||
run: |
|
run: |
|
||||||
set -euxo pipefail
|
set -euxo pipefail
|
||||||
cd "${{ github.workspace }}/deploy/docker"
|
npm ci
|
||||||
sh write-bake-override.sh
|
npx commitlint --from "${{ github.event.pull_request.base.sha }}" --to "${{ github.event.pull_request.head.sha }}"
|
||||||
docker buildx bake --allow=fs.read="${{ github.workspace }}" \
|
|
||||||
-f docker-bake.hcl -f docker-bake.override.hcl go-images --push
|
|
||||||
|
|
||||||
# ---------------------------------------------------------------------------
|
# ---------------------------------------------------------------------------
|
||||||
# Docker: Web (evobgp-web, evobgp-web-all) — один npm ci (кэш) + два nginx-тега.
|
# Один push в main: semantic-release (тег на текущий commit, без доп. commit) + docker push.
|
||||||
# ---------------------------------------------------------------------------
|
# ---------------------------------------------------------------------------
|
||||||
docker-web:
|
release:
|
||||||
needs: [changes]
|
needs: [changes, openapi, web, go, bird2]
|
||||||
if: >-
|
if: >-
|
||||||
|
always() &&
|
||||||
github.event_name == 'push' &&
|
github.event_name == 'push' &&
|
||||||
(github.ref == 'refs/heads/main' || github.ref == 'refs/heads/master') &&
|
(github.ref == 'refs/heads/main' || github.ref == 'refs/heads/master') &&
|
||||||
(needs.changes.outputs.web == 'true' || needs.changes.outputs.docker_web == 'true')
|
needs.changes.result == 'success' &&
|
||||||
|
(needs.openapi.result == 'success' || needs.openapi.result == 'skipped') &&
|
||||||
|
(needs.web.result == 'success' || needs.web.result == 'skipped') &&
|
||||||
|
(needs.go.result == 'success' || needs.go.result == 'skipped') &&
|
||||||
|
(needs.bird2.result == 'success' || needs.bird2.result == 'skipped')
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v4
|
- uses: actions/checkout@v4
|
||||||
|
with:
|
||||||
|
fetch-depth: 0
|
||||||
|
token: ${{ secrets.ACTIONS_PAT || gitea.token }}
|
||||||
|
persist-credentials: true
|
||||||
|
- uses: actions/setup-node@v4
|
||||||
|
with:
|
||||||
|
node-version: "22"
|
||||||
|
cache: npm
|
||||||
|
cache-dependency-path: package-lock.json
|
||||||
|
- name: Install release tooling
|
||||||
|
run: npm ci
|
||||||
|
- name: Semantic release
|
||||||
|
run: npx semantic-release
|
||||||
|
env:
|
||||||
|
GITEA_URL: https://git.shts.su
|
||||||
|
GITEA_TOKEN: ${{ secrets.ACTIONS_PAT || gitea.token }}
|
||||||
|
- name: Detect new release
|
||||||
|
id: rel
|
||||||
|
run: |
|
||||||
|
set -euo pipefail
|
||||||
|
if [ -f .release-version ]; then
|
||||||
|
echo "version=$(tr -d '[:space:]' < .release-version)" >> "$GITHUB_OUTPUT"
|
||||||
|
echo "released=true" >> "$GITHUB_OUTPUT"
|
||||||
|
else
|
||||||
|
echo "released=false" >> "$GITHUB_OUTPUT"
|
||||||
|
echo "No releasable commits — skipping image publish"
|
||||||
|
fi
|
||||||
- name: Set up Docker Buildx
|
- name: Set up Docker Buildx
|
||||||
|
if: steps.rel.outputs.released == 'true'
|
||||||
uses: docker/setup-buildx-action@v3
|
uses: docker/setup-buildx-action@v3
|
||||||
- name: Prepare image metadata
|
- name: Prepare image metadata
|
||||||
|
if: steps.rel.outputs.released == 'true'
|
||||||
id: meta
|
id: meta
|
||||||
run: |
|
run: |
|
||||||
set -euo pipefail
|
set -euo pipefail
|
||||||
|
echo "version=${{ steps.rel.outputs.version }}" >> "$GITHUB_OUTPUT"
|
||||||
owner_lc="$(echo '${{ github.repository_owner }}' | tr '[:upper:]' '[:lower:]')"
|
owner_lc="$(echo '${{ github.repository_owner }}' | tr '[:upper:]' '[:lower:]')"
|
||||||
echo "owner_lc=$owner_lc" >> "$GITHUB_OUTPUT"
|
echo "owner_lc=$owner_lc" >> "$GITHUB_OUTPUT"
|
||||||
short_sha="$(echo '${{ github.sha }}' | cut -c1-7)"
|
short_sha="$(echo '${{ github.sha }}' | cut -c1-7)"
|
||||||
echo "short_sha=$short_sha" >> "$GITHUB_OUTPUT"
|
echo "short_sha=$short_sha" >> "$GITHUB_OUTPUT"
|
||||||
|
echo "build_time=$(date -u +%Y-%m-%dT%H:%M:%SZ)" >> "$GITHUB_OUTPUT"
|
||||||
- name: Log in to Gitea Registry
|
- name: Log in to Gitea Registry
|
||||||
|
if: steps.rel.outputs.released == 'true'
|
||||||
uses: docker/login-action@v3
|
uses: docker/login-action@v3
|
||||||
with:
|
with:
|
||||||
registry: git.shts.su
|
registry: git.shts.su
|
||||||
username: ${{ gitea.actor }}
|
username: ${{ gitea.actor }}
|
||||||
password: ${{ secrets.ACTIONS_PAT || gitea.token }}
|
password: ${{ secrets.ACTIONS_PAT || gitea.token }}
|
||||||
- name: Build and push Web images (bake)
|
- name: Build and push images (bake)
|
||||||
|
if: steps.rel.outputs.released == 'true'
|
||||||
env:
|
env:
|
||||||
REGISTRY: git.shts.su/${{ steps.meta.outputs.owner_lc }}
|
REGISTRY: git.shts.su/${{ steps.meta.outputs.owner_lc }}
|
||||||
IMAGE_TAG: latest
|
IMAGE_TAG: latest
|
||||||
|
VERSION: ${{ steps.meta.outputs.version }}
|
||||||
SHORT_SHA: ${{ steps.meta.outputs.short_sha }}
|
SHORT_SHA: ${{ steps.meta.outputs.short_sha }}
|
||||||
SHA_FULL: ${{ github.sha }}
|
SHA_FULL: ${{ github.sha }}
|
||||||
CACHE_REF_GO: ""
|
BUILD_TIME: ${{ steps.meta.outputs.build_time }}
|
||||||
|
CACHE_REF_GO: git.shts.su/${{ steps.meta.outputs.owner_lc }}/evobgp-buildcache:go-buildcache
|
||||||
CACHE_REF_WEB: git.shts.su/${{ steps.meta.outputs.owner_lc }}/evobgp-buildcache:web-buildcache
|
CACHE_REF_WEB: git.shts.su/${{ steps.meta.outputs.owner_lc }}/evobgp-buildcache:web-buildcache
|
||||||
BUILDX_BAKE_ENTITLEMENTS_FS: "0"
|
BUILDX_BAKE_ENTITLEMENTS_FS: "0"
|
||||||
run: |
|
run: |
|
||||||
@@ -275,49 +355,5 @@ jobs:
|
|||||||
cd "${{ github.workspace }}/deploy/docker"
|
cd "${{ github.workspace }}/deploy/docker"
|
||||||
sh write-bake-override.sh
|
sh write-bake-override.sh
|
||||||
docker buildx bake --allow=fs.read="${{ github.workspace }}" \
|
docker buildx bake --allow=fs.read="${{ github.workspace }}" \
|
||||||
-f docker-bake.hcl -f docker-bake.override.hcl web-images --push
|
-f docker-bake.hcl -f docker-bake.override.hcl default --push
|
||||||
|
|
||||||
# ---------------------------------------------------------------------------
|
|
||||||
# Docker: BIRD2 (evobgp-bird2).
|
|
||||||
# Собирается только при изменении deploy/bird/ или Dockerfile bird2.
|
|
||||||
# ---------------------------------------------------------------------------
|
|
||||||
docker-bird:
|
|
||||||
needs: [changes]
|
|
||||||
if: >-
|
|
||||||
github.event_name == 'push' &&
|
|
||||||
(github.ref == 'refs/heads/main' || github.ref == 'refs/heads/master') &&
|
|
||||||
(needs.changes.outputs.bird_conf == 'true' || needs.changes.outputs.docker_bird == 'true')
|
|
||||||
runs-on: ubuntu-latest
|
|
||||||
steps:
|
|
||||||
- uses: actions/checkout@v4
|
|
||||||
- name: Set up Docker Buildx
|
|
||||||
uses: docker/setup-buildx-action@v3
|
|
||||||
- name: Prepare image metadata
|
|
||||||
id: meta
|
|
||||||
run: |
|
|
||||||
set -euo pipefail
|
|
||||||
owner_lc="$(echo '${{ github.repository_owner }}' | tr '[:upper:]' '[:lower:]')"
|
|
||||||
echo "owner_lc=$owner_lc" >> "$GITHUB_OUTPUT"
|
|
||||||
short_sha="$(echo '${{ github.sha }}' | cut -c1-7)"
|
|
||||||
echo "short_sha=$short_sha" >> "$GITHUB_OUTPUT"
|
|
||||||
- name: Log in to Gitea Registry
|
|
||||||
uses: docker/login-action@v3
|
|
||||||
with:
|
|
||||||
registry: git.shts.su
|
|
||||||
username: ${{ gitea.actor }}
|
|
||||||
password: ${{ secrets.ACTIONS_PAT || gitea.token }}
|
|
||||||
- name: Build and push evobgp-bird2 (bake)
|
|
||||||
env:
|
|
||||||
REGISTRY: git.shts.su/${{ steps.meta.outputs.owner_lc }}
|
|
||||||
IMAGE_TAG: latest
|
|
||||||
SHORT_SHA: ${{ steps.meta.outputs.short_sha }}
|
|
||||||
SHA_FULL: ${{ github.sha }}
|
|
||||||
CACHE_REF_GO: ""
|
|
||||||
CACHE_REF_WEB: ""
|
|
||||||
BUILDX_BAKE_ENTITLEMENTS_FS: "0"
|
|
||||||
run: |
|
|
||||||
set -euxo pipefail
|
|
||||||
cd "${{ github.workspace }}/deploy/docker"
|
|
||||||
sh write-bake-override.sh
|
|
||||||
docker buildx bake --allow=fs.read="${{ github.workspace }}" \
|
|
||||||
-f docker-bake.hcl -f docker-bake.override.hcl evobgp-bird2 --push
|
|
||||||
+18
@@ -0,0 +1,18 @@
|
|||||||
|
# Root npm (semantic-release, commitlint) — npm ci in CI, never commit deps
|
||||||
|
node_modules/
|
||||||
|
|
||||||
|
# Generated by deploy/docker/write-bake-override.sh (CI/local bake)
|
||||||
|
deploy/docker/docker-bake.override.hcl
|
||||||
|
|
||||||
|
# CI-only markers (not committed)
|
||||||
|
.release-version
|
||||||
|
CHANGELOG.md
|
||||||
|
|
||||||
|
# OS
|
||||||
|
.DS_Store
|
||||||
|
Thumbs.db
|
||||||
|
|
||||||
|
# Env / secrets (local only)
|
||||||
|
.env
|
||||||
|
.env.*
|
||||||
|
!.env.example
|
||||||
@@ -0,0 +1,18 @@
|
|||||||
|
run:
|
||||||
|
timeout: 5m
|
||||||
|
|
||||||
|
linters:
|
||||||
|
disable-all: true
|
||||||
|
enable:
|
||||||
|
- gofmt
|
||||||
|
- govet
|
||||||
|
- errcheck
|
||||||
|
|
||||||
|
issues:
|
||||||
|
exclude-use-default: false
|
||||||
|
max-issues-per-linter: 50
|
||||||
|
max-same-issues: 20
|
||||||
|
|
||||||
|
linters-settings:
|
||||||
|
gofmt:
|
||||||
|
simplify: true
|
||||||
@@ -0,0 +1,19 @@
|
|||||||
|
# Local hooks (optional): install with `pre-commit install`
|
||||||
|
repos:
|
||||||
|
- repo: https://github.com/pre-commit/pre-commit-hooks
|
||||||
|
rev: v5.0.0
|
||||||
|
hooks:
|
||||||
|
- id: trailing-whitespace
|
||||||
|
- id: end-of-file-fixer
|
||||||
|
- repo: https://github.com/dnephin/pre-commit-golang
|
||||||
|
rev: v0.5.1
|
||||||
|
hooks:
|
||||||
|
- id: go-fmt
|
||||||
|
- repo: local
|
||||||
|
hooks:
|
||||||
|
- id: prettier-web
|
||||||
|
name: prettier (web)
|
||||||
|
entry: bash -c 'cd web && npx prettier --check .'
|
||||||
|
language: system
|
||||||
|
files: ^web/
|
||||||
|
pass_filenames: false
|
||||||
@@ -0,0 +1,50 @@
|
|||||||
|
{
|
||||||
|
"branches": ["main", "master"],
|
||||||
|
"tagFormat": "v${version}",
|
||||||
|
"plugins": [
|
||||||
|
[
|
||||||
|
"@semantic-release/commit-analyzer",
|
||||||
|
{
|
||||||
|
"preset": "conventionalcommits",
|
||||||
|
"releaseRules": [
|
||||||
|
{ "type": "feat", "release": "minor" },
|
||||||
|
{ "type": "fix", "release": "patch" },
|
||||||
|
{ "type": "perf", "release": "patch" },
|
||||||
|
{ "type": "ci", "release": "patch" },
|
||||||
|
{ "type": "refactor", "release": "patch" },
|
||||||
|
{ "breaking": true, "release": "major" }
|
||||||
|
]
|
||||||
|
}
|
||||||
|
],
|
||||||
|
[
|
||||||
|
"@semantic-release/release-notes-generator",
|
||||||
|
{
|
||||||
|
"preset": "conventionalcommits"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
[
|
||||||
|
"@semantic-release/changelog",
|
||||||
|
{
|
||||||
|
"changelogFile": "CHANGELOG.md"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
[
|
||||||
|
"@semantic-release/exec",
|
||||||
|
{
|
||||||
|
"successCmd": "echo ${nextRelease.version} > .release-version"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
[
|
||||||
|
"@markwylde/semantic-release-gitea",
|
||||||
|
{
|
||||||
|
"giteaUrl": "https://git.shts.su",
|
||||||
|
"assets": [
|
||||||
|
{
|
||||||
|
"path": "CHANGELOG.md",
|
||||||
|
"label": "Changelog"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
]
|
||||||
|
]
|
||||||
|
}
|
||||||
@@ -36,6 +36,17 @@
|
|||||||
- **Повторное использование:** если [docs/architecture.md](docs/architecture.md) уже описывает поток — не пересказывайте его длинно; укажите документ и конкретный подпункт задачи.
|
- **Повторное использование:** если [docs/architecture.md](docs/architecture.md) уже описывает поток — не пересказывайте его длинно; укажите документ и конкретный подпункт задачи.
|
||||||
- **Длинные планы:** `.cursor/plans/*.plan.md` — для истории решений; для навигации пользователю достаточно `docs/`; не читайте план целиком без причины.
|
- **Длинные планы:** `.cursor/plans/*.plan.md` — для истории решений; для навигации пользователю достаточно `docs/`; не читайте план целиком без причины.
|
||||||
|
|
||||||
|
## Коммиты (Conventional Commits)
|
||||||
|
|
||||||
|
Если пользователь просит **коммит**, **commit message**, **закоммить**, **git commit**, **`/commit-message`** или это следует из плана — **сразу**:
|
||||||
|
|
||||||
|
1. Shell: `powershell -NoProfile -File scripts/commit/staged-context.ps1` (первый вызов, до текста коммита).
|
||||||
|
2. Скилл [.cursor/skills/commit-message/SKILL.md](.cursor/skills/commit-message/SKILL.md) и правило [.cursor/rules/conventional-commits.mdc](.cursor/rules/conventional-commits.mdc).
|
||||||
|
|
||||||
|
Без вывода скрипта (exit 0) **не** придумывать сообщение коммита. Заголовок — EN, тело — RU; несвязанные области — auto-split (скилл).
|
||||||
|
|
||||||
|
**Кнопка ✨ Generate commit message в Source Control** skill/rule **не** использует. Для сообщений по правилам EvoBGP — Agent Chat → **`/commit-message`** (см. [.cursor/commands/commit-message.md](.cursor/commands/commit-message.md)).
|
||||||
|
|
||||||
## Команды и среда
|
## Команды и среда
|
||||||
|
|
||||||
- Консоль пользователя: **PowerShell**; пути в стиле `deploy\compose`.
|
- Консоль пользователя: **PowerShell**; пути в стиле `deploy\compose`.
|
||||||
|
|||||||
+150
@@ -0,0 +1,150 @@
|
|||||||
|
## 1.0.0 (2026-05-19)
|
||||||
|
|
||||||
|
* feat: add @tanstack/table-core dependency and integrate module name mapping in operations page. Upda ([b140dcb](http://192.168.100.56:3000/denozord/EvoBGP/commit/b140dcb))
|
||||||
|
* feat: add @types/node and undici-types to devDependencies in package.json and package-lock.json for ([d92a06c](http://192.168.100.56:3000/denozord/EvoBGP/commit/d92a06c))
|
||||||
|
* feat: add aggregated router-lists catalog endpoint and update module listing filters ([c811c43](http://192.168.100.56:3000/denozord/EvoBGP/commit/c811c43))
|
||||||
|
* feat: add auto-updater service for Docker stack with configurable settings ([ae9fbe3](http://192.168.100.56:3000/denozord/EvoBGP/commit/ae9fbe3))
|
||||||
|
* feat: add bird configuration preview functionality with tabbed interface for fragments and prefixes. ([1969a00](http://192.168.100.56:3000/denozord/EvoBGP/commit/1969a00))
|
||||||
|
* feat: add BIRD status endpoint and integrate birdc checks into job processing. Enhance UI to display ([94a4c6a](http://192.168.100.56:3000/denozord/EvoBGP/commit/94a4c6a))
|
||||||
|
* feat: add CSV import and export functionality for module entries. Implement endpoints for exporting ([bae2d68](http://192.168.100.56:3000/denozord/EvoBGP/commit/bae2d68))
|
||||||
|
* feat: add debug logging and optimize database queries in Postgres repository ([6d0e214](http://192.168.100.56:3000/denozord/EvoBGP/commit/6d0e214))
|
||||||
|
* feat: add diagnostic log endpoint for revisions and implement download functionality ([2260ecf](http://192.168.100.56:3000/denozord/EvoBGP/commit/2260ecf))
|
||||||
|
* feat: add enabled state to BGP peer types and UI. Implement peer enabling toggle in the network page ([80965ad](http://192.168.100.56:3000/denozord/EvoBGP/commit/80965ad))
|
||||||
|
* feat: add last refreshed timestamp to modules and CDN sources ([1e13ef9](http://192.168.100.56:3000/denozord/EvoBGP/commit/1e13ef9))
|
||||||
|
* feat: add live BGP protocol state tracking to peer listing ([8a50ba4](http://192.168.100.56:3000/denozord/EvoBGP/commit/8a50ba4))
|
||||||
|
* feat: add optional name field to BGP peer creation and update UI ([1a61ae2](http://192.168.100.56:3000/denozord/EvoBGP/commit/1a61ae2))
|
||||||
|
* feat: add optional name field to DoH profile schema and types ([6bee5ad](http://192.168.100.56:3000/denozord/EvoBGP/commit/6bee5ad))
|
||||||
|
* feat: add smart aggregation for IPv4 CIDR prefixes in refresh pipeline. Implement functionality to a ([0428b83](http://192.168.100.56:3000/denozord/EvoBGP/commit/0428b83))
|
||||||
|
* feat: add strict bind configuration to BGP templates. Enhance BGP template rendering by including 's ([07f2ce5](http://192.168.100.56:3000/denozord/EvoBGP/commit/07f2ce5))
|
||||||
|
* feat: add tenant refresh functionality to HTTP API and job processing ([7a2b015](http://192.168.100.56:3000/denozord/EvoBGP/commit/7a2b015))
|
||||||
|
* feat: auto-refresh non-IP module updates and add full project manual ([1e77e1a](http://192.168.100.56:3000/denozord/EvoBGP/commit/1e77e1a))
|
||||||
|
* feat: enhance API client with pagination and new data fetching functions. Implement `apiPageAll` for ([9f0b128](http://192.168.100.56:3000/denozord/EvoBGP/commit/9f0b128))
|
||||||
|
* feat: enhance BGP template and peer configuration handling. Introduce policies_json parameter for lo ([be8e7b5](http://192.168.100.56:3000/denozord/EvoBGP/commit/be8e7b5))
|
||||||
|
* feat: enhance CDN source management with last refreshed timestamp ([4776434](http://192.168.100.56:3000/denozord/EvoBGP/commit/4776434))
|
||||||
|
* feat: enhance community attribute handling in BIRD format. Add validation for community route bodies ([b541794](http://192.168.100.56:3000/denozord/EvoBGP/commit/b541794))
|
||||||
|
* feat: enhance community label handling and improve UI localization across operations pages. Introduc ([53fd527](http://192.168.100.56:3000/denozord/EvoBGP/commit/53fd527))
|
||||||
|
* feat: enhance deployment configuration for secure Web UI with Traefik integration ([4acd685](http://192.168.100.56:3000/denozord/EvoBGP/commit/4acd685))
|
||||||
|
* feat: enhance DoH profile management and resolver policy in modules ([34ecc5c](http://192.168.100.56:3000/denozord/EvoBGP/commit/34ecc5c))
|
||||||
|
* feat: enhance EvoBGP with new command-line options for the evobgp-agent, including a watch command f ([6a55f72](http://192.168.100.56:3000/denozord/EvoBGP/commit/6a55f72))
|
||||||
|
* feat: enhance evobgp with new command-line tools for bundle management, including pull, verify, and ([bf52b21](http://192.168.100.56:3000/denozord/EvoBGP/commit/bf52b21))
|
||||||
|
* feat: enhance job detail handling in UI with caching and loading states. Introduce SvelteMap for job ([05bc5c4](http://192.168.100.56:3000/denozord/EvoBGP/commit/05bc5c4))
|
||||||
|
* feat: enhance job detail UI with improved overflow handling and layout adjustments. Update card comp ([67ce135](http://192.168.100.56:3000/denozord/EvoBGP/commit/67ce135))
|
||||||
|
* feat: enhance job filtering and display functionality in operations page. Introduce job search and f ([e1c4cbc](http://192.168.100.56:3000/denozord/EvoBGP/commit/e1c4cbc))
|
||||||
|
* feat: enhance job processing with detailed logging and UI improvements. Introduce revision log entri ([c48cc4e](http://192.168.100.56:3000/denozord/EvoBGP/commit/c48cc4e))
|
||||||
|
* feat: enhance monitoring page with detailed status tracking and error handling ([458a885](http://192.168.100.56:3000/denozord/EvoBGP/commit/458a885))
|
||||||
|
* feat: enhance observability with prefix aggregation metrics ([07b97bd](http://192.168.100.56:3000/denozord/EvoBGP/commit/07b97bd))
|
||||||
|
* feat: enhance peer neighbor handling by introducing NormalizePeerNeighborString function. Update Cre ([80f3a8d](http://192.168.100.56:3000/denozord/EvoBGP/commit/80f3a8d))
|
||||||
|
* feat: enhance RefreshModule to aggregate prefixes from all enabled tenant modules. Update documentat ([431c6a9](http://192.168.100.56:3000/denozord/EvoBGP/commit/431c6a9))
|
||||||
|
* feat: enhance RefreshModule to support legacy ASN resolution and improve prefix handling. Introduce ([e1aaa18](http://192.168.100.56:3000/denozord/EvoBGP/commit/e1aaa18))
|
||||||
|
* feat: enhance settings page layout and section management ([d91667f](http://192.168.100.56:3000/denozord/EvoBGP/commit/d91667f))
|
||||||
|
* feat: enhance UI components with improved styling and layout adjustments. Update button sizes, text ([6a72842](http://192.168.100.56:3000/denozord/EvoBGP/commit/6a72842))
|
||||||
|
* feat: enhance worker functionality by adding job queuing for deploy_apply. Introduce a Registry fiel ([42d956d](http://192.168.100.56:3000/denozord/EvoBGP/commit/42d956d))
|
||||||
|
* feat: implement AS holder name resolution and enhance ASEntry structure. Add ASHolderName function t ([c958d5a](http://192.168.100.56:3000/denozord/EvoBGP/commit/c958d5a))
|
||||||
|
* feat: implement bulk selection and deletion for modules and entries. Add functionality for selecting ([e816d17](http://192.168.100.56:3000/denozord/EvoBGP/commit/e816d17))
|
||||||
|
* feat: implement CDN source preview functionality and enhance data handling. Add a new endpoint for p ([e20c9f3](http://192.168.100.56:3000/denozord/EvoBGP/commit/e20c9f3))
|
||||||
|
* feat: implement countAll function for API data retrieval ([40c8a8d](http://192.168.100.56:3000/denozord/EvoBGP/commit/40c8a8d))
|
||||||
|
* feat: implement domain resolution via DoH in refresh pipeline. Enhance the collectModulePrefixRows f ([678bd27](http://192.168.100.56:3000/denozord/EvoBGP/commit/678bd27))
|
||||||
|
* feat: implement effective peer enabling logic during peer creation. Update CreatePeer methods in Pos ([3e85431](http://192.168.100.56:3000/denozord/EvoBGP/commit/3e85431))
|
||||||
|
* feat: implement module refresh job management with concurrency control. Add CountOtherActiveModuleRe ([149fb0a](http://192.168.100.56:3000/denozord/EvoBGP/commit/149fb0a))
|
||||||
|
* feat: implement peer reconciliation job for BGP peers ([3b17228](http://192.168.100.56:3000/denozord/EvoBGP/commit/3b17228))
|
||||||
|
* feat: implement revision retention settings and pruning logic ([4f50350](http://192.168.100.56:3000/denozord/EvoBGP/commit/4f50350))
|
||||||
|
* feat: implement theme selection and automatic theme application based on user preference. Update App ([b70a643](http://192.168.100.56:3000/denozord/EvoBGP/commit/b70a643))
|
||||||
|
* feat: implement versioning and release management in the project ([bb334b1](http://192.168.100.56:3000/denozord/EvoBGP/commit/bb334b1))
|
||||||
|
* feat: improve BGP protocol summary handling by introducing isBGPProtocolSummaryRow function. Update ([399622c](http://192.168.100.56:3000/denozord/EvoBGP/commit/399622c))
|
||||||
|
* feat: improve job detail UI with enhanced spacing and layout adjustments. Update table cell classes ([97908b5](http://192.168.100.56:3000/denozord/EvoBGP/commit/97908b5))
|
||||||
|
* feat: improve peer speaker assignment UX in network settings ([f877ec8](http://192.168.100.56:3000/denozord/EvoBGP/commit/f877ec8))
|
||||||
|
* feat: improve UI components with enhanced overflow handling and layout adjustments. Update card and ([0ca5542](http://192.168.100.56:3000/denozord/EvoBGP/commit/0ca5542))
|
||||||
|
* feat: improve UI layout and responsiveness in module and operations pages. Refactor component struct ([233f29b](http://192.168.100.56:3000/denozord/EvoBGP/commit/233f29b))
|
||||||
|
* feat: redesign settings page with structured controls ([2da6d49](http://192.168.100.56:3000/denozord/EvoBGP/commit/2da6d49))
|
||||||
|
* feat: refactor materialization logic to group static routes by community in the refresh pipeline. In ([1c5a9c9](http://192.168.100.56:3000/denozord/EvoBGP/commit/1c5a9c9))
|
||||||
|
* feat: refactor operations page to enhance UI and component structure. Remove unused card components ([88226f6](http://192.168.100.56:3000/denozord/EvoBGP/commit/88226f6))
|
||||||
|
* feat: refine BGP template handling and documentation updates. Remove local IP requirements in BGP te ([6266a39](http://192.168.100.56:3000/denozord/EvoBGP/commit/6266a39))
|
||||||
|
* feat: refine job detail UI with improved layout and scrolling capabilities. Enhance spacing and over ([57c09ac](http://192.168.100.56:3000/denozord/EvoBGP/commit/57c09ac))
|
||||||
|
* feat: update BGP community structure and related documentation. Refactor BGP community handling by r ([a2cbfac](http://192.168.100.56:3000/denozord/EvoBGP/commit/a2cbfac))
|
||||||
|
* feat: update BGP template configuration and OpenAPI documentation. Change import settings from 'all' ([133ea93](http://192.168.100.56:3000/denozord/EvoBGP/commit/133ea93))
|
||||||
|
* feat: update BIRD installation process to build from source. Modify CI workflow to ensure BIRD 2.14 ([e2002ba](http://192.168.100.56:3000/denozord/EvoBGP/commit/e2002ba))
|
||||||
|
* feat: update CI configuration and Dockerfiles for improved build efficiency ([80229b3](http://192.168.100.56:3000/denozord/EvoBGP/commit/80229b3))
|
||||||
|
* feat: update collectModulePrefixRows to support prior snapshots and enhance CDN/domain prefix collec ([ee364c8](http://192.168.100.56:3000/denozord/EvoBGP/commit/ee364c8))
|
||||||
|
* feat: update Go module dependencies and enhance DNS resolution in refresh pipeline. Upgrade Go versi ([655d750](http://192.168.100.56:3000/denozord/EvoBGP/commit/655d750))
|
||||||
|
* feat: update OpenAPI documentation and internal logic for BIRD settings. Enhance the description of ([62bf987](http://192.168.100.56:3000/denozord/EvoBGP/commit/62bf987))
|
||||||
|
* feat: update RevisionDiff type and enhance OperationsDiffTab component for better diff handling. Int ([4aaaa30](http://192.168.100.56:3000/denozord/EvoBGP/commit/4aaaa30))
|
||||||
|
* feat: update Traefik deployment configuration for Let's Encrypt and logging ([39ba976](http://192.168.100.56:3000/denozord/EvoBGP/commit/39ba976))
|
||||||
|
* docs: add router-lists-ui integration documentation to README ([b7a8aab](http://192.168.100.56:3000/denozord/EvoBGP/commit/b7a8aab))
|
||||||
|
* docs: add Web UI section to EvoBGP architecture plan, detailing Svelte and shadcn-svelte integration ([272542b](http://192.168.100.56:3000/denozord/EvoBGP/commit/272542b))
|
||||||
|
* docs: enhance EvoBGP architecture plan with new risk mitigation strategies, testing matrix for BIRD2 ([3992d01](http://192.168.100.56:3000/denozord/EvoBGP/commit/3992d01))
|
||||||
|
* docs: enhance README and CI workflow documentation for Docker image building and publishing process, ([9eb3e33](http://192.168.100.56:3000/denozord/EvoBGP/commit/9eb3e33))
|
||||||
|
* docs: enhance README and CI workflow to clarify Docker image build conditions and Gitea Container Re ([c6687b2](http://192.168.100.56:3000/denozord/EvoBGP/commit/c6687b2))
|
||||||
|
* docs: openapi.html со встроенным Redoc; инструкция для Gitea и скрипт сборки ([a754e1d](http://192.168.100.56:3000/denozord/EvoBGP/commit/a754e1d))
|
||||||
|
* docs: update AGENTS and README to include guidelines for Conventional Commits ([4c23232](http://192.168.100.56:3000/denozord/EvoBGP/commit/4c23232))
|
||||||
|
* docs: update AGENTS and README with engineering rules and guidelines ([aff27e8](http://192.168.100.56:3000/denozord/EvoBGP/commit/aff27e8))
|
||||||
|
* docs: update architecture and API documentation to clarify job processing, in-memory registry usage, ([acc0608](http://192.168.100.56:3000/denozord/EvoBGP/commit/acc0608))
|
||||||
|
* docs: update EvoBGP architecture plan with detailed REST API section, including general agreements, ([1a86d6c](http://192.168.100.56:3000/denozord/EvoBGP/commit/1a86d6c))
|
||||||
|
* docs: update EvoBGP architecture plan with new repository structure, refined sections, and detailed ([4480d64](http://192.168.100.56:3000/denozord/EvoBGP/commit/4480d64))
|
||||||
|
* docs: update README and CI workflow to clarify Docker workspace mounting for bird2 job ([6be46db](http://192.168.100.56:3000/denozord/EvoBGP/commit/6be46db))
|
||||||
|
* docs: update README and CI workflow to clarify Gitea Registry login process and improve Docker image ([f1b33b9](http://192.168.100.56:3000/denozord/EvoBGP/commit/f1b33b9))
|
||||||
|
* docs: update README and Docker Compose configurations to clarify usage of pre-built images from the ([7fac79c](http://192.168.100.56:3000/denozord/EvoBGP/commit/7fac79c))
|
||||||
|
* docs: update README to include information about the EvoBGP web interface, linking to quickstart and ([5d21f01](http://192.168.100.56:3000/denozord/EvoBGP/commit/5d21f01))
|
||||||
|
* docs: статическая Redoc-страница OpenAPI (для просмотра в Gitea без встроенного рендера) ([5c9d2e2](http://192.168.100.56:3000/denozord/EvoBGP/commit/5c9d2e2))
|
||||||
|
* docs: убрать типографское тире и невидимый Unicode из текстов API ([fbe9cd3](http://192.168.100.56:3000/denozord/EvoBGP/commit/fbe9cd3))
|
||||||
|
* refactor: adjust BootstrapWorkers function call in server.go to change the order of returned values, ([032fa99](http://192.168.100.56:3000/denozord/EvoBGP/commit/032fa99))
|
||||||
|
* refactor: consolidate module interval display logic and improve edit form handling ([1f85654](http://192.168.100.56:3000/denozord/EvoBGP/commit/1f85654))
|
||||||
|
* refactor: enhance bird metrics polling with context support ([f6b94a4](http://192.168.100.56:3000/denozord/EvoBGP/commit/f6b94a4))
|
||||||
|
* refactor: enhance CI workflow for granular change detection by module and improve idempotency key ge ([54eaad3](http://192.168.100.56:3000/denozord/EvoBGP/commit/54eaad3))
|
||||||
|
* refactor: enhance job status checks in worker tests ([6107c3e](http://192.168.100.56:3000/denozord/EvoBGP/commit/6107c3e))
|
||||||
|
* refactor: enhance JSON struct tags for various data models in backend and memory store. Update field ([4a860a0](http://192.168.100.56:3000/denozord/EvoBGP/commit/4a860a0))
|
||||||
|
* refactor: enhance module display and input handling in module pages ([25374a6](http://192.168.100.56:3000/denozord/EvoBGP/commit/25374a6))
|
||||||
|
* refactor: enhance module interval label logic and add reset buttons in edit forms ([b99fc17](http://192.168.100.56:3000/denozord/EvoBGP/commit/b99fc17))
|
||||||
|
* refactor: improve code consistency and formatting across components ([c263fd5](http://192.168.100.56:3000/denozord/EvoBGP/commit/c263fd5))
|
||||||
|
* refactor: improve handling of deployable fragments in ApplyRevision and buildPreviewFragments functi ([6932271](http://192.168.100.56:3000/denozord/EvoBGP/commit/6932271))
|
||||||
|
* refactor: improve module save functionality and nullable value handling ([05ec176](http://192.168.100.56:3000/denozord/EvoBGP/commit/05ec176))
|
||||||
|
* refactor: improve PATCH handling for module updates with nullable field support ([e700f90](http://192.168.100.56:3000/denozord/EvoBGP/commit/e700f90))
|
||||||
|
* refactor: optimize job listing and counting logic for concurrency safety. Separate tenant filtering ([d83efe2](http://192.168.100.56:3000/denozord/EvoBGP/commit/d83efe2))
|
||||||
|
* refactor: phase 2 structural alignment — reports, importer, nodecli, pagination ([250cdea](http://192.168.100.56:3000/denozord/EvoBGP/commit/250cdea))
|
||||||
|
* refactor: remove strict bind configuration from BGP templates and update related logic. Eliminate 's ([482eeb1](http://192.168.100.56:3000/denozord/EvoBGP/commit/482eeb1))
|
||||||
|
* refactor: streamline Docker build process in CI configuration and documentation ([6025f38](http://192.168.100.56:3000/denozord/EvoBGP/commit/6025f38))
|
||||||
|
* refactor: streamline edit form handling for community and DoH profile selections ([1765ab8](http://192.168.100.56:3000/denozord/EvoBGP/commit/1765ab8))
|
||||||
|
* refactor: streamline module refresh process and enhance revision handling ([10e2415](http://192.168.100.56:3000/denozord/EvoBGP/commit/10e2415))
|
||||||
|
* refactor: switch BIRD installation from source to Ubuntu package. Update CI workflow and Dockerfiles ([0b3ceaa](http://192.168.100.56:3000/denozord/EvoBGP/commit/0b3ceaa))
|
||||||
|
* refactor: update AS entry handling in API and database to support ASN-only entries. Remove prefix fi ([1db6b5b](http://192.168.100.56:3000/denozord/EvoBGP/commit/1db6b5b))
|
||||||
|
* refactor: update Docker build context and paths in CI configuration and documentation ([7d52a4a](http://192.168.100.56:3000/denozord/EvoBGP/commit/7d52a4a))
|
||||||
|
* refactor: update Docker build variable syntax in CI configuration and documentation ([27e01d0](http://192.168.100.56:3000/denozord/EvoBGP/commit/27e01d0))
|
||||||
|
* refactor: update job kind display logic in schedule page ([dc1f4a5](http://192.168.100.56:3000/denozord/EvoBGP/commit/dc1f4a5))
|
||||||
|
* refactor: update ListModules and GetModule methods in Postgres repository to include cron expression ([73d0003](http://192.168.100.56:3000/denozord/EvoBGP/commit/73d0003))
|
||||||
|
* refactor: update Switch component styles and structure for improved accessibility and responsiveness ([d4282c2](http://192.168.100.56:3000/denozord/EvoBGP/commit/d4282c2))
|
||||||
|
* refactor: update worker processes in EvoBGP to accept dependencies for shared store and job registry ([b7968db](http://192.168.100.56:3000/denozord/EvoBGP/commit/b7968db))
|
||||||
|
* ci: add conditional job for OpenAPI linting based on file changes; update README with workflow detai ([3adfc49](http://192.168.100.56:3000/denozord/EvoBGP/commit/3adfc49))
|
||||||
|
* ci: phase 4 automation — web job, lint-httpapi, golangci ([64516c3](http://192.168.100.56:3000/denozord/EvoBGP/commit/64516c3))
|
||||||
|
* ci: update README and CI workflow to improve bird2 job installation process and clarify Docker usage ([eddc6b8](http://192.168.100.56:3000/denozord/EvoBGP/commit/eddc6b8))
|
||||||
|
* chore: phase 3 code quality — pipeline prefixes, godoc baseline ([ea65451](http://192.168.100.56:3000/denozord/EvoBGP/commit/ea65451))
|
||||||
|
* chore: update CI configuration to disable filesystem entitlement for Docker builds ([9ab7de6](http://192.168.100.56:3000/denozord/EvoBGP/commit/9ab7de6))
|
||||||
|
* chore: update package dependencies and enhance AppShell component with new navigation items and tool ([7d85fef](http://192.168.100.56:3000/denozord/EvoBGP/commit/7d85fef))
|
||||||
|
* chore: upgrade Go version to 1.24 in Dockerfiles for evobgp-agent and gobinary. This change ensures ([4ba5b03](http://192.168.100.56:3000/denozord/EvoBGP/commit/4ba5b03))
|
||||||
|
* fix: adjust Postgres resource limits and healthcheck parameters. Increase memory limit to 256M and m ([20e674c](http://192.168.100.56:3000/denozord/EvoBGP/commit/20e674c))
|
||||||
|
* fix: improve input handling and validation for settings fields ([1386b63](http://192.168.100.56:3000/denozord/EvoBGP/commit/1386b63))
|
||||||
|
* fix: improve sidebar and navigation layout in AppShell component ([9f02128](http://192.168.100.56:3000/denozord/EvoBGP/commit/9f02128))
|
||||||
|
* fix: update BGP configuration in test scenarios to use new IPv6 addresses ([9fd9745](http://192.168.100.56:3000/denozord/EvoBGP/commit/9fd9745))
|
||||||
|
* fix: update bird build script and Dockerfile to include libncurses dependency ([0cb5a7d](http://192.168.100.56:3000/denozord/EvoBGP/commit/0cb5a7d))
|
||||||
|
* fix: update bird build script and Dockerfile to include readline dependency ([35ed79b](http://192.168.100.56:3000/denozord/EvoBGP/commit/35ed79b))
|
||||||
|
* fix: update bird build script and Dockerfile to remove readline dependency ([fefadac](http://192.168.100.56:3000/denozord/EvoBGP/commit/fefadac))
|
||||||
|
* fix: update deployment configuration for Traefik and secure Web UI ([00bd037](http://192.168.100.56:3000/denozord/EvoBGP/commit/00bd037))
|
||||||
|
* fix: update Docker build commands in CI configuration and documentation ([b5061a5](http://192.168.100.56:3000/denozord/EvoBGP/commit/b5061a5))
|
||||||
|
* fix(httpapi): phase 1 compliance — ERR-01, SEC-04, CDN client, scheduler docs ([1dd7135](http://192.168.100.56:3000/denozord/EvoBGP/commit/1dd7135))
|
||||||
|
* test: add CDN prefetch tests for 304 responses and snapshot handling ([a536a2d](http://192.168.100.56:3000/denozord/EvoBGP/commit/a536a2d))
|
||||||
|
* test: add validation for 'strict bind on' in BGP rendering tests. Enhance BGP test cases to ensure ' ([dc5e20e](http://192.168.100.56:3000/denozord/EvoBGP/commit/dc5e20e))
|
||||||
|
* docker: refactor cache handling in Docker bake configuration ([5e59a1c](http://192.168.100.56:3000/denozord/EvoBGP/commit/5e59a1c))
|
||||||
|
* docker: simplify web image targets in Docker bake configuration ([765a805](http://192.168.100.56:3000/denozord/EvoBGP/commit/765a805))
|
||||||
|
* docker: update web image build process and README ([92f6de8](http://192.168.100.56:3000/denozord/EvoBGP/commit/92f6de8))
|
||||||
|
* web(ui): app layout — sidebar, mobile sheet, topbar, PageHeader ([2d78c81](http://192.168.100.56:3000/denozord/EvoBGP/commit/2d78c81))
|
||||||
|
* web(ui): AppDataTable pattern and modules pilot ([b992301](http://192.168.100.56:3000/denozord/EvoBGP/commit/b992301))
|
||||||
|
* web(ui): design tokens — spacing and component scale ([ac635e9](http://192.168.100.56:3000/denozord/EvoBGP/commit/ac635e9))
|
||||||
|
* web(ui): feedback — confirm dialog, skeletons, README ([87309cf](http://192.168.100.56:3000/denozord/EvoBGP/commit/87309cf))
|
||||||
|
* web(ui): form patterns — FormField, formsnap, directories pilot ([77a2cfd](http://192.168.100.56:3000/denozord/EvoBGP/commit/77a2cfd))
|
||||||
|
* web(ui): foundation — ui/core layout, shadcn primitives, notify ([00a2a44](http://192.168.100.56:3000/denozord/EvoBGP/commit/00a2a44))
|
||||||
|
* web(ui): migrate dashboard, schedule, monitoring to ui patterns ([57dcf30](http://192.168.100.56:3000/denozord/EvoBGP/commit/57dcf30))
|
||||||
|
* web(ui): migrate network to ui patterns ([3a3056b](http://192.168.100.56:3000/denozord/EvoBGP/commit/3a3056b))
|
||||||
|
* web(ui): migrate operations and module detail to ui patterns ([1f9930d](http://192.168.100.56:3000/denozord/EvoBGP/commit/1f9930d))
|
||||||
|
* web(ui): migrate settings to ui patterns ([9808aca](http://192.168.100.56:3000/denozord/EvoBGP/commit/9808aca))
|
||||||
|
* Enhance EvoBGP architecture plan by refining the overview, updating todos with detailed descriptions ([30efdbf](http://192.168.100.56:3000/denozord/EvoBGP/commit/30efdbf))
|
||||||
|
* init ([cbf3aaa](http://192.168.100.56:3000/denozord/EvoBGP/commit/cbf3aaa))
|
||||||
|
* Refine EvoBGP architecture plan with updated database schema details, improved descriptions for comp ([431ef3e](http://192.168.100.56:3000/denozord/EvoBGP/commit/431ef3e))
|
||||||
|
* Update EvoBGP architecture plan with new overview and todos. Refined descriptions for control-plane ([31ff5bb](http://192.168.100.56:3000/denozord/EvoBGP/commit/31ff5bb))
|
||||||
@@ -44,4 +44,12 @@ docker compose --profile reference up -d
|
|||||||
- **Go:** модуль `evobgp`, точки входа в `cmd/`.
|
- **Go:** модуль `evobgp`, точки входа в `cmd/`.
|
||||||
- **Веб:** SvelteKit в каталоге `web/` (см. [web/README.md](web/README.md)).
|
- **Веб:** SvelteKit в каталоге `web/` (см. [web/README.md](web/README.md)).
|
||||||
|
|
||||||
|
## Версионирование и релизы
|
||||||
|
|
||||||
|
Версии определяются автоматически из Conventional Commits при merge в `main` (semantic-release на Gitea Actions). Первая версия — **1.0.0**; ручной bump не нужен.
|
||||||
|
|
||||||
|
- [docs/releasing.md](docs/releasing.md) — пайплайн, commit conventions, секреты CI
|
||||||
|
- API: `GET /version` и `GET /v1/version` (поле `version`)
|
||||||
|
- Docker-образы: теги `latest`, `vX.Y.Z`, `X.Y.Z` — в **том же CI run**, что и релиз (job `release`)
|
||||||
|
|
||||||
Лицензия и условия использования — по политике владельца репозитория.
|
Лицензия и условия использования — по политике владельца репозитория.
|
||||||
@@ -19,6 +19,7 @@ import (
|
|||||||
"evobgp/internal/platform"
|
"evobgp/internal/platform"
|
||||||
"evobgp/internal/render"
|
"evobgp/internal/render"
|
||||||
"evobgp/internal/scheduler"
|
"evobgp/internal/scheduler"
|
||||||
|
"evobgp/internal/version"
|
||||||
)
|
)
|
||||||
|
|
||||||
// microVPS entrypoint: один процесс — HTTP API и фоновые воркеры scheduler, ingest, render, deploy (общий store и jobs.Registry).
|
// microVPS entrypoint: один процесс — HTTP API и фоновые воркеры scheduler, ingest, render, deploy (общий store и jobs.Registry).
|
||||||
@@ -37,7 +38,7 @@ func main() {
|
|||||||
log.Fatal(err)
|
log.Fatal(err)
|
||||||
}
|
}
|
||||||
defer srv.Close()
|
defer srv.Close()
|
||||||
observability.SetBuildInfo("0.1.0", strings.TrimSpace(os.Getenv("EVOBGP_GIT_SHA")))
|
observability.SetBuildInfo(version.Version, version.GitSHA)
|
||||||
|
|
||||||
ctx, stop := signal.NotifyContext(context.Background(), os.Interrupt, syscall.SIGTERM)
|
ctx, stop := signal.NotifyContext(context.Background(), os.Interrupt, syscall.SIGTERM)
|
||||||
defer stop()
|
defer stop()
|
||||||
@@ -54,8 +55,12 @@ func main() {
|
|||||||
startBirdMetricsPoller(ctx)
|
startBirdMetricsPoller(ctx)
|
||||||
|
|
||||||
httpSrv := &http.Server{
|
httpSrv := &http.Server{
|
||||||
Addr: cfg.HTTPAddr,
|
Addr: cfg.HTTPAddr,
|
||||||
Handler: srv.Handler(),
|
Handler: srv.Handler(),
|
||||||
|
ReadHeaderTimeout: 10 * time.Second,
|
||||||
|
ReadTimeout: 60 * time.Second,
|
||||||
|
WriteTimeout: 120 * time.Second,
|
||||||
|
IdleTimeout: 120 * time.Second,
|
||||||
}
|
}
|
||||||
go func() {
|
go func() {
|
||||||
svc := platform.ServiceName("evobgp-all")
|
svc := platform.ServiceName("evobgp-all")
|
||||||
@@ -90,6 +95,7 @@ func startBirdMetricsPoller(ctx context.Context) {
|
|||||||
return birdfmt.ShowProtocols(ctx, socket, birdcBin)
|
return birdfmt.ShowProtocols(ctx, socket, birdcBin)
|
||||||
},
|
},
|
||||||
birdfmt.CountEstablishedBGPSessions,
|
birdfmt.CountEstablishedBGPSessions,
|
||||||
|
birdfmt.ParseBGPProtocolStates,
|
||||||
)
|
)
|
||||||
log.Printf("birdc protocols poller enabled (socket=%s interval=%s)", sock, interval)
|
log.Printf("birdc protocols poller enabled (socket=%s interval=%s)", sock, interval)
|
||||||
}
|
}
|
||||||
@@ -15,6 +15,7 @@ import (
|
|||||||
"evobgp/internal/httpapi"
|
"evobgp/internal/httpapi"
|
||||||
"evobgp/internal/observability"
|
"evobgp/internal/observability"
|
||||||
"evobgp/internal/platform"
|
"evobgp/internal/platform"
|
||||||
|
"evobgp/internal/version"
|
||||||
)
|
)
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
@@ -34,15 +35,19 @@ func main() {
|
|||||||
}
|
}
|
||||||
defer srv.Close()
|
defer srv.Close()
|
||||||
|
|
||||||
observability.SetBuildInfo("0.1.0", strings.TrimSpace(os.Getenv("EVOBGP_GIT_SHA")))
|
observability.SetBuildInfo(version.Version, version.GitSHA)
|
||||||
ctx, stop := signal.NotifyContext(context.Background(), os.Interrupt, syscall.SIGTERM)
|
ctx, stop := signal.NotifyContext(context.Background(), os.Interrupt, syscall.SIGTERM)
|
||||||
defer stop()
|
defer stop()
|
||||||
|
|
||||||
startBirdMetricsPoller(ctx)
|
startBirdMetricsPoller(ctx)
|
||||||
|
|
||||||
httpSrv := &http.Server{
|
httpSrv := &http.Server{
|
||||||
Addr: cfg.HTTPAddr,
|
Addr: cfg.HTTPAddr,
|
||||||
Handler: srv.Handler(),
|
Handler: srv.Handler(),
|
||||||
|
ReadHeaderTimeout: 10 * time.Second,
|
||||||
|
ReadTimeout: 60 * time.Second,
|
||||||
|
WriteTimeout: 120 * time.Second,
|
||||||
|
IdleTimeout: 120 * time.Second,
|
||||||
}
|
}
|
||||||
go func() {
|
go func() {
|
||||||
svc := platform.ServiceName("evobgp-api")
|
svc := platform.ServiceName("evobgp-api")
|
||||||
@@ -83,6 +88,7 @@ func startBirdMetricsPoller(ctx context.Context) {
|
|||||||
return birdfmt.ShowProtocols(ctx, socket, birdcBin)
|
return birdfmt.ShowProtocols(ctx, socket, birdcBin)
|
||||||
},
|
},
|
||||||
birdfmt.CountEstablishedBGPSessions,
|
birdfmt.CountEstablishedBGPSessions,
|
||||||
|
birdfmt.ParseBGPProtocolStates,
|
||||||
)
|
)
|
||||||
log.Printf("birdc protocols poller enabled (socket=%s interval=%s)", sock, interval)
|
log.Printf("birdc protocols poller enabled (socket=%s interval=%s)", sock, interval)
|
||||||
}
|
}
|
||||||
+3
-228
@@ -1,240 +1,15 @@
|
|||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
|
||||||
"crypto/ed25519"
|
|
||||||
"encoding/base64"
|
|
||||||
"encoding/json"
|
|
||||||
"flag"
|
|
||||||
"fmt"
|
|
||||||
"io"
|
|
||||||
"net/http"
|
|
||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
|
||||||
"strings"
|
|
||||||
"time"
|
|
||||||
|
|
||||||
"evobgp/internal/birdfmt"
|
"evobgp/internal/nodecli"
|
||||||
"evobgp/internal/bundle"
|
|
||||||
"evobgp/internal/signing"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
if len(os.Args) < 2 {
|
if len(os.Args) < 2 {
|
||||||
usage()
|
nodecli.Usage(os.Stderr)
|
||||||
os.Exit(2)
|
|
||||||
}
|
|
||||||
switch os.Args[1] {
|
|
||||||
case "pull-bundle":
|
|
||||||
os.Exit(cmdPullBundle(os.Args[2:]))
|
|
||||||
case "verify-bundle":
|
|
||||||
os.Exit(cmdVerifyBundle(os.Args[2:]))
|
|
||||||
case "apply-bundle":
|
|
||||||
os.Exit(cmdApplyBundle(os.Args[2:]))
|
|
||||||
default:
|
|
||||||
usage()
|
|
||||||
os.Exit(2)
|
os.Exit(2)
|
||||||
}
|
}
|
||||||
}
|
os.Exit(nodecli.Run(os.Args[1:]))
|
||||||
|
|
||||||
func usage() {
|
|
||||||
fmt.Fprintf(os.Stderr, `Usage:
|
|
||||||
%s pull-bundle -base-url URL -token TOKEN -speaker-id ID [-revision-id ID] [-o path]
|
|
||||||
%s verify-bundle -f bundle.tar.gz (-pubkey-base64 B64 | -pubkey-hex HEX)
|
|
||||||
%s apply-bundle -f bundle.tar.gz -extract-dir DIR (-pubkey-base64 B64 | -pubkey-hex HEX)
|
|
||||||
[-bird PATH] [-birdc PATH] [-socket PATH] [-timeout DURATION]
|
|
||||||
|
|
||||||
apply-bundle verifies, extracts, runs bird -p on main bird.conf, then birdc configure.
|
|
||||||
`, os.Args[0], os.Args[0], os.Args[0])
|
|
||||||
}
|
|
||||||
|
|
||||||
func cmdPullBundle(args []string) int {
|
|
||||||
fs := flag.NewFlagSet("pull-bundle", flag.ExitOnError)
|
|
||||||
base := fs.String("base-url", "", "control plane base URL, e.g. http://localhost:8080")
|
|
||||||
token := fs.String("token", "", "Bearer token (node role)")
|
|
||||||
speaker := fs.String("speaker-id", "", "bgp_speaker id")
|
|
||||||
revision := fs.String("revision-id", "", "revision to fetch (empty = latest pointer)")
|
|
||||||
out := fs.String("o", "bundle.tar.gz", "output file")
|
|
||||||
_ = fs.Parse(args)
|
|
||||||
|
|
||||||
if strings.TrimSpace(*base) == "" || *token == "" || *speaker == "" {
|
|
||||||
fmt.Fprintln(os.Stderr, "pull-bundle: -base-url, -token, -speaker-id are required")
|
|
||||||
return 2
|
|
||||||
}
|
|
||||||
rev := strings.TrimSpace(*revision)
|
|
||||||
if rev == "" {
|
|
||||||
var err error
|
|
||||||
rev, err = fetchLatestRevision(*base, *token, *speaker)
|
|
||||||
if err != nil {
|
|
||||||
fmt.Fprintln(os.Stderr, err)
|
|
||||||
return 1
|
|
||||||
}
|
|
||||||
}
|
|
||||||
body, err := fetchBundle(*base, *token, *speaker, rev)
|
|
||||||
if err != nil {
|
|
||||||
fmt.Fprintln(os.Stderr, err)
|
|
||||||
return 1
|
|
||||||
}
|
|
||||||
if err := os.WriteFile(*out, body, 0o644); err != nil {
|
|
||||||
fmt.Fprintln(os.Stderr, err)
|
|
||||||
return 1
|
|
||||||
}
|
|
||||||
fmt.Fprintf(os.Stderr, "wrote %s (revision %s)\n", *out, rev)
|
|
||||||
return 0
|
|
||||||
}
|
|
||||||
|
|
||||||
func fetchLatestRevision(base, token, speaker string) (string, error) {
|
|
||||||
u := strings.TrimRight(base, "/") + "/v1/speakers/" + speaker + "/revisions/latest"
|
|
||||||
req, err := http.NewRequest(http.MethodGet, u, nil)
|
|
||||||
if err != nil {
|
|
||||||
return "", err
|
|
||||||
}
|
|
||||||
req.Header.Set("Authorization", "Bearer "+token)
|
|
||||||
resp, err := http.DefaultClient.Do(req)
|
|
||||||
if err != nil {
|
|
||||||
return "", err
|
|
||||||
}
|
|
||||||
defer resp.Body.Close()
|
|
||||||
if resp.StatusCode != http.StatusOK {
|
|
||||||
b, _ := io.ReadAll(resp.Body)
|
|
||||||
return "", fmt.Errorf("latest revision: %s: %s", resp.Status, strings.TrimSpace(string(b)))
|
|
||||||
}
|
|
||||||
var out struct {
|
|
||||||
RevisionID string `json:"revision_id"`
|
|
||||||
}
|
|
||||||
if err := json.NewDecoder(resp.Body).Decode(&out); err != nil {
|
|
||||||
return "", err
|
|
||||||
}
|
|
||||||
if out.RevisionID == "" {
|
|
||||||
return "", fmt.Errorf("empty revision_id in response")
|
|
||||||
}
|
|
||||||
return out.RevisionID, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func fetchBundle(base, token, speaker, revision string) ([]byte, error) {
|
|
||||||
u := strings.TrimRight(base, "/") + "/v1/speakers/" + speaker + "/bundle/" + revision
|
|
||||||
req, err := http.NewRequest(http.MethodGet, u, nil)
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
req.Header.Set("Authorization", "Bearer "+token)
|
|
||||||
resp, err := http.DefaultClient.Do(req)
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
defer resp.Body.Close()
|
|
||||||
if resp.StatusCode != http.StatusOK {
|
|
||||||
b, _ := io.ReadAll(resp.Body)
|
|
||||||
return nil, fmt.Errorf("bundle: %s: %s", resp.Status, strings.TrimSpace(string(b)))
|
|
||||||
}
|
|
||||||
return io.ReadAll(resp.Body)
|
|
||||||
}
|
|
||||||
|
|
||||||
func loadPubKey(pubB64, pubHex string) (ed25519.PublicKey, error) {
|
|
||||||
switch {
|
|
||||||
case strings.TrimSpace(pubB64) != "":
|
|
||||||
raw, err := base64.StdEncoding.DecodeString(strings.TrimSpace(pubB64))
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
if len(raw) != ed25519.PublicKeySize {
|
|
||||||
return nil, fmt.Errorf("pubkey-base64 must decode to %d bytes", ed25519.PublicKeySize)
|
|
||||||
}
|
|
||||||
return ed25519.PublicKey(raw), nil
|
|
||||||
case strings.TrimSpace(pubHex) != "":
|
|
||||||
return bundle.ParsePublicKeyHex(pubHex)
|
|
||||||
default:
|
|
||||||
return nil, fmt.Errorf("public key required")
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func cmdVerifyBundle(args []string) int {
|
|
||||||
fs := flag.NewFlagSet("verify-bundle", flag.ExitOnError)
|
|
||||||
path := fs.String("f", "", "path to bundle.tar.gz")
|
|
||||||
pubB64 := fs.String("pubkey-base64", "", "Ed25519 public key (base64)")
|
|
||||||
pubHex := fs.String("pubkey-hex", "", "Ed25519 public key (64 hex chars)")
|
|
||||||
_ = fs.Parse(args)
|
|
||||||
|
|
||||||
if *path == "" {
|
|
||||||
fmt.Fprintln(os.Stderr, "verify-bundle: -f required")
|
|
||||||
return 2
|
|
||||||
}
|
|
||||||
pub, err := loadPubKey(*pubB64, *pubHex)
|
|
||||||
if err != nil {
|
|
||||||
fmt.Fprintln(os.Stderr, err)
|
|
||||||
return 2
|
|
||||||
}
|
|
||||||
raw, err := os.ReadFile(*path)
|
|
||||||
if err != nil {
|
|
||||||
fmt.Fprintln(os.Stderr, err)
|
|
||||||
return 1
|
|
||||||
}
|
|
||||||
v, err := signing.VerifyGzippedTar(raw, pub)
|
|
||||||
if err != nil {
|
|
||||||
fmt.Fprintln(os.Stderr, err)
|
|
||||||
return 1
|
|
||||||
}
|
|
||||||
fmt.Fprintf(os.Stderr, "ok: revision %s, %d payload files\n", v.Manifest.RevisionID, len(v.Files))
|
|
||||||
return 0
|
|
||||||
}
|
|
||||||
|
|
||||||
func cmdApplyBundle(args []string) int {
|
|
||||||
fs := flag.NewFlagSet("apply-bundle", flag.ExitOnError)
|
|
||||||
path := fs.String("f", "", "path to bundle.tar.gz")
|
|
||||||
dir := fs.String("extract-dir", "", "directory to extract into")
|
|
||||||
pubB64 := fs.String("pubkey-base64", "", "Ed25519 public key (base64)")
|
|
||||||
pubHex := fs.String("pubkey-hex", "", "Ed25519 public key (64 hex chars)")
|
|
||||||
bird := fs.String("bird", "", "bird binary (default PATH)")
|
|
||||||
birdc := fs.String("birdc", "", "birdc binary (default PATH)")
|
|
||||||
socket := fs.String("socket", "", "birdc -s socket path")
|
|
||||||
timeout := fs.Duration("timeout", 30*time.Second, "timeout for bird/birdc")
|
|
||||||
_ = fs.Parse(args)
|
|
||||||
|
|
||||||
if *path == "" || *dir == "" {
|
|
||||||
fmt.Fprintln(os.Stderr, "apply-bundle: -f and -extract-dir required")
|
|
||||||
return 2
|
|
||||||
}
|
|
||||||
pub, err := loadPubKey(*pubB64, *pubHex)
|
|
||||||
if err != nil {
|
|
||||||
fmt.Fprintln(os.Stderr, err)
|
|
||||||
return 2
|
|
||||||
}
|
|
||||||
raw, err := os.ReadFile(*path)
|
|
||||||
if err != nil {
|
|
||||||
fmt.Fprintln(os.Stderr, err)
|
|
||||||
return 1
|
|
||||||
}
|
|
||||||
v, err := signing.VerifyGzippedTar(raw, pub)
|
|
||||||
if err != nil {
|
|
||||||
fmt.Fprintln(os.Stderr, err)
|
|
||||||
return 1
|
|
||||||
}
|
|
||||||
root := filepath.Clean(*dir)
|
|
||||||
if err := os.MkdirAll(root, 0o755); err != nil {
|
|
||||||
fmt.Fprintln(os.Stderr, err)
|
|
||||||
return 1
|
|
||||||
}
|
|
||||||
if err := bundle.WriteExtractedFiles(root, v); err != nil {
|
|
||||||
fmt.Fprintln(os.Stderr, err)
|
|
||||||
return 1
|
|
||||||
}
|
|
||||||
mainRel := v.FindMainBirdConf()
|
|
||||||
if mainRel == "" {
|
|
||||||
fmt.Fprintln(os.Stderr, "bundle has no bird.conf path in manifest")
|
|
||||||
return 1
|
|
||||||
}
|
|
||||||
mainPath := filepath.Join(root, filepath.FromSlash(strings.TrimPrefix(mainRel, "/")))
|
|
||||||
ctx, cancel := context.WithTimeout(context.Background(), *timeout)
|
|
||||||
defer cancel()
|
|
||||||
ctl := &birdfmt.BirdCtl{Bird: *bird, Birdc: *birdc, Socket: *socket}
|
|
||||||
if err := ctl.ParseCheck(ctx, mainPath); err != nil {
|
|
||||||
fmt.Fprintln(os.Stderr, err)
|
|
||||||
return 1
|
|
||||||
}
|
|
||||||
if err := ctl.Configure(ctx); err != nil {
|
|
||||||
fmt.Fprintln(os.Stderr, err)
|
|
||||||
return 1
|
|
||||||
}
|
|
||||||
fmt.Fprintf(os.Stderr, "applied revision %s (main config %s)\n", v.Manifest.RevisionID, mainPath)
|
|
||||||
return 0
|
|
||||||
}
|
}
|
||||||
@@ -41,6 +41,9 @@ func main() {
|
|||||||
|
|
||||||
apiBase := strings.TrimSpace(os.Getenv("EVOBGP_CONTROL_PLANE_URL"))
|
apiBase := strings.TrimSpace(os.Getenv("EVOBGP_CONTROL_PLANE_URL"))
|
||||||
apiTok := strings.TrimSpace(os.Getenv("EVOBGP_SCHEDULER_BEARER"))
|
apiTok := strings.TrimSpace(os.Getenv("EVOBGP_SCHEDULER_BEARER"))
|
||||||
|
if os.Getenv("EVOBGP_SCHEDULER_STANDALONE") == "1" && apiBase == "" {
|
||||||
|
log.Fatal("evobgp-scheduler: EVOBGP_SCHEDULER_STANDALONE=1 requires EVOBGP_CONTROL_PLANE_URL and EVOBGP_SCHEDULER_BEARER (split deploy must not use in-process jobs.Registry)")
|
||||||
|
}
|
||||||
deps := &scheduler.Deps{
|
deps := &scheduler.Deps{
|
||||||
Store: st,
|
Store: st,
|
||||||
HTTP: &http.Client{Timeout: 45 * time.Second},
|
HTTP: &http.Client{Timeout: 45 * time.Second},
|
||||||
|
|||||||
@@ -96,7 +96,7 @@ services:
|
|||||||
<<: *env-ref
|
<<: *env-ref
|
||||||
EVOBGP_HTTP_ADDR: ":8080"
|
EVOBGP_HTTP_ADDR: ":8080"
|
||||||
EVOBGP_SEED_DEMO: "1"
|
EVOBGP_SEED_DEMO: "1"
|
||||||
# Local reference only: allows Bearer dev for scheduler HTTP client (EVOBGP_SCHEDULER_BEARER).
|
# DEV ONLY — не для production. Bearer dev + слабые demo-секреты (см. docs/access.md).
|
||||||
EVOBGP_DEV_INSECURE: "1"
|
EVOBGP_DEV_INSECURE: "1"
|
||||||
EVOBGP_BIRDC_SOCKET: /run/bird/bird.ctl
|
EVOBGP_BIRDC_SOCKET: /run/bird/bird.ctl
|
||||||
EVOBGP_BIRDC_INTERVAL: 30s
|
EVOBGP_BIRDC_INTERVAL: 30s
|
||||||
@@ -126,6 +126,8 @@ services:
|
|||||||
condition: service_started
|
condition: service_started
|
||||||
environment:
|
environment:
|
||||||
<<: *env-ref
|
<<: *env-ref
|
||||||
|
# Split deploy: scheduler must enqueue jobs via API, not in-process Registry (ARCH-04).
|
||||||
|
EVOBGP_SCHEDULER_STANDALONE: "1"
|
||||||
EVOBGP_CONTROL_PLANE_URL: http://evobgp-api:8080
|
EVOBGP_CONTROL_PLANE_URL: http://evobgp-api:8080
|
||||||
EVOBGP_SCHEDULER_BEARER: dev
|
EVOBGP_SCHEDULER_BEARER: dev
|
||||||
logging: *default-logging
|
logging: *default-logging
|
||||||
|
|||||||
@@ -135,6 +135,7 @@ services:
|
|||||||
EVOBGP_BIRDC_INTERVAL: 30s
|
EVOBGP_BIRDC_INTERVAL: 30s
|
||||||
EVOBGP_BIRD_ACTIVE_DIR: /etc/bird
|
EVOBGP_BIRD_ACTIVE_DIR: /etc/bird
|
||||||
EVOBGP_BIRD_STAGING_DIR: /tmp/evobgp-bird-staging
|
EVOBGP_BIRD_STAGING_DIR: /tmp/evobgp-bird-staging
|
||||||
|
# DEV ONLY — не для production (см. docs/access.md).
|
||||||
EVOBGP_DEV_INSECURE: "1"
|
EVOBGP_DEV_INSECURE: "1"
|
||||||
volumes:
|
volumes:
|
||||||
- bird_etc:/etc/bird
|
- bird_etc:/etc/bird
|
||||||
|
|||||||
@@ -2,7 +2,11 @@
|
|||||||
|
|
||||||
## CI (Gitea Actions)
|
## CI (Gitea Actions)
|
||||||
|
|
||||||
Сборка образов — **`docker buildx bake`** (`deploy/docker/docker-bake.hcl`), а не матрица из восьми отдельных `docker build`.
|
Сборка образов — **`docker buildx bake`** (`deploy/docker/docker-bake.hcl`), не отдельные `docker build`.
|
||||||
|
|
||||||
|
**Publish:** push в `main` после quality gates — job **release** в [.gitea/workflows/ci.yaml](../.gitea/workflows/ci.yaml): semantic-release + bake с `VERSION` из релиза.
|
||||||
|
|
||||||
|
Локально BuildKit также кэширует `/go/pkg/mod` и `~/.cache/go-build` через `RUN --mount=type=cache`.
|
||||||
|
|
||||||
| Было | Стало |
|
| Было | Стало |
|
||||||
|------|--------|
|
|------|--------|
|
||||||
@@ -31,6 +35,8 @@ cd deploy/docker
|
|||||||
export REGISTRY=git.shts.su/<owner>
|
export REGISTRY=git.shts.su/<owner>
|
||||||
export IMAGE_TAG=latest
|
export IMAGE_TAG=latest
|
||||||
export SHORT_SHA=$(git rev-parse --short HEAD)
|
export SHORT_SHA=$(git rev-parse --short HEAD)
|
||||||
|
export VERSION=dev
|
||||||
|
export BUILD_TIME=
|
||||||
sh write-bake-override.sh
|
sh write-bake-override.sh
|
||||||
docker buildx bake --allow=fs.read=../.. -f docker-bake.hcl -f docker-bake.override.hcl go-images
|
docker buildx bake --allow=fs.read=../.. -f docker-bake.hcl -f docker-bake.override.hcl go-images
|
||||||
docker buildx bake --allow=fs.read=../.. -f docker-bake.hcl -f docker-bake.override.hcl web-images
|
docker buildx bake --allow=fs.read=../.. -f docker-bake.hcl -f docker-bake.override.hcl web-images
|
||||||
|
|||||||
@@ -19,6 +19,14 @@ variable "SHA_FULL" {
|
|||||||
default = ""
|
default = ""
|
||||||
}
|
}
|
||||||
|
|
||||||
|
variable "VERSION" {
|
||||||
|
default = "dev"
|
||||||
|
}
|
||||||
|
|
||||||
|
variable "BUILD_TIME" {
|
||||||
|
default = ""
|
||||||
|
}
|
||||||
|
|
||||||
variable "CACHE_REF_GO" {
|
variable "CACHE_REF_GO" {
|
||||||
default = ""
|
default = ""
|
||||||
}
|
}
|
||||||
@@ -87,6 +95,11 @@ target "go-build-all" {
|
|||||||
dockerfile = "deploy/docker/gobinary/Dockerfile"
|
dockerfile = "deploy/docker/gobinary/Dockerfile"
|
||||||
target = "build-all"
|
target = "build-all"
|
||||||
platforms = ["linux/amd64"]
|
platforms = ["linux/amd64"]
|
||||||
|
args = {
|
||||||
|
VERSION = VERSION
|
||||||
|
GIT_SHA = notequal("", SHA_FULL) ? SHA_FULL : SHORT_SHA
|
||||||
|
BUILD_TIME = BUILD_TIME
|
||||||
|
}
|
||||||
contexts = {
|
contexts = {
|
||||||
deps = "target:go-deps"
|
deps = "target:go-deps"
|
||||||
}
|
}
|
||||||
@@ -127,14 +140,20 @@ target "_go-runtime-birdc" {
|
|||||||
|
|
||||||
function "image-tags" {
|
function "image-tags" {
|
||||||
params = [name]
|
params = [name]
|
||||||
result = notequal("", SHA_FULL) ? [
|
result = concat(
|
||||||
"${REGISTRY}/${name}:${IMAGE_TAG}",
|
notequal("", SHA_FULL) ? [
|
||||||
"${REGISTRY}/${name}:${SHORT_SHA}",
|
"${REGISTRY}/${name}:${IMAGE_TAG}",
|
||||||
"${REGISTRY}/${name}:sha-${SHA_FULL}",
|
"${REGISTRY}/${name}:${SHORT_SHA}",
|
||||||
] : [
|
"${REGISTRY}/${name}:sha-${SHA_FULL}",
|
||||||
"${REGISTRY}/${name}:${IMAGE_TAG}",
|
] : [
|
||||||
"${REGISTRY}/${name}:${SHORT_SHA}",
|
"${REGISTRY}/${name}:${IMAGE_TAG}",
|
||||||
]
|
"${REGISTRY}/${name}:${SHORT_SHA}",
|
||||||
|
],
|
||||||
|
notequal(VERSION, "dev") && notequal(VERSION, "") ? [
|
||||||
|
"${REGISTRY}/${name}:v${VERSION}",
|
||||||
|
"${REGISTRY}/${name}:${VERSION}",
|
||||||
|
] : []
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
target "evobgp-api" {
|
target "evobgp-api" {
|
||||||
|
|||||||
@@ -5,8 +5,14 @@ server {
|
|||||||
gzip on;
|
gzip on;
|
||||||
gzip_types text/css application/javascript application/json image/svg+xml;
|
gzip_types text/css application/javascript application/json image/svg+xml;
|
||||||
|
|
||||||
|
# Docker embedded DNS: без resolver nginx кэширует IP upstream при старте —
|
||||||
|
# после recreate evobgp-all остаётся 502 (connection refused на старый IP).
|
||||||
|
resolver 127.0.0.11 valid=10s ipv6=off;
|
||||||
|
set $evobgp_upstream evobgp-api;
|
||||||
|
|
||||||
location /v1/ {
|
location /v1/ {
|
||||||
proxy_pass http://evobgp-api:8080/v1/;
|
# С переменной в proxy_pass нельзя полагаться на замену URI — передаём $request_uri целиком.
|
||||||
|
proxy_pass http://$evobgp_upstream:8080$request_uri;
|
||||||
proxy_http_version 1.1;
|
proxy_http_version 1.1;
|
||||||
proxy_set_header Host $host;
|
proxy_set_header Host $host;
|
||||||
proxy_set_header X-Real-IP $remote_addr;
|
proxy_set_header X-Real-IP $remote_addr;
|
||||||
@@ -15,7 +21,7 @@ server {
|
|||||||
}
|
}
|
||||||
|
|
||||||
location = /metrics {
|
location = /metrics {
|
||||||
proxy_pass http://evobgp-api:8080/metrics;
|
proxy_pass http://$evobgp_upstream:8080/metrics;
|
||||||
proxy_http_version 1.1;
|
proxy_http_version 1.1;
|
||||||
proxy_set_header Host $host;
|
proxy_set_header Host $host;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -10,22 +10,38 @@ RUN --mount=type=cache,target=/go/pkg/mod,sharing=locked \
|
|||||||
|
|
||||||
FROM deps AS build-all
|
FROM deps AS build-all
|
||||||
COPY . .
|
COPY . .
|
||||||
|
ARG VERSION=dev
|
||||||
|
ARG GIT_SHA=unknown
|
||||||
|
ARG BUILD_TIME=
|
||||||
RUN --mount=type=cache,target=/go/pkg/mod,sharing=locked \
|
RUN --mount=type=cache,target=/go/pkg/mod,sharing=locked \
|
||||||
--mount=type=cache,target=/root/.cache/go-build,sharing=locked \
|
--mount=type=cache,target=/root/.cache/go-build,sharing=locked \
|
||||||
set -eux; \
|
set -eux; \
|
||||||
mkdir -p /out; \
|
mkdir -p /out; \
|
||||||
for d in cmd/*/; do \
|
for d in cmd/*/; do \
|
||||||
name="$(basename "$d")"; \
|
name="$(basename "$d")"; \
|
||||||
CGO_ENABLED=0 go build -trimpath -ldflags="-s -w" -o "/out/${name}" "./cmd/${name}"; \
|
CGO_ENABLED=0 go build -trimpath \
|
||||||
|
-ldflags="-s -w \
|
||||||
|
-X evobgp/internal/version.Version=${VERSION} \
|
||||||
|
-X evobgp/internal/version.GitSHA=${GIT_SHA} \
|
||||||
|
-X evobgp/internal/version.BuildTime=${BUILD_TIME}" \
|
||||||
|
-o "/out/${name}" "./cmd/${name}"; \
|
||||||
done
|
done
|
||||||
|
|
||||||
# Один бинарь (локальная сборка); в CI — build-all + runtime.
|
# Один бинарь (локальная сборка); в CI — build-all + runtime.
|
||||||
FROM deps AS build
|
FROM deps AS build
|
||||||
COPY . .
|
COPY . .
|
||||||
ARG BIN=evobgp-api
|
ARG BIN=evobgp-api
|
||||||
|
ARG VERSION=dev
|
||||||
|
ARG GIT_SHA=unknown
|
||||||
|
ARG BUILD_TIME=
|
||||||
RUN --mount=type=cache,target=/go/pkg/mod,sharing=locked \
|
RUN --mount=type=cache,target=/go/pkg/mod,sharing=locked \
|
||||||
--mount=type=cache,target=/root/.cache/go-build,sharing=locked \
|
--mount=type=cache,target=/root/.cache/go-build,sharing=locked \
|
||||||
CGO_ENABLED=0 go build -trimpath -ldflags="-s -w" -o /out/evobgp "./cmd/${BIN}"
|
CGO_ENABLED=0 go build -trimpath \
|
||||||
|
-ldflags="-s -w \
|
||||||
|
-X evobgp/internal/version.Version=${VERSION} \
|
||||||
|
-X evobgp/internal/version.GitSHA=${GIT_SHA} \
|
||||||
|
-X evobgp/internal/version.BuildTime=${BUILD_TIME}" \
|
||||||
|
-o /out/evobgp "./cmd/${BIN}"
|
||||||
|
|
||||||
FROM public.ecr.aws/docker/library/debian:bookworm-slim AS birdc
|
FROM public.ecr.aws/docker/library/debian:bookworm-slim AS birdc
|
||||||
ARG BIRD_VERSION=2.14
|
ARG BIRD_VERSION=2.14
|
||||||
|
|||||||
@@ -6,6 +6,8 @@ REGISTRY="${REGISTRY:?REGISTRY required}"
|
|||||||
IMAGE_TAG="${IMAGE_TAG:-latest}"
|
IMAGE_TAG="${IMAGE_TAG:-latest}"
|
||||||
SHORT_SHA="${SHORT_SHA:-dev}"
|
SHORT_SHA="${SHORT_SHA:-dev}"
|
||||||
SHA_FULL="${SHA_FULL:-}"
|
SHA_FULL="${SHA_FULL:-}"
|
||||||
|
VERSION="${VERSION:-dev}"
|
||||||
|
BUILD_TIME="${BUILD_TIME:-}"
|
||||||
CACHE_REF_GO="${CACHE_REF_GO:-}"
|
CACHE_REF_GO="${CACHE_REF_GO:-}"
|
||||||
CACHE_REF_WEB="${CACHE_REF_WEB:-}"
|
CACHE_REF_WEB="${CACHE_REF_WEB:-}"
|
||||||
cat >"$OUT" <<EOF
|
cat >"$OUT" <<EOF
|
||||||
@@ -22,6 +24,12 @@ variable "SHORT_SHA" {
|
|||||||
variable "SHA_FULL" {
|
variable "SHA_FULL" {
|
||||||
default = "${SHA_FULL}"
|
default = "${SHA_FULL}"
|
||||||
}
|
}
|
||||||
|
variable "VERSION" {
|
||||||
|
default = "${VERSION}"
|
||||||
|
}
|
||||||
|
variable "BUILD_TIME" {
|
||||||
|
default = "${BUILD_TIME}"
|
||||||
|
}
|
||||||
variable "CACHE_REF_GO" {
|
variable "CACHE_REF_GO" {
|
||||||
default = "${CACHE_REF_GO}"
|
default = "${CACHE_REF_GO}"
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -20,6 +20,7 @@
|
|||||||
| [api.md](api.md) | REST: префикс `/v1`, публичные маршруты, ссылки на OpenAPI |
|
| [api.md](api.md) | REST: префикс `/v1`, публичные маршруты, ссылки на OpenAPI |
|
||||||
| [router-lists-ui-integration.md](router-lists-ui-integration.md) | Интеграция `router-lists-ui` с EvoBGP API (`DOMAINS/IP_RANGES/AS_PREFIXES/communities`) |
|
| [router-lists-ui-integration.md](router-lists-ui-integration.md) | Интеграция `router-lists-ui` с EvoBGP API (`DOMAINS/IP_RANGES/AS_PREFIXES/communities`) |
|
||||||
| [access.md](access.md) | Выдача доступа: API-ключи, роли, нода, CORS |
|
| [access.md](access.md) | Выдача доступа: API-ключи, роли, нода, CORS |
|
||||||
|
| [releasing.md](releasing.md) | Автоматические релизы, Conventional Commits, CI |
|
||||||
| [openapi.yaml](openapi.yaml) | Источник правды по контракту API |
|
| [openapi.yaml](openapi.yaml) | Источник правды по контракту API |
|
||||||
| [OPENAPI-GITEA.md](OPENAPI-GITEA.md) | Как открыть HTML-документацию API (в т.ч. из Gitea) |
|
| [OPENAPI-GITEA.md](OPENAPI-GITEA.md) | Как открыть HTML-документацию API (в т.ч. из Gitea) |
|
||||||
| [evobgp-api-sketches.md](evobgp-api-sketches.md) | Ранний черновик идей API (контекст, не замена OpenAPI) |
|
| [evobgp-api-sketches.md](evobgp-api-sketches.md) | Ранний черновик идей API (контекст, не замена OpenAPI) |
|
||||||
@@ -31,7 +32,22 @@
|
|||||||
| [../.cursor/rules/engineering.mdc](../.cursor/rules/engineering.mdc) | Go, API, migrations, security, enforcement |
|
| [../.cursor/rules/engineering.mdc](../.cursor/rules/engineering.mdc) | Go, API, migrations, security, enforcement |
|
||||||
| [../.cursor/rules/web-shadcn.mdc](../.cursor/rules/web-shadcn.mdc) | SvelteKit, shadcn-svelte |
|
| [../.cursor/rules/web-shadcn.mdc](../.cursor/rules/web-shadcn.mdc) | SvelteKit, shadcn-svelte |
|
||||||
| [../.cursor/rules/networking-bird.mdc](../.cursor/rules/networking-bird.mdc) | BIRD2, BGP policy, IP/CIDR |
|
| [../.cursor/rules/networking-bird.mdc](../.cursor/rules/networking-bird.mdc) | BIRD2, BGP policy, IP/CIDR |
|
||||||
|
| [../.cursor/rules/conventional-commits.mdc](../.cursor/rules/conventional-commits.mdc) | Conventional Commits (заголовок EN, тело RU) |
|
||||||
|
|
||||||
|
### Сообщения коммитов (Cursor)
|
||||||
|
|
||||||
|
После `git add`:
|
||||||
|
|
||||||
|
| Способ | Skill + rule + `staged-context.ps1` |
|
||||||
|
|--------|-------------------------------------|
|
||||||
|
| Agent → **`/commit-message`** или «сгенерируй коммит по staged» | **Да** |
|
||||||
|
| Кнопка **✨ Generate commit message** в Source Control | **Нет** (только diff + история; [ограничение Cursor](https://forum.cursor.com/t/how-to-set-prompt-for-generate-commit-message/148606)) |
|
||||||
|
|
||||||
|
Рекомендуемый workflow: Agent Chat → **`/commit-message`** ([команда](../.cursor/commands/commit-message.md), [скилл](../.cursor/skills/commit-message/SKILL.md), [правило](../.cursor/rules/conventional-commits.mdc)). Агент **обязан первым делом** запустить `scripts/commit/staged-context.ps1` (заголовок EN, тело RU, auto-split).
|
||||||
|
|
||||||
|
Просмотр групп вручную: `powershell -NoProfile -File scripts/commit/staged-context.ps1 | ConvertFrom-Json`.
|
||||||
|
|
||||||
## Репозиторий и CI
|
## Репозиторий и CI
|
||||||
|
|
||||||
- [../.gitea/README.md](../.gitea/README.md) — Gitea Actions, runner, сборка образов и push в Container Registry.
|
- [../.gitea/README.md](../.gitea/README.md) — Gitea Actions, runner, сборка образов и push в Container Registry.
|
||||||
|
- [releasing.md](releasing.md) — semantic-release, commit conventions, теги образов.
|
||||||
+6
-1
@@ -37,7 +37,12 @@ opkey|01ARZ3NDEKTSV4RRFFQ69G5FAV|operator,nodekey|01ARZ3NDEKTSV4RRFFQ69G5FAV|nod
|
|||||||
|
|
||||||
Если установлено `EVOBGP_DEV_INSECURE=1` и в store доступен демо-tenant (`DemoIDs`), то запрос с заголовком **`Authorization: Bearer dev`** получает контекст **`operator`** для этого tenant.
|
Если установлено `EVOBGP_DEV_INSECURE=1` и в store доступен демо-tenant (`DemoIDs`), то запрос с заголовком **`Authorization: Bearer dev`** получает контекст **`operator`** для этого tenant.
|
||||||
|
|
||||||
**Запрещено** в продакшене: любой, кто знает заголовок, получает полные права оператора на демо-данные.
|
**Запрещено** в продакшене: любой, кто знает заголовок, получает полные права оператора на демо-данные. В reference Compose (`deploy/compose/docker-compose.yaml`) флаг включён только для локальной разработки.
|
||||||
|
|
||||||
|
### Синхронные «тяжёлые» GET (control plane)
|
||||||
|
|
||||||
|
- `POST /v1/modules/{module_id}/cdn-sources/preview` — загрузка CDN в том же HTTP-запросе (лимит тела ~8 MiB, см. OpenAPI).
|
||||||
|
- `GET /v1/bird/status` (если маршрут включён в деплое) — опрос локального `birdc`, таймаут сервера ~12 с.
|
||||||
|
|
||||||
### Детерминированный ключ подписи бандлов (тесты)
|
### Детерминированный ключ подписи бандлов (тесты)
|
||||||
|
|
||||||
|
|||||||
+44
-4
@@ -1,10 +1,12 @@
|
|||||||
openapi: 3.1.0
|
openapi: 3.1.0
|
||||||
info:
|
info:
|
||||||
title: EvoBGP Control Plane API
|
title: EvoBGP Control Plane API
|
||||||
version: 0.1.0
|
version: 1.0.0
|
||||||
description: |
|
description: |
|
||||||
REST API управления префиксами, модулями ingest, ревизиями конфигурации BIRD и задачами (async jobs).
|
REST API управления префиксами, модулями ingest, ревизиями конфигурации BIRD и задачами (async jobs).
|
||||||
|
|
||||||
|
**Актуальная semver-сборка:** `GET /version` или `GET /v1/version` (поле `version`; совпадает с git-тегом `vX.Y.Z`).
|
||||||
|
|
||||||
**Соглашения:** префикс `/v1`; идентификаторы - UUID v7 или ULID (строки); время - ISO 8601 UTC.
|
**Соглашения:** префикс `/v1`; идентификаторы - UUID v7 или ULID (строки); время - ISO 8601 UTC.
|
||||||
Ошибки - `application/problem+json` ([RFC 9457](https://www.rfc-editor.org/rfc/rfc9457)).
|
Ошибки - `application/problem+json` ([RFC 9457](https://www.rfc-editor.org/rfc/rfc9457)).
|
||||||
Пагинация списков - `cursor` + `limit`; ответ содержит `items`, `next_cursor`, `has_more`.
|
Пагинация списков - `cursor` + `limit`; ответ содержит `items`, `next_cursor`, `has_more`.
|
||||||
@@ -65,7 +67,9 @@ components:
|
|||||||
required: false
|
required: false
|
||||||
schema:
|
schema:
|
||||||
$ref: "#/components/schemas/ResourceId"
|
$ref: "#/components/schemas/ResourceId"
|
||||||
description: Явный tenant (только супер-роли). Без заголовка tenant определяется по ключу.
|
description: >
|
||||||
|
Явный tenant (только супер-роли). Без заголовка tenant определяется по API-ключу.
|
||||||
|
**Реализация v1:** заголовок в Go handlers не обрабатывается; tenant только из Bearer-токена (см. docs/access.md).
|
||||||
IdempotencyKey:
|
IdempotencyKey:
|
||||||
name: Idempotency-Key
|
name: Idempotency-Key
|
||||||
in: header
|
in: header
|
||||||
@@ -606,6 +610,9 @@ components:
|
|||||||
properties:
|
properties:
|
||||||
id:
|
id:
|
||||||
$ref: "#/components/schemas/ResourceId"
|
$ref: "#/components/schemas/ResourceId"
|
||||||
|
name:
|
||||||
|
type: string
|
||||||
|
description: Отображаемое имя профиля (опционально).
|
||||||
url:
|
url:
|
||||||
type: string
|
type: string
|
||||||
format: uri
|
format: uri
|
||||||
@@ -621,6 +628,9 @@ components:
|
|||||||
required:
|
required:
|
||||||
- url
|
- url
|
||||||
properties:
|
properties:
|
||||||
|
name:
|
||||||
|
type: string
|
||||||
|
description: Отображаемое имя профиля (опционально).
|
||||||
url:
|
url:
|
||||||
type: string
|
type: string
|
||||||
format: uri
|
format: uri
|
||||||
@@ -752,8 +762,14 @@ components:
|
|||||||
VersionInfo:
|
VersionInfo:
|
||||||
type: object
|
type: object
|
||||||
properties:
|
properties:
|
||||||
|
version:
|
||||||
|
type: string
|
||||||
|
description: Semver сборки (git tag без префикса v).
|
||||||
|
example: "1.2.3"
|
||||||
api_version:
|
api_version:
|
||||||
type: string
|
type: string
|
||||||
|
deprecated: true
|
||||||
|
description: Alias поля `version` (сохранён для обратной совместимости).
|
||||||
git_sha:
|
git_sha:
|
||||||
type: string
|
type: string
|
||||||
build_time:
|
build_time:
|
||||||
@@ -840,6 +856,8 @@ components:
|
|||||||
DohProfilePatch:
|
DohProfilePatch:
|
||||||
type: object
|
type: object
|
||||||
properties:
|
properties:
|
||||||
|
name:
|
||||||
|
type: string
|
||||||
url:
|
url:
|
||||||
type: string
|
type: string
|
||||||
format: uri
|
format: uri
|
||||||
@@ -959,11 +977,31 @@ paths:
|
|||||||
default:
|
default:
|
||||||
$ref: "#/components/responses/DefaultProblem"
|
$ref: "#/components/responses/DefaultProblem"
|
||||||
|
|
||||||
|
/version:
|
||||||
|
get:
|
||||||
|
tags: [System]
|
||||||
|
summary: Версия сборки (корневой путь)
|
||||||
|
description: |
|
||||||
|
Аналог `GET /v1/version`. Публичный маршрут без аутентификации.
|
||||||
|
Semver в поле `version` задаётся при сборке Docker-образов из git-тега.
|
||||||
|
operationId: getVersionRoot
|
||||||
|
responses:
|
||||||
|
"200":
|
||||||
|
description: Метаданные сборки.
|
||||||
|
content:
|
||||||
|
application/json:
|
||||||
|
schema:
|
||||||
|
$ref: "#/components/schemas/VersionInfo"
|
||||||
|
default:
|
||||||
|
$ref: "#/components/responses/DefaultProblem"
|
||||||
|
|
||||||
/v1/version:
|
/v1/version:
|
||||||
get:
|
get:
|
||||||
tags: [System]
|
tags: [System]
|
||||||
summary: Версия сборки
|
summary: Версия сборки
|
||||||
description: Версия API и control-plane (`git_sha`, `build_time` и др.).
|
description: |
|
||||||
|
Semver control-plane и метаданные сборки (`git_sha`, `build_time`).
|
||||||
|
Дублирует `GET /version`.
|
||||||
operationId: getVersion
|
operationId: getVersion
|
||||||
responses:
|
responses:
|
||||||
"200":
|
"200":
|
||||||
@@ -1775,7 +1813,9 @@ paths:
|
|||||||
tags: [Modules]
|
tags: [Modules]
|
||||||
summary: Предпросмотр префиксов из CDN-источника
|
summary: Предпросмотр префиксов из CDN-источника
|
||||||
description: >
|
description: >
|
||||||
Загружает URL, парсит как plaintext или json и возвращает список извлечённых префиксов (до 100 записей).
|
Синхронный запрос: conditional GET к URL (до 8 MiB тела ответа), парсинг plaintext или JSON,
|
||||||
|
возврат до 100 префиксов в `items` (полный счётчик в `total`). Выполняется в HTTP worker;
|
||||||
|
при таймауте клиента используйте короткий URL или меньший payload.
|
||||||
operationId: previewCdnSource
|
operationId: previewCdnSource
|
||||||
requestBody:
|
requestBody:
|
||||||
required: true
|
required: true
|
||||||
|
|||||||
@@ -0,0 +1,78 @@
|
|||||||
|
# Релизы и версионирование EvoBGP
|
||||||
|
|
||||||
|
EvoBGP использует [Conventional Commits](https://www.conventionalcommits.org/) и [semantic-release](https://semantic-release.gitbook.io/) для полностью автоматических релизов на Gitea (`git.shts.su`). Ручное повышение версии в коде не требуется.
|
||||||
|
|
||||||
|
## Как определяется версия
|
||||||
|
|
||||||
|
| Тип коммита | Bump |
|
||||||
|
|-------------|------|
|
||||||
|
| `feat` | minor (1.0.0 → 1.1.0) |
|
||||||
|
| `fix`, `perf`, `ci`, `refactor` | patch (1.5.1 → 1.5.2) |
|
||||||
|
| `feat!`, `fix!` или `BREAKING CHANGE:` в теле | major (1.0.0 → 2.0.0) |
|
||||||
|
| `docs`, `chore`, `test` | без релиза |
|
||||||
|
|
||||||
|
`refactor` — patch без новых функций: перестройка кода/UI при том же поведении для пользователя. По semver на одном уровне с `fix`, но семантически «мельче» `feat` (не minor).
|
||||||
|
|
||||||
|
Отдельного суффикса `1.x.y.fix` в semver нет: «fix» в Conventional Commits означает **patch** (третья цифра). Для починки пайплайна без смены продукта — `fix(ci):` или `ci:` (оба дают patch после настройки `.releaserc.json`).
|
||||||
|
|
||||||
|
Первый релиз при отсутствии git-тегов — **1.0.0**, если есть releasable-коммиты.
|
||||||
|
|
||||||
|
**Как не перепутать `feat` и `fix`:** см. раздел «Выбор type: semver, а не «красивые слова»» в [.cursor/rules/conventional-commits.mdc](../.cursor/rules/conventional-commits.mdc). Кратко: `feat` — новая возможность (minor); `fix` — починка ожидаемого поведения (patch); follow-up баги после недавнего `feat` — всегда `fix`, даже если diff большой.
|
||||||
|
|
||||||
|
Подробные правила сообщений коммитов: [.cursor/rules/conventional-commits.mdc](../.cursor/rules/conventional-commits.mdc).
|
||||||
|
|
||||||
|
## CI-пайплайн (один push в main)
|
||||||
|
|
||||||
|
```text
|
||||||
|
push/merge в main
|
||||||
|
→ CI: openapi, web, go, bird2 (параллельно)
|
||||||
|
→ job release (в том же workflow, после quality gates):
|
||||||
|
→ semantic-release: git tag vX.Y.Z на текущий commit (без доп. commit)
|
||||||
|
→ Gitea Release + CHANGELOG.md как attachment
|
||||||
|
→ docker buildx bake с VERSION=X.Y.Z
|
||||||
|
→ образы: latest, vX.Y.Z, X.Y.Z, sha-*, короткий SHA
|
||||||
|
```
|
||||||
|
|
||||||
|
Pull request: только quality gates + commitlint; релиз и образы **не** публикуются.
|
||||||
|
|
||||||
|
Workflow: [.gitea/workflows/ci.yaml](../.gitea/workflows/ci.yaml) (job **release**).
|
||||||
|
|
||||||
|
Конфиг semantic-release: [.releaserc.json](../.releaserc.json) — без `@semantic-release/git` (CHANGELOG не коммитится в репозиторий).
|
||||||
|
|
||||||
|
## Секреты Gitea
|
||||||
|
|
||||||
|
Один PAT — **`ACTIONS_PAT`** (Settings → Actions → Secrets).
|
||||||
|
|
||||||
|
| Право PAT | Зачем |
|
||||||
|
|-----------|--------|
|
||||||
|
| push tags | git tag `vX.Y.Z` на commit merge |
|
||||||
|
| releases | Gitea Release + notes |
|
||||||
|
| packages (Container Registry) | push образов |
|
||||||
|
|
||||||
|
Fallback: **`gitea.token`** (нужны права на releases и packages).
|
||||||
|
|
||||||
|
## Источник правды для версии в runtime
|
||||||
|
|
||||||
|
Semver из git-тега пробрасывается в Go-бинарники через `-ldflags` при сборке Docker (`deploy/docker/gobinary/Dockerfile`). Пакет [`internal/version`](../internal/version/version.go):
|
||||||
|
|
||||||
|
- локально (`go run`) — `version: "dev"`
|
||||||
|
- в образе после релиза — совпадает с тегом (например `1.2.3`)
|
||||||
|
|
||||||
|
API: `GET /version`, `GET /v1/version` — поля `version`, `git_sha`, `build_time`.
|
||||||
|
|
||||||
|
Web UI показывает версию из API (footer sidebar, страница «Мониторинг»).
|
||||||
|
|
||||||
|
## CHANGELOG
|
||||||
|
|
||||||
|
Release notes — в Gitea Release; файл `CHANGELOG.md` генерируется в CI и прикрепляется как asset, **не** попадает в git history.
|
||||||
|
|
||||||
|
## Проверка после релиза
|
||||||
|
|
||||||
|
1. Один run workflow **CI** на push в main: job **release** зелёный.
|
||||||
|
2. Gitea: тег `vX.Y.Z` на том же commit, что и merge; Release с notes.
|
||||||
|
3. Container Registry: `evobgp-api:vX.Y.Z`, `evobgp-api:X.Y.Z`, `evobgp-api:latest`.
|
||||||
|
4. `curl http://localhost:8080/version` → `"version":"X.Y.Z"`.
|
||||||
|
|
||||||
|
## Первый релиз (bootstrap)
|
||||||
|
|
||||||
|
Merge в `main` с `feat(release): ...` → **v1.0.0** в том же CI run.
|
||||||
@@ -42,7 +42,7 @@ func AnnouncedPrefixes(ctx context.Context, hc *http.Client, asn int64) ([]netip
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, fmt.Errorf("ripestat fetch AS%d: %w", asn, err)
|
return nil, fmt.Errorf("ripestat fetch AS%d: %w", asn, err)
|
||||||
}
|
}
|
||||||
defer resp.Body.Close()
|
defer func() { _ = resp.Body.Close() }()
|
||||||
body, err := io.ReadAll(io.LimitReader(resp.Body, 32<<20))
|
body, err := io.ReadAll(io.LimitReader(resp.Body, 32<<20))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
@@ -52,8 +52,8 @@ func AnnouncedPrefixes(ctx context.Context, hc *http.Client, asn int64) ([]netip
|
|||||||
}
|
}
|
||||||
|
|
||||||
var wrap struct {
|
var wrap struct {
|
||||||
Status string `json:"status"`
|
Status string `json:"status"`
|
||||||
Data struct {
|
Data struct {
|
||||||
Prefixes []struct {
|
Prefixes []struct {
|
||||||
Prefix string `json:"prefix"`
|
Prefix string `json:"prefix"`
|
||||||
} `json:"prefixes"`
|
} `json:"prefixes"`
|
||||||
@@ -104,7 +104,7 @@ func ASHolderName(ctx context.Context, hc *http.Client, asn int64) (string, erro
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return "", fmt.Errorf("ripestat as-overview AS%d: %w", asn, err)
|
return "", fmt.Errorf("ripestat as-overview AS%d: %w", asn, err)
|
||||||
}
|
}
|
||||||
defer resp.Body.Close()
|
defer func() { _ = resp.Body.Close() }()
|
||||||
body, err := io.ReadAll(io.LimitReader(resp.Body, 4<<20))
|
body, err := io.ReadAll(io.LimitReader(resp.Body, 4<<20))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return "", err
|
return "", err
|
||||||
|
|||||||
@@ -60,10 +60,10 @@ func RenderBGPTemplates(opts BGPTemplatesOptions) (string, error) {
|
|||||||
|
|
||||||
// BGPPeerFromTemplateOptions describes protocol bgp NAME from TEMPLATE { … }.
|
// BGPPeerFromTemplateOptions describes protocol bgp NAME from TEMPLATE { … }.
|
||||||
type BGPPeerFromTemplateOptions struct {
|
type BGPPeerFromTemplateOptions struct {
|
||||||
ProtocolName string
|
ProtocolName string
|
||||||
TemplateName string
|
TemplateName string
|
||||||
NeighborIP string
|
NeighborIP string
|
||||||
NeighborASN uint32
|
NeighborASN uint32
|
||||||
// If set, emits "local … as …" before neighbor (overrides template local/ASN for this peer).
|
// If set, emits "local … as …" before neighbor (overrides template local/ASN for this peer).
|
||||||
OverrideLocalIP string
|
OverrideLocalIP string
|
||||||
OverrideLocalASN uint32
|
OverrideLocalASN uint32
|
||||||
|
|||||||
@@ -9,6 +9,21 @@ import (
|
|||||||
|
|
||||||
const maxBGPASN = 4294967295
|
const maxBGPASN = 4294967295
|
||||||
|
|
||||||
|
const filterPrefixChunkSize = 500
|
||||||
|
|
||||||
|
func writePrefixSetAcceptBlocks(b *strings.Builder, keys []string) {
|
||||||
|
for i := 0; i < len(keys); i += filterPrefixChunkSize {
|
||||||
|
end := i + filterPrefixChunkSize
|
||||||
|
if end > len(keys) {
|
||||||
|
end = len(keys)
|
||||||
|
}
|
||||||
|
chunk := keys[i:end]
|
||||||
|
b.WriteString(" if net ~ [ ")
|
||||||
|
b.WriteString(strings.Join(chunk, ", "))
|
||||||
|
b.WriteString(" ] then accept;\n")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func filterUniqueASNs(pathASNs []int64) []int64 {
|
func filterUniqueASNs(pathASNs []int64) []int64 {
|
||||||
seen := make(map[int64]struct{})
|
seen := make(map[int64]struct{})
|
||||||
for _, a := range pathASNs {
|
for _, a := range pathASNs {
|
||||||
@@ -52,9 +67,7 @@ func RenderExportFilterIPv4(filterName string, prefixes []netip.Prefix, pathASNs
|
|||||||
b.WriteString(strings.TrimSpace(filterName))
|
b.WriteString(strings.TrimSpace(filterName))
|
||||||
b.WriteString(" {\n")
|
b.WriteString(" {\n")
|
||||||
if len(keys) > 0 {
|
if len(keys) > 0 {
|
||||||
b.WriteString(" if net ~ [ ")
|
writePrefixSetAcceptBlocks(&b, keys)
|
||||||
b.WriteString(strings.Join(keys, ", "))
|
|
||||||
b.WriteString(" ] then accept;\n")
|
|
||||||
}
|
}
|
||||||
for _, asn := range asns {
|
for _, asn := range asns {
|
||||||
fmt.Fprintf(&b, " if bgp_path ~ [= * %d =] then accept;\n", asn)
|
fmt.Fprintf(&b, " if bgp_path ~ [= * %d =] then accept;\n", asn)
|
||||||
@@ -95,9 +108,7 @@ func RenderExportFilterIPv6(filterName string, prefixes []netip.Prefix, pathASNs
|
|||||||
b.WriteString(strings.TrimSpace(filterName))
|
b.WriteString(strings.TrimSpace(filterName))
|
||||||
b.WriteString(" {\n")
|
b.WriteString(" {\n")
|
||||||
if len(keys) > 0 {
|
if len(keys) > 0 {
|
||||||
b.WriteString(" if net ~ [ ")
|
writePrefixSetAcceptBlocks(&b, keys)
|
||||||
b.WriteString(strings.Join(keys, ", "))
|
|
||||||
b.WriteString(" ] then accept;\n")
|
|
||||||
}
|
}
|
||||||
for _, asn := range asns {
|
for _, asn := range asns {
|
||||||
fmt.Fprintf(&b, " if bgp_path ~ [= * %d =] then accept;\n", asn)
|
fmt.Fprintf(&b, " if bgp_path ~ [= * %d =] then accept;\n", asn)
|
||||||
|
|||||||
@@ -50,3 +50,48 @@ func CountEstablishedBGPSessions(showProtocolsOutput string) int {
|
|||||||
}
|
}
|
||||||
return n
|
return n
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ParseBGPProtocolStates parses `birdc show protocols all` summary rows into protocol_name -> state.
|
||||||
|
func ParseBGPProtocolStates(output string) map[string]string {
|
||||||
|
out := make(map[string]string)
|
||||||
|
for _, raw := range strings.Split(output, "\n") {
|
||||||
|
line := strings.TrimSpace(raw)
|
||||||
|
if line == "" {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
low := strings.ToLower(line)
|
||||||
|
if strings.HasPrefix(low, "bird ") || strings.HasPrefix(low, "name ") || strings.HasPrefix(low, "table ") {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
fields := strings.Fields(line)
|
||||||
|
if len(fields) < 4 {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
if !strings.EqualFold(fields[1], "BGP") {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
state := extractBGPSessionStateLine(line)
|
||||||
|
if state == "" {
|
||||||
|
state = fields[3]
|
||||||
|
}
|
||||||
|
out[fields[0]] = state
|
||||||
|
}
|
||||||
|
return out
|
||||||
|
}
|
||||||
|
|
||||||
|
func extractBGPSessionStateLine(line string) string {
|
||||||
|
known := []string{
|
||||||
|
"Established",
|
||||||
|
"Idle",
|
||||||
|
"Connect",
|
||||||
|
"Active",
|
||||||
|
"OpenSent",
|
||||||
|
"OpenConfirm",
|
||||||
|
}
|
||||||
|
for _, st := range known {
|
||||||
|
if strings.Contains(line, st) {
|
||||||
|
return st
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return ""
|
||||||
|
}
|
||||||
@@ -17,12 +17,12 @@ import (
|
|||||||
|
|
||||||
// Manifest describes bundle contents for evobgp-node verification.
|
// Manifest describes bundle contents for evobgp-node verification.
|
||||||
type Manifest struct {
|
type Manifest struct {
|
||||||
RevisionID string `json:"revision_id"`
|
RevisionID string `json:"revision_id"`
|
||||||
SpeakerID string `json:"speaker_id,omitempty"`
|
SpeakerID string `json:"speaker_id,omitempty"`
|
||||||
CreatedAt time.Time `json:"created_at"`
|
CreatedAt time.Time `json:"created_at"`
|
||||||
Files []FileEntry `json:"files"`
|
Files []FileEntry `json:"files"`
|
||||||
Algorithm string `json:"signature_algorithm"`
|
Algorithm string `json:"signature_algorithm"`
|
||||||
PublicKeyB64 string `json:"public_key_base64"`
|
PublicKeyB64 string `json:"public_key_base64"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// FileEntry is one file inside the bundle archive.
|
// FileEntry is one file inside the bundle archive.
|
||||||
|
|||||||
@@ -27,7 +27,7 @@ func VerifyGzippedTar(bundle []byte, pub ed25519.PublicKey) (*VerifiedContents,
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
defer gr.Close()
|
defer func() { _ = gr.Close() }()
|
||||||
|
|
||||||
var manifestRaw []byte
|
var manifestRaw []byte
|
||||||
var sig []byte
|
var sig []byte
|
||||||
|
|||||||
@@ -6,9 +6,12 @@ import (
|
|||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io/fs"
|
"io/fs"
|
||||||
|
"os"
|
||||||
"path"
|
"path"
|
||||||
"sort"
|
"sort"
|
||||||
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
|
"time"
|
||||||
|
|
||||||
"evobgp/migrations"
|
"evobgp/migrations"
|
||||||
|
|
||||||
@@ -22,6 +25,17 @@ func OpenPostgresPool(ctx context.Context, dsn string) (*pgxpool.Pool, error) {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
if max := os.Getenv("EVOBGP_DB_MAX_CONNS"); max != "" {
|
||||||
|
if n, err := strconv.Atoi(strings.TrimSpace(max)); err == nil && n > 0 {
|
||||||
|
cfg.MaxConns = int32(n)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if min := os.Getenv("EVOBGP_DB_MIN_CONNS"); min != "" {
|
||||||
|
if n, err := strconv.Atoi(strings.TrimSpace(min)); err == nil && n >= 0 {
|
||||||
|
cfg.MinConns = int32(n)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
cfg.MaxConnLifetime = 30 * time.Minute
|
||||||
pool, err := pgxpool.NewWithConfig(ctx, cfg)
|
pool, err := pgxpool.NewWithConfig(ctx, cfg)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
|
|||||||
@@ -15,6 +15,11 @@ import (
|
|||||||
"github.com/jackc/pgx/v5/pgxpool"
|
"github.com/jackc/pgx/v5/pgxpool"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// NewCDNHTTPClient returns the shared HTTP client for CDN and preview fetches (PERF-02 / ERR-03).
|
||||||
|
func NewCDNHTTPClient() *http.Client {
|
||||||
|
return &http.Client{Timeout: 45 * time.Second}
|
||||||
|
}
|
||||||
|
|
||||||
// BootstrapWorkers opens the same store.Backend and jobs.Registry as New (without HTTP or bundle keys).
|
// BootstrapWorkers opens the same store.Backend and jobs.Registry as New (without HTTP or bundle keys).
|
||||||
// Used by standalone worker binaries (scheduler, ingest, …) that share PostgreSQL with the API.
|
// Used by standalone worker binaries (scheduler, ingest, …) that share PostgreSQL with the API.
|
||||||
func BootstrapWorkers(ctx context.Context, opts Options) (store.Backend, *jobs.Registry, *pgxpool.Pool, error) {
|
func BootstrapWorkers(ctx context.Context, opts Options) (store.Backend, *jobs.Registry, *pgxpool.Pool, error) {
|
||||||
@@ -44,10 +49,25 @@ func BootstrapWorkers(ctx context.Context, opts Options) (store.Backend, *jobs.R
|
|||||||
backend = mem
|
backend = mem
|
||||||
}
|
}
|
||||||
|
|
||||||
cdnHTTP := &http.Client{Timeout: 45 * time.Second}
|
cdnHTTP := NewCDNHTTPClient()
|
||||||
wk := &jobs.Worker{Store: backend, HTTPClient: cdnHTTP}
|
wk := &jobs.Worker{Store: backend, HTTPClient: cdnHTTP}
|
||||||
reg := jobs.NewRegistry(wk.Process)
|
reg := jobs.NewRegistry(wk.Process)
|
||||||
wk.Registry = reg
|
wk.Registry = reg
|
||||||
|
if pool != nil {
|
||||||
|
audit := repository.NewJobAuditWriter(pool)
|
||||||
|
reg.SetTerminalHook(func(j *jobs.Job) {
|
||||||
|
if j == nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
st := j.Snapshot()
|
||||||
|
status, _ := st["status"].(string)
|
||||||
|
var errMsg *string
|
||||||
|
if e, ok := st["error"].(string); ok && e != "" {
|
||||||
|
errMsg = &e
|
||||||
|
}
|
||||||
|
audit.MarkTerminal(context.Background(), j.TenantID, j.ID, status, errMsg, time.Now().UTC())
|
||||||
|
})
|
||||||
|
}
|
||||||
observability.RegisterStoreBackend(backend)
|
observability.RegisterStoreBackend(backend)
|
||||||
return backend, reg, pool, nil
|
return backend, reg, pool, nil
|
||||||
}
|
}
|
||||||
@@ -0,0 +1,38 @@
|
|||||||
|
package httpapi
|
||||||
|
|
||||||
|
import (
|
||||||
|
"net/http"
|
||||||
|
"strconv"
|
||||||
|
|
||||||
|
"evobgp/internal/store"
|
||||||
|
)
|
||||||
|
|
||||||
|
func parseListLimit(r *http.Request) int {
|
||||||
|
limit, _ := strconv.Atoi(r.URL.Query().Get("limit"))
|
||||||
|
if limit <= 0 {
|
||||||
|
return 50
|
||||||
|
}
|
||||||
|
if limit > 500 {
|
||||||
|
return 500
|
||||||
|
}
|
||||||
|
return limit
|
||||||
|
}
|
||||||
|
|
||||||
|
func strPtrOrNull(s string) any {
|
||||||
|
if s == "" {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
return s
|
||||||
|
}
|
||||||
|
|
||||||
|
// writePaginatedListJSON returns a cursor/limit page as OpenAPI list envelopes (items, next_cursor, has_more).
|
||||||
|
func writePaginatedListJSON[T any](w http.ResponseWriter, r *http.Request, all []T, toItem func(T) map[string]any) {
|
||||||
|
page, next, more := store.PaginateOffset(all, r.URL.Query().Get("cursor"), parseListLimit(r))
|
||||||
|
items := make([]map[string]any, 0, len(page))
|
||||||
|
for _, x := range page {
|
||||||
|
items = append(items, toItem(x))
|
||||||
|
}
|
||||||
|
writeJSON(w, http.StatusOK, map[string]any{
|
||||||
|
"items": items, "next_cursor": strPtrOrNull(next), "has_more": more,
|
||||||
|
})
|
||||||
|
}
|
||||||
@@ -2,16 +2,26 @@ package httpapi
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
|
"log"
|
||||||
"net/http"
|
"net/http"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
const (
|
||||||
|
internalErrorDetail = "an internal error occurred"
|
||||||
|
badGatewayDetail = "upstream request failed"
|
||||||
|
notFoundDetail = "resource not found"
|
||||||
|
invalidInputDetail = "invalid request data"
|
||||||
|
cdnExtractDetail = "could not extract prefixes from source"
|
||||||
|
csvInvalidRowDetail = "invalid row in csv file"
|
||||||
|
)
|
||||||
|
|
||||||
// Problem is RFC 9457 application/problem+json.
|
// Problem is RFC 9457 application/problem+json.
|
||||||
type Problem struct {
|
type Problem struct {
|
||||||
Type string `json:"type,omitempty"`
|
Type string `json:"type,omitempty"`
|
||||||
Title string `json:"title"`
|
Title string `json:"title"`
|
||||||
Status int `json:"status"`
|
Status int `json:"status"`
|
||||||
Detail string `json:"detail,omitempty"`
|
Detail string `json:"detail,omitempty"`
|
||||||
Instance string `json:"instance,omitempty"`
|
Instance string `json:"instance,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func writeProblem(w http.ResponseWriter, status int, title, detail string) {
|
func writeProblem(w http.ResponseWriter, status int, title, detail string) {
|
||||||
@@ -34,3 +44,19 @@ func writeJSON(w http.ResponseWriter, status int, v any) {
|
|||||||
func writeNoContent(w http.ResponseWriter) {
|
func writeNoContent(w http.ResponseWriter) {
|
||||||
w.WriteHeader(http.StatusNoContent)
|
w.WriteHeader(http.StatusNoContent)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// writeInternalError logs err server-side and returns a generic 500 problem (ERR-01).
|
||||||
|
func writeInternalError(w http.ResponseWriter, operation string, err error) {
|
||||||
|
if err != nil {
|
||||||
|
log.Printf("httpapi: %s: %v", operation, err)
|
||||||
|
}
|
||||||
|
writeProblem(w, http.StatusInternalServerError, "Internal Error", internalErrorDetail)
|
||||||
|
}
|
||||||
|
|
||||||
|
// writeBadGateway logs err server-side and returns a generic 502 problem (ERR-01).
|
||||||
|
func writeBadGateway(w http.ResponseWriter, operation string, err error) {
|
||||||
|
if err != nil {
|
||||||
|
log.Printf("httpapi: %s: %v", operation, err)
|
||||||
|
}
|
||||||
|
writeProblem(w, http.StatusBadGateway, "Bad Gateway", badGatewayDetail)
|
||||||
|
}
|
||||||
+131
-335
@@ -19,7 +19,9 @@ import (
|
|||||||
"evobgp/internal/jobs"
|
"evobgp/internal/jobs"
|
||||||
"evobgp/internal/observability"
|
"evobgp/internal/observability"
|
||||||
"evobgp/internal/pipeline"
|
"evobgp/internal/pipeline"
|
||||||
|
"evobgp/internal/reports"
|
||||||
"evobgp/internal/store"
|
"evobgp/internal/store"
|
||||||
|
"evobgp/internal/version"
|
||||||
)
|
)
|
||||||
|
|
||||||
// Handler returns the root HTTP handler (system routes public; rest under /v1/ authenticated).
|
// Handler returns the root HTTP handler (system routes public; rest under /v1/ authenticated).
|
||||||
@@ -29,6 +31,7 @@ func (s *Server) Handler() http.Handler {
|
|||||||
wrappedV1 := http.StripPrefix("/v1", v1)
|
wrappedV1 := http.StripPrefix("/v1", v1)
|
||||||
|
|
||||||
s.mux.Handle("GET /metrics", observability.MetricsHandler())
|
s.mux.Handle("GET /metrics", observability.MetricsHandler())
|
||||||
|
s.mux.HandleFunc("GET /version", s.handleVersion)
|
||||||
s.mux.HandleFunc("GET /v1/health", s.handleHealth)
|
s.mux.HandleFunc("GET /v1/health", s.handleHealth)
|
||||||
s.mux.HandleFunc("GET /v1/ready", s.handleReady)
|
s.mux.HandleFunc("GET /v1/ready", s.handleReady)
|
||||||
s.mux.HandleFunc("GET /v1/version", s.handleVersion)
|
s.mux.HandleFunc("GET /v1/version", s.handleVersion)
|
||||||
@@ -66,6 +69,7 @@ func (s *Server) registerV1(m *http.ServeMux) {
|
|||||||
m.HandleFunc("GET /bird/status", s.handleBirdStatus)
|
m.HandleFunc("GET /bird/status", s.handleBirdStatus)
|
||||||
m.HandleFunc("GET /jobs", s.handleListJobs)
|
m.HandleFunc("GET /jobs", s.handleListJobs)
|
||||||
m.HandleFunc("GET /jobs/{job_id}", s.handleGetJob)
|
m.HandleFunc("GET /jobs/{job_id}", s.handleGetJob)
|
||||||
|
m.HandleFunc("GET /jobs/{job_id}/report", s.handleGetJobReport)
|
||||||
m.HandleFunc("POST /jobs/{job_id}/cancel", s.handleCancelJob)
|
m.HandleFunc("POST /jobs/{job_id}/cancel", s.handleCancelJob)
|
||||||
m.HandleFunc("GET /speakers/{speaker_id}/revisions/latest", s.handleNodeLatestRevision)
|
m.HandleFunc("GET /speakers/{speaker_id}/revisions/latest", s.handleNodeLatestRevision)
|
||||||
m.HandleFunc("GET /speakers/{speaker_id}/bundle/{revision_id}", s.handleNodeBundle)
|
m.HandleFunc("GET /speakers/{speaker_id}/bundle/{revision_id}", s.handleNodeBundle)
|
||||||
@@ -81,12 +85,15 @@ func (s *Server) handleReady(w http.ResponseWriter, r *http.Request) {
|
|||||||
checks := map[string]string{"store": "ok", "jobs": "memory"}
|
checks := map[string]string{"store": "ok", "jobs": "memory"}
|
||||||
ctx, cancel := context.WithTimeout(r.Context(), 2*time.Second)
|
ctx, cancel := context.WithTimeout(r.Context(), 2*time.Second)
|
||||||
defer cancel()
|
defer cancel()
|
||||||
if s.pgPool != nil {
|
if err := s.store.Ping(ctx); err != nil {
|
||||||
if err := s.pgPool.Ping(ctx); err != nil {
|
checks["store"] = "unavailable"
|
||||||
checks["postgres"] = err.Error()
|
if s.pgPool != nil {
|
||||||
writeJSON(w, http.StatusServiceUnavailable, map[string]any{"status": "not_ready", "checks": checks})
|
checks["postgres"] = "unavailable"
|
||||||
return
|
|
||||||
}
|
}
|
||||||
|
writeJSON(w, http.StatusServiceUnavailable, map[string]any{"status": "not_ready", "checks": checks})
|
||||||
|
return
|
||||||
|
}
|
||||||
|
if s.pgPool != nil {
|
||||||
checks["postgres"] = "ok"
|
checks["postgres"] = "ok"
|
||||||
} else {
|
} else {
|
||||||
checks["store_backend"] = "memory"
|
checks["store_backend"] = "memory"
|
||||||
@@ -95,11 +102,16 @@ func (s *Server) handleReady(w http.ResponseWriter, r *http.Request) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (s *Server) handleVersion(w http.ResponseWriter, r *http.Request) {
|
func (s *Server) handleVersion(w http.ResponseWriter, r *http.Request) {
|
||||||
sha := strings.TrimSpace(os.Getenv("EVOBGP_GIT_SHA"))
|
ver, sha, buildTime := version.Info()
|
||||||
if sha == "" {
|
resp := map[string]string{
|
||||||
sha = "unknown"
|
"version": ver,
|
||||||
|
"api_version": ver,
|
||||||
|
"git_sha": sha,
|
||||||
}
|
}
|
||||||
writeJSON(w, http.StatusOK, map[string]string{"api_version": "0.1.0", "git_sha": sha})
|
if buildTime != "" {
|
||||||
|
resp["build_time"] = buildTime
|
||||||
|
}
|
||||||
|
writeJSON(w, http.StatusOK, resp)
|
||||||
}
|
}
|
||||||
|
|
||||||
func moduleJSON(mod *store.Module) map[string]any {
|
func moduleJSON(mod *store.Module) map[string]any {
|
||||||
@@ -189,19 +201,39 @@ func (s *Server) handleListModules(w http.ResponseWriter, r *http.Request) {
|
|||||||
enabledFilter = &v
|
enabledFilter = &v
|
||||||
}
|
}
|
||||||
|
|
||||||
mods := s.store.ListModules(a.TenantID)
|
filtered := make([]*store.Module, 0)
|
||||||
items := make([]map[string]any, 0, len(mods))
|
limit := parseListLimit(r)
|
||||||
for _, mod := range mods {
|
cursor := r.URL.Query().Get("cursor")
|
||||||
|
if typeFilter == "" && enabledFilter == nil {
|
||||||
|
page, next, more := s.store.ListModulesPage(a.TenantID, cursor, limit)
|
||||||
|
for _, mod := range page {
|
||||||
|
filtered = append(filtered, mod)
|
||||||
|
}
|
||||||
|
items := make([]map[string]any, 0, len(filtered))
|
||||||
|
for _, mod := range filtered {
|
||||||
|
items = append(items, moduleJSON(mod))
|
||||||
|
}
|
||||||
|
writeJSON(w, http.StatusOK, map[string]any{
|
||||||
|
"items": items, "next_cursor": strPtrOrNull(next), "has_more": more,
|
||||||
|
})
|
||||||
|
return
|
||||||
|
}
|
||||||
|
for _, mod := range s.store.ListModules(a.TenantID) {
|
||||||
if typeFilter != "" && mod.Type != typeFilter {
|
if typeFilter != "" && mod.Type != typeFilter {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
if enabledFilter != nil && mod.Enabled != *enabledFilter {
|
if enabledFilter != nil && mod.Enabled != *enabledFilter {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
filtered = append(filtered, mod)
|
||||||
|
}
|
||||||
|
page, next, more := store.PaginateOffset(filtered, r.URL.Query().Get("cursor"), parseListLimit(r))
|
||||||
|
items := make([]map[string]any, 0, len(page))
|
||||||
|
for _, mod := range page {
|
||||||
items = append(items, moduleJSON(mod))
|
items = append(items, moduleJSON(mod))
|
||||||
}
|
}
|
||||||
writeJSON(w, http.StatusOK, map[string]any{
|
writeJSON(w, http.StatusOK, map[string]any{
|
||||||
"items": items, "next_cursor": nil, "has_more": false,
|
"items": items, "next_cursor": strPtrOrNull(next), "has_more": more,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -214,91 +246,17 @@ func (s *Server) handleRouterListsCatalog(w http.ResponseWriter, r *http.Request
|
|||||||
if !s.requireAtLeast(w, a, "viewer") {
|
if !s.requireAtLeast(w, a, "viewer") {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
cat, err := reports.BuildRouterListsCatalog(s.store, a.TenantID)
|
||||||
mods := s.store.ListModules(a.TenantID)
|
|
||||||
moduleItems := make([]map[string]any, 0, len(mods))
|
|
||||||
domains := make([]map[string]any, 0)
|
|
||||||
asns := make([]map[string]any, 0)
|
|
||||||
ipRanges := make([]map[string]any, 0)
|
|
||||||
|
|
||||||
for _, mod := range mods {
|
|
||||||
switch mod.Type {
|
|
||||||
case "DOMAINS", "AS_PREFIXES", "IP_RANGES":
|
|
||||||
moduleItems = append(moduleItems, moduleJSON(mod))
|
|
||||||
default:
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
|
|
||||||
switch mod.Type {
|
|
||||||
case "DOMAINS":
|
|
||||||
list, err := s.store.ListDomainEntries(a.TenantID, mod.ID)
|
|
||||||
if err != nil {
|
|
||||||
writeStoreErr(w, err)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
for _, x := range list {
|
|
||||||
domains = append(domains, map[string]any{
|
|
||||||
"module_id": mod.ID,
|
|
||||||
"entry": domainEntryJSON(x),
|
|
||||||
})
|
|
||||||
}
|
|
||||||
case "AS_PREFIXES":
|
|
||||||
list, err := s.store.ListASEntries(a.TenantID, mod.ID)
|
|
||||||
if err != nil {
|
|
||||||
writeStoreErr(w, err)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
for _, x := range list {
|
|
||||||
asns = append(asns, map[string]any{
|
|
||||||
"module_id": mod.ID,
|
|
||||||
"entry": asEntryJSON(x),
|
|
||||||
})
|
|
||||||
}
|
|
||||||
case "IP_RANGES":
|
|
||||||
list, err := s.store.ListIPRangeEntries(a.TenantID, mod.ID)
|
|
||||||
if err != nil {
|
|
||||||
writeStoreErr(w, err)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
for _, x := range list {
|
|
||||||
ipRanges = append(ipRanges, map[string]any{
|
|
||||||
"module_id": mod.ID,
|
|
||||||
"entry": ipRangeJSON(x),
|
|
||||||
})
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
comms, err := s.store.ListCommunities(a.TenantID)
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
writeStoreErr(w, err)
|
writeStoreErr(w, err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
communityItems := make([]map[string]any, 0, len(comms))
|
|
||||||
for _, c := range comms {
|
|
||||||
communityItems = append(communityItems, map[string]any{
|
|
||||||
"id": c.ID,
|
|
||||||
"community": c.Community,
|
|
||||||
"title": c.Title,
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
writeJSON(w, http.StatusOK, map[string]any{
|
writeJSON(w, http.StatusOK, map[string]any{
|
||||||
"modules": map[string]any{
|
"modules": map[string]any{"items": cat.Modules},
|
||||||
"items": moduleItems,
|
"domains": map[string]any{"items": cat.Domains},
|
||||||
},
|
"asns": map[string]any{"items": cat.ASNs},
|
||||||
"domains": map[string]any{
|
"ip_ranges": map[string]any{"items": cat.IPRanges},
|
||||||
"items": domains,
|
"communities": map[string]any{"items": cat.Communities},
|
||||||
},
|
|
||||||
"asns": map[string]any{
|
|
||||||
"items": asns,
|
|
||||||
},
|
|
||||||
"ip_ranges": map[string]any{
|
|
||||||
"items": ipRanges,
|
|
||||||
},
|
|
||||||
"communities": map[string]any{
|
|
||||||
"items": communityItems,
|
|
||||||
},
|
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -317,7 +275,7 @@ func (s *Server) handleGetModule(w http.ResponseWriter, r *http.Request) {
|
|||||||
writeProblem(w, http.StatusNotFound, "Not Found", "module not found")
|
writeProblem(w, http.StatusNotFound, "Not Found", "module not found")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
writeProblem(w, http.StatusInternalServerError, "Internal Error", err.Error())
|
writeInternalError(w, "internal", err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
writeJSON(w, http.StatusOK, moduleJSON(mod))
|
writeJSON(w, http.StatusOK, moduleJSON(mod))
|
||||||
@@ -332,10 +290,11 @@ func (s *Server) handleListPeers(w http.ResponseWriter, r *http.Request) {
|
|||||||
if !s.requireAtLeast(w, a, "viewer") {
|
if !s.requireAtLeast(w, a, "viewer") {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
peers := s.store.ListPeers(a.TenantID)
|
allPeers := s.store.ListPeers(a.TenantID)
|
||||||
liveStates := s.liveBGPProtocolStates(r.Context())
|
page, next, more := store.PaginateOffset(allPeers, r.URL.Query().Get("cursor"), parseListLimit(r))
|
||||||
items := make([]map[string]any, 0, len(peers))
|
liveStates := s.liveBGPProtocolStates(r)
|
||||||
for _, p := range peers {
|
items := make([]map[string]any, 0, len(page))
|
||||||
|
for _, p := range page {
|
||||||
row := peerJSON(p)
|
row := peerJSON(p)
|
||||||
if st, ok := liveStates[peerProtocolNameForID(p.ID)]; ok && strings.TrimSpace(st) != "" {
|
if st, ok := liveStates[peerProtocolNameForID(p.ID)]; ok && strings.TrimSpace(st) != "" {
|
||||||
row["session_state"] = strings.TrimSpace(st)
|
row["session_state"] = strings.TrimSpace(st)
|
||||||
@@ -343,11 +302,21 @@ func (s *Server) handleListPeers(w http.ResponseWriter, r *http.Request) {
|
|||||||
items = append(items, row)
|
items = append(items, row)
|
||||||
}
|
}
|
||||||
writeJSON(w, http.StatusOK, map[string]any{
|
writeJSON(w, http.StatusOK, map[string]any{
|
||||||
"items": items, "next_cursor": nil, "has_more": false,
|
"items": items, "next_cursor": strPtrOrNull(next), "has_more": more,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *Server) liveBGPProtocolStates(ctx context.Context) map[string]string {
|
func (s *Server) liveBGPProtocolStates(r *http.Request) map[string]string {
|
||||||
|
if r != nil && strings.EqualFold(strings.TrimSpace(r.URL.Query().Get("live")), "1") {
|
||||||
|
return s.liveBGPProtocolStatesFresh(r.Context())
|
||||||
|
}
|
||||||
|
if cached, ok := observability.CachedBirdProtocolStates(90 * time.Second); ok {
|
||||||
|
return cached
|
||||||
|
}
|
||||||
|
return s.liveBGPProtocolStatesFresh(r.Context())
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *Server) liveBGPProtocolStatesFresh(ctx context.Context) map[string]string {
|
||||||
sock := strings.TrimSpace(os.Getenv("EVOBGP_BIRDC_SOCKET"))
|
sock := strings.TrimSpace(os.Getenv("EVOBGP_BIRDC_SOCKET"))
|
||||||
if sock == "" {
|
if sock == "" {
|
||||||
return map[string]string{}
|
return map[string]string{}
|
||||||
@@ -356,7 +325,9 @@ func (s *Server) liveBGPProtocolStates(ctx context.Context) map[string]string {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return map[string]string{}
|
return map[string]string{}
|
||||||
}
|
}
|
||||||
return parseBGPProtocolStates(out)
|
states := birdfmt.ParseBGPProtocolStates(out)
|
||||||
|
observability.SetBirdProtocolStates(states)
|
||||||
|
return states
|
||||||
}
|
}
|
||||||
|
|
||||||
// parseBGPProtocolStates parses `birdc show protocols all` summary rows into protocol_name -> state.
|
// parseBGPProtocolStates parses `birdc show protocols all` summary rows into protocol_name -> state.
|
||||||
@@ -451,7 +422,7 @@ func (s *Server) handleModuleRefresh(w http.ResponseWriter, r *http.Request) {
|
|||||||
writeProblem(w, http.StatusNotFound, "Not Found", "module not found")
|
writeProblem(w, http.StatusNotFound, "Not Found", "module not found")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
writeProblem(w, http.StatusInternalServerError, "Internal Error", err.Error())
|
writeInternalError(w, "internal", err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
idem := r.Header.Get("Idempotency-Key")
|
idem := r.Header.Get("Idempotency-Key")
|
||||||
@@ -463,7 +434,7 @@ func (s *Server) handleModuleRefresh(w http.ResponseWriter, r *http.Request) {
|
|||||||
mid := mod.ID
|
mid := mod.ID
|
||||||
j, _, err := s.jobs.Enqueue(a.TenantID, jobs.KindModuleRefresh, idemPtr, &mid, map[string]any{"module_id": moduleID})
|
j, _, err := s.jobs.Enqueue(a.TenantID, jobs.KindModuleRefresh, idemPtr, &mid, map[string]any{"module_id": moduleID})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
writeProblem(w, http.StatusInternalServerError, "Internal Error", err.Error())
|
writeInternalError(w, "internal", err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
w.Header().Set("Location", "/v1/jobs/"+j.ID)
|
w.Header().Set("Location", "/v1/jobs/"+j.ID)
|
||||||
@@ -512,7 +483,7 @@ func (s *Server) handleTenantRefresh(w http.ResponseWriter, r *http.Request) {
|
|||||||
"trigger": "api",
|
"trigger": "api",
|
||||||
})
|
})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
writeProblem(w, http.StatusInternalServerError, "Internal Error", err.Error())
|
writeInternalError(w, "internal", err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
w.Header().Set("Location", "/v1/jobs/"+j.ID)
|
w.Header().Set("Location", "/v1/jobs/"+j.ID)
|
||||||
@@ -570,13 +541,6 @@ func revisionJSON(rev *store.Revision) map[string]any {
|
|||||||
return m
|
return m
|
||||||
}
|
}
|
||||||
|
|
||||||
func strPtrOrNull(s string) any {
|
|
||||||
if s == "" {
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
return s
|
|
||||||
}
|
|
||||||
|
|
||||||
// enqueueModuleRefreshIfEnabled queues module_refresh when the module exists and is enabled (best-effort, no HTTP error).
|
// enqueueModuleRefreshIfEnabled queues module_refresh when the module exists and is enabled (best-effort, no HTTP error).
|
||||||
func (s *Server) enqueueModuleRefreshIfEnabled(tenantID, moduleID, trigger string) {
|
func (s *Server) enqueueModuleRefreshIfEnabled(tenantID, moduleID, trigger string) {
|
||||||
if s.jobs == nil {
|
if s.jobs == nil {
|
||||||
@@ -587,7 +551,8 @@ func (s *Server) enqueueModuleRefreshIfEnabled(tenantID, moduleID, trigger strin
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
mid := moduleID
|
mid := moduleID
|
||||||
_, _, _ = s.jobs.Enqueue(tenantID, jobs.KindModuleRefresh, nil, &mid, map[string]any{
|
key := "module_refresh:" + moduleID
|
||||||
|
_, _, _ = s.jobs.Enqueue(tenantID, jobs.KindModuleRefresh, &key, &mid, map[string]any{
|
||||||
"module_id": moduleID,
|
"module_id": moduleID,
|
||||||
"trigger": trigger,
|
"trigger": trigger,
|
||||||
})
|
})
|
||||||
@@ -654,6 +619,9 @@ func (s *Server) handleRevisionPreview(w http.ResponseWriter, r *http.Request) {
|
|||||||
for k, v := range rev.PreviewFragments {
|
for k, v := range rev.PreviewFragments {
|
||||||
obj[k] = v
|
obj[k] = v
|
||||||
}
|
}
|
||||||
|
if expanded := pipeline.BuildExpandedBirdPreview(rev.PreviewFragments); expanded != "" {
|
||||||
|
obj[pipeline.AuxBirdFullExpandedKey()] = expanded
|
||||||
|
}
|
||||||
writeJSON(w, http.StatusOK, obj)
|
writeJSON(w, http.StatusOK, obj)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -672,225 +640,15 @@ func (s *Server) handleRevisionDiagnosticLog(w http.ResponseWriter, r *http.Requ
|
|||||||
writeProblem(w, http.StatusNotFound, "Not Found", "revision not found")
|
writeProblem(w, http.StatusNotFound, "Not Found", "revision not found")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
logOut, err := reports.BuildRevisionDiagnosticLog(s.store, a.TenantID, rev)
|
||||||
moduleType := ""
|
if err != nil {
|
||||||
moduleName := ""
|
writeInternalError(w, "revision diagnostic log", err)
|
||||||
if strings.TrimSpace(rev.ModuleID) != "" {
|
return
|
||||||
if mod, modErr := s.store.GetModule(a.TenantID, rev.ModuleID); modErr == nil && mod != nil {
|
|
||||||
moduleType = strings.TrimSpace(mod.Type)
|
|
||||||
moduleName = strings.TrimSpace(mod.Name)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
communityLabels := map[string]string{}
|
|
||||||
if communities, listErr := s.store.ListCommunities(a.TenantID); listErr == nil {
|
|
||||||
for _, c := range communities {
|
|
||||||
if c == nil {
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
label := strings.TrimSpace(c.Title)
|
|
||||||
if label == "" {
|
|
||||||
label = strings.TrimSpace(c.Community)
|
|
||||||
}
|
|
||||||
if label == "" {
|
|
||||||
label = c.ID
|
|
||||||
}
|
|
||||||
communityLabels[c.ID] = label
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
type rawRow struct {
|
|
||||||
Prefix string
|
|
||||||
Source string
|
|
||||||
Kind string
|
|
||||||
SourceName string
|
|
||||||
SourceDetail string
|
|
||||||
CommunityID string
|
|
||||||
CommunityLabel string
|
|
||||||
}
|
|
||||||
type summary struct {
|
|
||||||
Kind string
|
|
||||||
Source string
|
|
||||||
SourceDetail string
|
|
||||||
CommunityID string
|
|
||||||
CommunityLabel string
|
|
||||||
Count int
|
|
||||||
Sample []string
|
|
||||||
}
|
|
||||||
|
|
||||||
cdnSourceURLByID := map[string]string{}
|
|
||||||
if moduleType == "CDN_CIDRS" && strings.TrimSpace(rev.ModuleID) != "" {
|
|
||||||
if sources, srcErr := s.store.ListCDNSources(a.TenantID, rev.ModuleID); srcErr == nil {
|
|
||||||
for _, src := range sources {
|
|
||||||
if src == nil {
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
id := strings.TrimSpace(src.ID)
|
|
||||||
url := strings.TrimSpace(src.URL)
|
|
||||||
if id != "" && url != "" {
|
|
||||||
cdnSourceURLByID[id] = url
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
rows := make([]rawRow, 0, rev.MaterializedPrefixCount)
|
|
||||||
byGroup := map[string]*summary{}
|
|
||||||
cursor := ""
|
|
||||||
for {
|
|
||||||
page, next, more := s.store.ListRevisionPrefixes(a.TenantID, revID, cursor, 2000)
|
|
||||||
for _, p := range page {
|
|
||||||
kind, sourceName := classifyRevisionSource(p.Source)
|
|
||||||
sourceDetail := sourceName
|
|
||||||
if kind == "cdn" {
|
|
||||||
if url, ok := cdnSourceURLByID[sourceName]; ok && strings.TrimSpace(url) != "" {
|
|
||||||
sourceDetail = url
|
|
||||||
}
|
|
||||||
}
|
|
||||||
communityID := "none"
|
|
||||||
if p.CommunityID != nil && strings.TrimSpace(*p.CommunityID) != "" {
|
|
||||||
communityID = strings.TrimSpace(*p.CommunityID)
|
|
||||||
}
|
|
||||||
communityLabel := "без community"
|
|
||||||
if communityID != "none" {
|
|
||||||
if lbl, ok := communityLabels[communityID]; ok && strings.TrimSpace(lbl) != "" {
|
|
||||||
communityLabel = lbl
|
|
||||||
} else {
|
|
||||||
communityLabel = communityID
|
|
||||||
}
|
|
||||||
}
|
|
||||||
rows = append(rows, rawRow{
|
|
||||||
Prefix: p.Prefix,
|
|
||||||
Source: p.Source,
|
|
||||||
Kind: kind,
|
|
||||||
SourceName: sourceName,
|
|
||||||
SourceDetail: sourceDetail,
|
|
||||||
CommunityID: communityID,
|
|
||||||
CommunityLabel: communityLabel,
|
|
||||||
})
|
|
||||||
groupKey := kind + "|" + sourceName + "|" + communityID
|
|
||||||
g, ok := byGroup[groupKey]
|
|
||||||
if !ok {
|
|
||||||
g = &summary{
|
|
||||||
Kind: kind,
|
|
||||||
Source: sourceName,
|
|
||||||
SourceDetail: sourceDetail,
|
|
||||||
CommunityID: communityID,
|
|
||||||
CommunityLabel: communityLabel,
|
|
||||||
Sample: make([]string, 0, 5),
|
|
||||||
}
|
|
||||||
byGroup[groupKey] = g
|
|
||||||
}
|
|
||||||
g.Count++
|
|
||||||
if len(g.Sample) < 5 {
|
|
||||||
g.Sample = append(g.Sample, p.Prefix)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if !more || strings.TrimSpace(next) == "" {
|
|
||||||
break
|
|
||||||
}
|
|
||||||
cursor = next
|
|
||||||
}
|
|
||||||
|
|
||||||
summaryKeys := make([]string, 0, len(byGroup))
|
|
||||||
for k := range byGroup {
|
|
||||||
summaryKeys = append(summaryKeys, k)
|
|
||||||
}
|
|
||||||
sort.Strings(summaryKeys)
|
|
||||||
|
|
||||||
sort.Slice(rows, func(i, j int) bool {
|
|
||||||
if rows[i].Kind != rows[j].Kind {
|
|
||||||
return rows[i].Kind < rows[j].Kind
|
|
||||||
}
|
|
||||||
if rows[i].SourceName != rows[j].SourceName {
|
|
||||||
return rows[i].SourceName < rows[j].SourceName
|
|
||||||
}
|
|
||||||
if rows[i].CommunityID != rows[j].CommunityID {
|
|
||||||
return rows[i].CommunityID < rows[j].CommunityID
|
|
||||||
}
|
|
||||||
return rows[i].Prefix < rows[j].Prefix
|
|
||||||
})
|
|
||||||
|
|
||||||
var b strings.Builder
|
|
||||||
b.WriteString("EvoBGP revision diagnostic log\n")
|
|
||||||
b.WriteString("generated_at=" + time.Now().UTC().Format(time.RFC3339Nano) + "\n")
|
|
||||||
b.WriteString("tenant_id=" + a.TenantID + "\n")
|
|
||||||
b.WriteString("revision_id=" + rev.ID + "\n")
|
|
||||||
b.WriteString("revision_created_at=" + rev.CreatedAt.UTC().Format(time.RFC3339Nano) + "\n")
|
|
||||||
b.WriteString("content_hash=" + rev.ContentHash + "\n")
|
|
||||||
b.WriteString("materialized_prefix_count=" + strconv.Itoa(rev.MaterializedPrefixCount) + "\n")
|
|
||||||
if rev.ModuleID != "" {
|
|
||||||
b.WriteString("module_id=" + rev.ModuleID + "\n")
|
|
||||||
} else {
|
|
||||||
b.WriteString("module_id=\n")
|
|
||||||
}
|
|
||||||
b.WriteString("module_type=" + moduleType + "\n")
|
|
||||||
b.WriteString("module_name=" + moduleName + "\n")
|
|
||||||
b.WriteString("fetched_rows=" + strconv.Itoa(len(rows)) + "\n\n")
|
|
||||||
|
|
||||||
b.WriteString("## Aggregation by source and community\n")
|
|
||||||
for _, k := range summaryKeys {
|
|
||||||
g := byGroup[k]
|
|
||||||
b.WriteString("- kind=" + g.Kind +
|
|
||||||
" source=" + g.Source +
|
|
||||||
" source_detail=" + g.SourceDetail +
|
|
||||||
" community_id=" + g.CommunityID +
|
|
||||||
" community_label=" + g.CommunityLabel +
|
|
||||||
" count=" + strconv.Itoa(g.Count))
|
|
||||||
if len(g.Sample) > 0 {
|
|
||||||
b.WriteString(" sample=" + strings.Join(g.Sample, ","))
|
|
||||||
}
|
|
||||||
b.WriteByte('\n')
|
|
||||||
}
|
|
||||||
|
|
||||||
b.WriteString("\n## Raw rows\n")
|
|
||||||
b.WriteString("prefix\tkind\tsource\tsource_detail\tcommunity_id\tcommunity_label\n")
|
|
||||||
for _, row := range rows {
|
|
||||||
b.WriteString(row.Prefix)
|
|
||||||
b.WriteByte('\t')
|
|
||||||
b.WriteString(row.Kind)
|
|
||||||
b.WriteByte('\t')
|
|
||||||
b.WriteString(row.Source)
|
|
||||||
b.WriteByte('\t')
|
|
||||||
b.WriteString(strings.ReplaceAll(row.SourceDetail, "\t", " "))
|
|
||||||
b.WriteByte('\t')
|
|
||||||
b.WriteString(row.CommunityID)
|
|
||||||
b.WriteByte('\t')
|
|
||||||
b.WriteString(strings.ReplaceAll(row.CommunityLabel, "\t", " "))
|
|
||||||
b.WriteByte('\n')
|
|
||||||
}
|
|
||||||
|
|
||||||
filename := "revision-" + shortRevisionID(rev.ID) + "-diagnostic.log"
|
|
||||||
w.Header().Set("Content-Type", "text/plain; charset=utf-8")
|
w.Header().Set("Content-Type", "text/plain; charset=utf-8")
|
||||||
w.Header().Set("Content-Disposition", `attachment; filename="`+filename+`"`)
|
w.Header().Set("Content-Disposition", `attachment; filename="`+logOut.Filename+`"`)
|
||||||
w.WriteHeader(http.StatusOK)
|
w.WriteHeader(http.StatusOK)
|
||||||
_, _ = w.Write([]byte(b.String()))
|
_, _ = w.Write(logOut.Body)
|
||||||
}
|
|
||||||
|
|
||||||
func classifyRevisionSource(src string) (kind, sourceName string) {
|
|
||||||
switch {
|
|
||||||
case strings.HasPrefix(src, "as:"):
|
|
||||||
return "asn", strings.TrimPrefix(src, "as:")
|
|
||||||
case strings.HasPrefix(src, "domain:"):
|
|
||||||
return "domain", strings.TrimPrefix(src, "domain:")
|
|
||||||
case strings.HasPrefix(src, "cdn:"):
|
|
||||||
return "cdn", strings.TrimPrefix(src, "cdn:")
|
|
||||||
case src == "ip_range":
|
|
||||||
return "ip_range", "manual_ranges"
|
|
||||||
default:
|
|
||||||
if strings.TrimSpace(src) == "" {
|
|
||||||
return "unknown", "unknown"
|
|
||||||
}
|
|
||||||
return "source", strings.TrimSpace(src)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func shortRevisionID(id string) string {
|
|
||||||
s := strings.TrimSpace(id)
|
|
||||||
if len(s) <= 8 {
|
|
||||||
return s
|
|
||||||
}
|
|
||||||
return s[:8]
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *Server) handleRevisionDiff(w http.ResponseWriter, r *http.Request) {
|
func (s *Server) handleRevisionDiff(w http.ResponseWriter, r *http.Request) {
|
||||||
@@ -916,7 +674,7 @@ func (s *Server) handleRevisionRollback(w http.ResponseWriter, r *http.Request)
|
|||||||
writeProblem(w, http.StatusUnauthorized, "Unauthorized", "missing auth")
|
writeProblem(w, http.StatusUnauthorized, "Unauthorized", "missing auth")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
if !s.requireAtLeast(w, a, "editor") {
|
if !s.requireAtLeast(w, a, "operator") {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
revID := r.PathValue("revision_id")
|
revID := r.PathValue("revision_id")
|
||||||
@@ -933,7 +691,7 @@ func (s *Server) handleRevisionRollback(w http.ResponseWriter, r *http.Request)
|
|||||||
"source_revision_id": revID,
|
"source_revision_id": revID,
|
||||||
})
|
})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
writeProblem(w, http.StatusInternalServerError, "Internal Error", err.Error())
|
writeInternalError(w, "internal", err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
w.Header().Set("Location", "/v1/jobs/"+j.ID)
|
w.Header().Set("Location", "/v1/jobs/"+j.ID)
|
||||||
@@ -980,7 +738,7 @@ func (s *Server) handleApply(w http.ResponseWriter, r *http.Request) {
|
|||||||
"strategy": body.Strategy,
|
"strategy": body.Strategy,
|
||||||
})
|
})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
writeProblem(w, http.StatusInternalServerError, "Internal Error", err.Error())
|
writeInternalError(w, "internal", err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
w.Header().Set("Location", "/v1/jobs/"+j.ID)
|
w.Header().Set("Location", "/v1/jobs/"+j.ID)
|
||||||
@@ -1031,7 +789,7 @@ func (s *Server) handleSpeakerApply(w http.ResponseWriter, r *http.Request) {
|
|||||||
"speaker_id": spkID,
|
"speaker_id": spkID,
|
||||||
})
|
})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
writeProblem(w, http.StatusInternalServerError, "Internal Error", err.Error())
|
writeInternalError(w, "internal", err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
w.Header().Set("Location", "/v1/jobs/"+j.ID)
|
w.Header().Set("Location", "/v1/jobs/"+j.ID)
|
||||||
@@ -1056,7 +814,7 @@ func (s *Server) handleBirdReload(w http.ResponseWriter, r *http.Request) {
|
|||||||
}
|
}
|
||||||
j, _, err := s.jobs.Enqueue(a.TenantID, jobs.KindBirdReload, idemPtr, nil, nil)
|
j, _, err := s.jobs.Enqueue(a.TenantID, jobs.KindBirdReload, idemPtr, nil, nil)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
writeProblem(w, http.StatusInternalServerError, "Internal Error", err.Error())
|
writeInternalError(w, "internal", err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
w.Header().Set("Location", "/v1/jobs/"+j.ID)
|
w.Header().Set("Location", "/v1/jobs/"+j.ID)
|
||||||
@@ -1118,6 +876,44 @@ func (s *Server) handleGetJob(w http.ResponseWriter, r *http.Request) {
|
|||||||
writeJSON(w, http.StatusOK, j.Snapshot())
|
writeJSON(w, http.StatusOK, j.Snapshot())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (s *Server) handleGetJobReport(w http.ResponseWriter, r *http.Request) {
|
||||||
|
a, ok := authFromContext(r.Context())
|
||||||
|
if !ok {
|
||||||
|
writeProblem(w, http.StatusUnauthorized, "Unauthorized", "missing auth")
|
||||||
|
return
|
||||||
|
}
|
||||||
|
if !s.requireAtLeast(w, a, "viewer") {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
j, err := s.jobs.Get(a.TenantID, r.PathValue("job_id"))
|
||||||
|
if err != nil {
|
||||||
|
writeProblem(w, http.StatusNotFound, "Not Found", "job not found")
|
||||||
|
return
|
||||||
|
}
|
||||||
|
snap := j.Snapshot()
|
||||||
|
meta, _ := snap["meta"].(map[string]any)
|
||||||
|
out := map[string]any{
|
||||||
|
"job_id": snap["job_id"],
|
||||||
|
"kind": snap["kind"],
|
||||||
|
"status": snap["status"],
|
||||||
|
"meta": meta,
|
||||||
|
"error": snap["error"],
|
||||||
|
"created_at": snap["created_at"],
|
||||||
|
}
|
||||||
|
if meta != nil {
|
||||||
|
if v, ok := meta["log_entries"]; ok {
|
||||||
|
out["log_entries"] = v
|
||||||
|
}
|
||||||
|
if v, ok := meta["log_total"]; ok {
|
||||||
|
out["log_total"] = v
|
||||||
|
}
|
||||||
|
if v, ok := meta["revision_id"]; ok {
|
||||||
|
out["revision_id"] = v
|
||||||
|
}
|
||||||
|
}
|
||||||
|
writeJSON(w, http.StatusOK, out)
|
||||||
|
}
|
||||||
|
|
||||||
func (s *Server) handleCancelJob(w http.ResponseWriter, r *http.Request) {
|
func (s *Server) handleCancelJob(w http.ResponseWriter, r *http.Request) {
|
||||||
a, ok := authFromContext(r.Context())
|
a, ok := authFromContext(r.Context())
|
||||||
if !ok {
|
if !ok {
|
||||||
@@ -1191,7 +987,7 @@ func (s *Server) handleNodeBundle(w http.ResponseWriter, r *http.Request) {
|
|||||||
}
|
}
|
||||||
tgz, err := bundle.BuildGzippedTar(rid, sid, rev.PreviewFragments, s.bundlePriv)
|
tgz, err := bundle.BuildGzippedTar(rid, sid, rev.PreviewFragments, s.bundlePriv)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
writeProblem(w, http.StatusInternalServerError, "Internal Error", err.Error())
|
writeInternalError(w, "internal", err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
w.Header().Set("Content-Type", "application/gzip")
|
w.Header().Set("Content-Type", "application/gzip")
|
||||||
@@ -1241,7 +1037,7 @@ func (s *Server) handleNodeEnroll(w http.ResponseWriter, r *http.Request) {
|
|||||||
}
|
}
|
||||||
patch := &store.SpeakerPatch{MetaJSON: &meta}
|
patch := &store.SpeakerPatch{MetaJSON: &meta}
|
||||||
if _, err := s.store.UpdateSpeaker(a.TenantID, sid, patch); err != nil {
|
if _, err := s.store.UpdateSpeaker(a.TenantID, sid, patch); err != nil {
|
||||||
writeProblem(w, http.StatusInternalServerError, "Internal Error", err.Error())
|
writeInternalError(w, "internal", err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
writeJSON(w, http.StatusOK, map[string]any{
|
writeJSON(w, http.StatusOK, map[string]any{
|
||||||
|
|||||||
+45
-176
@@ -3,13 +3,16 @@ package httpapi
|
|||||||
import (
|
import (
|
||||||
"encoding/csv"
|
"encoding/csv"
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
|
"log"
|
||||||
"net/http"
|
"net/http"
|
||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
"evobgp/internal/importer"
|
||||||
"evobgp/internal/pipeline"
|
"evobgp/internal/pipeline"
|
||||||
"evobgp/internal/store"
|
"evobgp/internal/store"
|
||||||
)
|
)
|
||||||
@@ -170,15 +173,18 @@ func (s *Server) handleDeleteModule(w http.ResponseWriter, r *http.Request) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func writeStoreErr(w http.ResponseWriter, err error) {
|
func writeStoreErr(w http.ResponseWriter, err error) {
|
||||||
|
if err != nil {
|
||||||
|
log.Printf("httpapi: store: %v", err)
|
||||||
|
}
|
||||||
if err == store.ErrNotFound || err == store.ErrTenantScope {
|
if err == store.ErrNotFound || err == store.ErrTenantScope {
|
||||||
writeProblem(w, http.StatusNotFound, "Not Found", err.Error())
|
writeProblem(w, http.StatusNotFound, "Not Found", notFoundDetail)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
if err == store.ErrInvalidInput {
|
if err == store.ErrInvalidInput {
|
||||||
writeProblem(w, http.StatusUnprocessableEntity, "Unprocessable Entity", err.Error())
|
writeProblem(w, http.StatusUnprocessableEntity, "Unprocessable Entity", invalidInputDetail)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
writeProblem(w, http.StatusInternalServerError, "Internal Error", err.Error())
|
writeInternalError(w, "store", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *Server) handleListCDNSources(w http.ResponseWriter, r *http.Request) {
|
func (s *Server) handleListCDNSources(w http.ResponseWriter, r *http.Request) {
|
||||||
@@ -191,11 +197,7 @@ func (s *Server) handleListCDNSources(w http.ResponseWriter, r *http.Request) {
|
|||||||
writeStoreErr(w, err)
|
writeStoreErr(w, err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
items := make([]map[string]any, 0, len(list))
|
writePaginatedListJSON(w, r, list, cdnSourceJSON)
|
||||||
for _, x := range list {
|
|
||||||
items = append(items, cdnSourceJSON(x))
|
|
||||||
}
|
|
||||||
writeJSON(w, http.StatusOK, map[string]any{"items": items, "next_cursor": nil, "has_more": false})
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func cdnSourceJSON(x *store.CDNSource) map[string]any {
|
func cdnSourceJSON(x *store.CDNSource) map[string]any {
|
||||||
@@ -251,25 +253,26 @@ func (s *Server) handlePreviewCDNSource(w http.ResponseWriter, r *http.Request)
|
|||||||
writeProblem(w, http.StatusUnprocessableEntity, "Unprocessable Entity", "invalid url")
|
writeProblem(w, http.StatusUnprocessableEntity, "Unprocessable Entity", "invalid url")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
resp, err := http.DefaultClient.Do(req)
|
resp, err := s.cdnHTTP.Do(req)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
writeProblem(w, http.StatusBadGateway, "Bad Gateway", err.Error())
|
writeBadGateway(w, "cdn preview fetch", err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
defer resp.Body.Close()
|
defer func() { _ = resp.Body.Close() }()
|
||||||
if resp.StatusCode != http.StatusOK {
|
if resp.StatusCode != http.StatusOK {
|
||||||
_, _ = io.Copy(io.Discard, resp.Body)
|
_, _ = io.Copy(io.Discard, resp.Body)
|
||||||
writeProblem(w, http.StatusBadGateway, "Bad Gateway", fmt.Sprintf("upstream status: %s", resp.Status))
|
writeBadGateway(w, "cdn preview fetch", fmt.Errorf("upstream status: %s", resp.Status))
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
raw, err := io.ReadAll(io.LimitReader(resp.Body, 8<<20))
|
raw, err := io.ReadAll(io.LimitReader(resp.Body, 8<<20))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
writeProblem(w, http.StatusBadGateway, "Bad Gateway", err.Error())
|
writeBadGateway(w, "cdn preview read body", err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
pfxs, err := pipeline.ExtractCIDRs(string(raw), body.SourceKind, body.PrefixPath)
|
pfxs, err := pipeline.ExtractCIDRs(string(raw), body.SourceKind, body.PrefixPath)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
writeProblem(w, http.StatusUnprocessableEntity, "Unprocessable Entity", err.Error())
|
log.Printf("httpapi: cdn preview extract: %v", err)
|
||||||
|
writeProblem(w, http.StatusUnprocessableEntity, "Unprocessable Entity", cdnExtractDetail)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
items := make([]string, 0, len(pfxs))
|
items := make([]string, 0, len(pfxs))
|
||||||
@@ -352,11 +355,7 @@ func (s *Server) handleListAS(w http.ResponseWriter, r *http.Request) {
|
|||||||
writeStoreErr(w, err)
|
writeStoreErr(w, err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
items := make([]map[string]any, 0, len(list))
|
writePaginatedListJSON(w, r, list, asEntryJSON)
|
||||||
for _, x := range list {
|
|
||||||
items = append(items, asEntryJSON(x))
|
|
||||||
}
|
|
||||||
writeJSON(w, http.StatusOK, map[string]any{"items": items})
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func asEntryJSON(x *store.ASEntry) map[string]any {
|
func asEntryJSON(x *store.ASEntry) map[string]any {
|
||||||
@@ -448,11 +447,7 @@ func (s *Server) handleListDomain(w http.ResponseWriter, r *http.Request) {
|
|||||||
writeStoreErr(w, err)
|
writeStoreErr(w, err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
items := make([]map[string]any, 0, len(list))
|
writePaginatedListJSON(w, r, list, domainEntryJSON)
|
||||||
for _, x := range list {
|
|
||||||
items = append(items, domainEntryJSON(x))
|
|
||||||
}
|
|
||||||
writeJSON(w, http.StatusOK, map[string]any{"items": items})
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func domainEntryJSON(x *store.DomainEntry) map[string]any {
|
func domainEntryJSON(x *store.DomainEntry) map[string]any {
|
||||||
@@ -529,11 +524,7 @@ func (s *Server) handleListIPRange(w http.ResponseWriter, r *http.Request) {
|
|||||||
writeStoreErr(w, err)
|
writeStoreErr(w, err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
items := make([]map[string]any, 0, len(list))
|
writePaginatedListJSON(w, r, list, ipRangeJSON)
|
||||||
for _, x := range list {
|
|
||||||
items = append(items, ipRangeJSON(x))
|
|
||||||
}
|
|
||||||
writeJSON(w, http.StatusOK, map[string]any{"items": items})
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func ipRangeJSON(x *store.IPRangeEntry) map[string]any {
|
func ipRangeJSON(x *store.IPRangeEntry) map[string]any {
|
||||||
@@ -689,163 +680,41 @@ func (s *Server) handleImportModuleEntriesCSV(w http.ResponseWriter, r *http.Req
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
moduleID := r.PathValue("module_id")
|
moduleID := r.PathValue("module_id")
|
||||||
mod, err := s.store.GetModule(a.TenantID, moduleID)
|
res, err := importer.ImportModuleEntriesCSV(s.store, a.TenantID, moduleID, r.Body)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
if errors.Is(err, store.ErrInvalidInput) {
|
||||||
|
writeProblem(w, http.StatusUnprocessableEntity, "Unprocessable Entity", "csv is empty")
|
||||||
|
return
|
||||||
|
}
|
||||||
|
if strings.Contains(err.Error(), "importer: invalid csv") {
|
||||||
|
writeProblem(w, http.StatusBadRequest, "Bad Request", "invalid csv")
|
||||||
|
return
|
||||||
|
}
|
||||||
|
if strings.Contains(err.Error(), "importer: line") {
|
||||||
|
log.Printf("httpapi: csv import: %v", err)
|
||||||
|
writeProblem(w, http.StatusUnprocessableEntity, "Unprocessable Entity", csvInvalidRowDetail)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
if strings.Contains(err.Error(), "importer: csv import/export") {
|
||||||
|
writeProblem(w, http.StatusUnprocessableEntity, "Unprocessable Entity", "csv import/export is supported only for AS_PREFIXES, DOMAINS, IP_RANGES")
|
||||||
|
return
|
||||||
|
}
|
||||||
writeStoreErr(w, err)
|
writeStoreErr(w, err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
if res.Imported > 0 {
|
||||||
cr := csv.NewReader(io.LimitReader(r.Body, 8<<20))
|
switch res.ModuleType {
|
||||||
cr.TrimLeadingSpace = true
|
case "AS_PREFIXES":
|
||||||
cr.FieldsPerRecord = -1
|
|
||||||
rows, err := cr.ReadAll()
|
|
||||||
if err != nil {
|
|
||||||
writeProblem(w, http.StatusBadRequest, "Bad Request", "invalid csv")
|
|
||||||
return
|
|
||||||
}
|
|
||||||
if len(rows) == 0 {
|
|
||||||
writeProblem(w, http.StatusUnprocessableEntity, "Unprocessable Entity", "csv is empty")
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
communities, err := s.store.ListCommunities(a.TenantID)
|
|
||||||
if err != nil {
|
|
||||||
writeStoreErr(w, err)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
communityIDByID := make(map[string]string, len(communities))
|
|
||||||
communityIDByValue := make(map[string]string, len(communities))
|
|
||||||
for _, c := range communities {
|
|
||||||
communityIDByID[c.ID] = c.ID
|
|
||||||
communityIDByValue[strings.TrimSpace(c.Community)] = c.ID
|
|
||||||
}
|
|
||||||
|
|
||||||
resolveCommunity := func(raw string, required bool) (*string, error) {
|
|
||||||
v := strings.TrimSpace(raw)
|
|
||||||
if v == "" {
|
|
||||||
if required {
|
|
||||||
return nil, fmt.Errorf("community is required")
|
|
||||||
}
|
|
||||||
return nil, nil
|
|
||||||
}
|
|
||||||
if id, ok := communityIDByID[v]; ok {
|
|
||||||
return &id, nil
|
|
||||||
}
|
|
||||||
if id, ok := communityIDByValue[v]; ok {
|
|
||||||
return &id, nil
|
|
||||||
}
|
|
||||||
return nil, fmt.Errorf("unknown community %q", v)
|
|
||||||
}
|
|
||||||
|
|
||||||
start := 0
|
|
||||||
if len(rows[0]) >= 2 {
|
|
||||||
key := strings.ToLower(strings.TrimSpace(rows[0][0]))
|
|
||||||
switch key {
|
|
||||||
case "asn", "domain", "iprange":
|
|
||||||
start = 1
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
imported := 0
|
|
||||||
switch mod.Type {
|
|
||||||
case "AS_PREFIXES":
|
|
||||||
for i := start; i < len(rows); i++ {
|
|
||||||
rec := rows[i]
|
|
||||||
if len(rec) == 0 || (strings.TrimSpace(rec[0]) == "" && (len(rec) < 2 || strings.TrimSpace(rec[1]) == "")) {
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
if len(rec) < 2 {
|
|
||||||
writeProblem(w, http.StatusUnprocessableEntity, "Unprocessable Entity", fmt.Sprintf("line %d: expected 2 columns", i+1))
|
|
||||||
return
|
|
||||||
}
|
|
||||||
asn, err := strconv.ParseInt(strings.TrimSpace(rec[0]), 10, 64)
|
|
||||||
if err != nil || asn <= 0 {
|
|
||||||
writeProblem(w, http.StatusUnprocessableEntity, "Unprocessable Entity", fmt.Sprintf("line %d: invalid asn", i+1))
|
|
||||||
return
|
|
||||||
}
|
|
||||||
cid, err := resolveCommunity(rec[1], false)
|
|
||||||
if err != nil {
|
|
||||||
writeProblem(w, http.StatusUnprocessableEntity, "Unprocessable Entity", fmt.Sprintf("line %d: %v", i+1, err))
|
|
||||||
return
|
|
||||||
}
|
|
||||||
_, err = s.store.CreateASEntry(a.TenantID, moduleID, &store.ASEntry{ASN: asn, CommunityID: cid})
|
|
||||||
if err != nil {
|
|
||||||
writeStoreErr(w, err)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
imported++
|
|
||||||
}
|
|
||||||
if imported > 0 {
|
|
||||||
s.enqueueModuleRefreshIfEnabled(a.TenantID, moduleID, "as_entry_import_csv")
|
s.enqueueModuleRefreshIfEnabled(a.TenantID, moduleID, "as_entry_import_csv")
|
||||||
}
|
case "DOMAINS":
|
||||||
case "DOMAINS":
|
|
||||||
for i := start; i < len(rows); i++ {
|
|
||||||
rec := rows[i]
|
|
||||||
if len(rec) == 0 || (strings.TrimSpace(rec[0]) == "" && (len(rec) < 2 || strings.TrimSpace(rec[1]) == "")) {
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
if len(rec) < 2 {
|
|
||||||
writeProblem(w, http.StatusUnprocessableEntity, "Unprocessable Entity", fmt.Sprintf("line %d: expected 2 columns", i+1))
|
|
||||||
return
|
|
||||||
}
|
|
||||||
fqdn := strings.TrimSpace(rec[0])
|
|
||||||
if fqdn == "" {
|
|
||||||
writeProblem(w, http.StatusUnprocessableEntity, "Unprocessable Entity", fmt.Sprintf("line %d: domain is required", i+1))
|
|
||||||
return
|
|
||||||
}
|
|
||||||
cid, err := resolveCommunity(rec[1], false)
|
|
||||||
if err != nil {
|
|
||||||
writeProblem(w, http.StatusUnprocessableEntity, "Unprocessable Entity", fmt.Sprintf("line %d: %v", i+1, err))
|
|
||||||
return
|
|
||||||
}
|
|
||||||
_, err = s.store.CreateDomainEntry(a.TenantID, moduleID, &store.DomainEntry{FQDN: fqdn, CommunityID: cid})
|
|
||||||
if err != nil {
|
|
||||||
writeStoreErr(w, err)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
imported++
|
|
||||||
}
|
|
||||||
if imported > 0 {
|
|
||||||
s.enqueueModuleRefreshIfEnabled(a.TenantID, moduleID, "domain_entry_import_csv")
|
s.enqueueModuleRefreshIfEnabled(a.TenantID, moduleID, "domain_entry_import_csv")
|
||||||
}
|
case "IP_RANGES":
|
||||||
case "IP_RANGES":
|
|
||||||
for i := start; i < len(rows); i++ {
|
|
||||||
rec := rows[i]
|
|
||||||
if len(rec) == 0 || (strings.TrimSpace(rec[0]) == "" && (len(rec) < 2 || strings.TrimSpace(rec[1]) == "")) {
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
if len(rec) < 2 {
|
|
||||||
writeProblem(w, http.StatusUnprocessableEntity, "Unprocessable Entity", fmt.Sprintf("line %d: expected 2 columns", i+1))
|
|
||||||
return
|
|
||||||
}
|
|
||||||
prefix := strings.TrimSpace(rec[0])
|
|
||||||
if prefix == "" {
|
|
||||||
writeProblem(w, http.StatusUnprocessableEntity, "Unprocessable Entity", fmt.Sprintf("line %d: ipRange is required", i+1))
|
|
||||||
return
|
|
||||||
}
|
|
||||||
cid, err := resolveCommunity(rec[1], true)
|
|
||||||
if err != nil {
|
|
||||||
writeProblem(w, http.StatusUnprocessableEntity, "Unprocessable Entity", fmt.Sprintf("line %d: %v", i+1, err))
|
|
||||||
return
|
|
||||||
}
|
|
||||||
_, err = s.store.CreateIPRangeEntry(a.TenantID, moduleID, &store.IPRangeEntry{Prefix: prefix, CommunityID: cid})
|
|
||||||
if err != nil {
|
|
||||||
writeStoreErr(w, err)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
imported++
|
|
||||||
}
|
|
||||||
if imported > 0 {
|
|
||||||
s.enqueueModuleRefreshIfEnabled(a.TenantID, moduleID, "ip_range_import_csv")
|
s.enqueueModuleRefreshIfEnabled(a.TenantID, moduleID, "ip_range_import_csv")
|
||||||
}
|
}
|
||||||
default:
|
|
||||||
writeProblem(w, http.StatusUnprocessableEntity, "Unprocessable Entity", "csv import/export is supported only for AS_PREFIXES, DOMAINS, IP_RANGES")
|
|
||||||
return
|
|
||||||
}
|
}
|
||||||
|
|
||||||
writeJSON(w, http.StatusOK, map[string]any{
|
writeJSON(w, http.StatusOK, map[string]any{
|
||||||
"imported": imported,
|
"imported": res.Imported,
|
||||||
"module_type": mod.Type,
|
"module_type": res.ModuleType,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -34,7 +34,7 @@ func TestModuleEntriesCSVImportExportIPRanges(t *testing.T) {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
defer respList.Body.Close()
|
defer func() { _ = respList.Body.Close() }()
|
||||||
if respList.StatusCode != http.StatusOK {
|
if respList.StatusCode != http.StatusOK {
|
||||||
b, _ := io.ReadAll(respList.Body)
|
b, _ := io.ReadAll(respList.Body)
|
||||||
t.Fatalf("communities status %d: %s", respList.StatusCode, b)
|
t.Fatalf("communities status %d: %s", respList.StatusCode, b)
|
||||||
@@ -59,7 +59,7 @@ func TestModuleEntriesCSVImportExportIPRanges(t *testing.T) {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
defer respImport.Body.Close()
|
defer func() { _ = respImport.Body.Close() }()
|
||||||
if respImport.StatusCode != http.StatusOK {
|
if respImport.StatusCode != http.StatusOK {
|
||||||
b, _ := io.ReadAll(respImport.Body)
|
b, _ := io.ReadAll(respImport.Body)
|
||||||
t.Fatalf("import status %d: %s", respImport.StatusCode, b)
|
t.Fatalf("import status %d: %s", respImport.StatusCode, b)
|
||||||
@@ -80,7 +80,7 @@ func TestModuleEntriesCSVImportExportIPRanges(t *testing.T) {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
defer respExport.Body.Close()
|
defer func() { _ = respExport.Body.Close() }()
|
||||||
if respExport.StatusCode != http.StatusOK {
|
if respExport.StatusCode != http.StatusOK {
|
||||||
b, _ := io.ReadAll(respExport.Body)
|
b, _ := io.ReadAll(respExport.Body)
|
||||||
t.Fatalf("export status %d: %s", respExport.StatusCode, b)
|
t.Fatalf("export status %d: %s", respExport.StatusCode, b)
|
||||||
|
|||||||
@@ -0,0 +1,87 @@
|
|||||||
|
package httpapi
|
||||||
|
|
||||||
|
import (
|
||||||
|
"encoding/json"
|
||||||
|
"fmt"
|
||||||
|
"io"
|
||||||
|
"net/http"
|
||||||
|
"net/http/httptest"
|
||||||
|
"strings"
|
||||||
|
"testing"
|
||||||
|
)
|
||||||
|
|
||||||
|
func TestNestedModuleListPagination(t *testing.T) {
|
||||||
|
srv, err := New(Options{InsecureDev: true, SeedDemo: true, BundleSeedHex: testBundleSeed})
|
||||||
|
if err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
defer srv.Close()
|
||||||
|
tenant, _, modIP, _, _ := srv.Store().DemoIDs()
|
||||||
|
srv.apiKeys = parseAPIKeysSpec("edkey|" + tenant + "|editor")
|
||||||
|
|
||||||
|
ts := httptest.NewServer(srv.Handler())
|
||||||
|
defer ts.Close()
|
||||||
|
client := ts.Client()
|
||||||
|
base := ts.URL
|
||||||
|
mid := modIP
|
||||||
|
|
||||||
|
for i := 0; i < 3; i++ {
|
||||||
|
body := strings.NewReader(fmt.Sprintf(`{"prefix":"10.%d.0.0/24"}`, 200+i))
|
||||||
|
req, _ := http.NewRequest(http.MethodPost, base+"/v1/modules/"+mid+"/ip-range-entries", body)
|
||||||
|
req.Header.Set("Authorization", "Bearer edkey")
|
||||||
|
req.Header.Set("Content-Type", "application/json")
|
||||||
|
resp, err := client.Do(req)
|
||||||
|
if err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
_, _ = io.Copy(io.Discard, resp.Body)
|
||||||
|
_ = resp.Body.Close()
|
||||||
|
if resp.StatusCode != http.StatusCreated {
|
||||||
|
t.Fatalf("create entry %d: status %d", i, resp.StatusCode)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
req, _ := http.NewRequest(http.MethodGet, base+"/v1/modules/"+mid+"/ip-range-entries?limit=2", nil)
|
||||||
|
req.Header.Set("Authorization", "Bearer edkey")
|
||||||
|
resp, err := client.Do(req)
|
||||||
|
if err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
defer func() { _ = resp.Body.Close() }()
|
||||||
|
if resp.StatusCode != http.StatusOK {
|
||||||
|
b, _ := io.ReadAll(resp.Body)
|
||||||
|
t.Fatalf("list status %d: %s", resp.StatusCode, b)
|
||||||
|
}
|
||||||
|
var page1 struct {
|
||||||
|
Items []map[string]any `json:"items"`
|
||||||
|
NextCursor *string `json:"next_cursor"`
|
||||||
|
HasMore bool `json:"has_more"`
|
||||||
|
}
|
||||||
|
if err := json.NewDecoder(resp.Body).Decode(&page1); err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
if len(page1.Items) != 2 {
|
||||||
|
t.Fatalf("page1 items: got %d want 2", len(page1.Items))
|
||||||
|
}
|
||||||
|
if !page1.HasMore || page1.NextCursor == nil || *page1.NextCursor == "" {
|
||||||
|
t.Fatalf("page1: has_more=%v next_cursor=%v", page1.HasMore, page1.NextCursor)
|
||||||
|
}
|
||||||
|
|
||||||
|
req2, _ := http.NewRequest(http.MethodGet, base+"/v1/modules/"+mid+"/ip-range-entries?limit=2&cursor="+*page1.NextCursor, nil)
|
||||||
|
req2.Header.Set("Authorization", "Bearer edkey")
|
||||||
|
resp2, err := client.Do(req2)
|
||||||
|
if err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
defer func() { _ = resp2.Body.Close() }()
|
||||||
|
var page2 struct {
|
||||||
|
Items []map[string]any `json:"items"`
|
||||||
|
HasMore bool `json:"has_more"`
|
||||||
|
}
|
||||||
|
if err := json.NewDecoder(resp2.Body).Decode(&page2); err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
if len(page1.Items)+len(page2.Items) < 3 {
|
||||||
|
t.Fatalf("expected at least 3 entries across pages, got %d+%d", len(page1.Items), len(page2.Items))
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -24,6 +24,7 @@ type Server struct {
|
|||||||
apiKeys []apiKeyRecord
|
apiKeys []apiKeyRecord
|
||||||
insecureDev bool
|
insecureDev bool
|
||||||
corsOrigins []string
|
corsOrigins []string
|
||||||
|
cdnHTTP *http.Client
|
||||||
mux *http.ServeMux
|
mux *http.ServeMux
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -31,10 +32,10 @@ type Server struct {
|
|||||||
type Options struct {
|
type Options struct {
|
||||||
APIKeys string
|
APIKeys string
|
||||||
// DatabaseURL enables PostgreSQL-backed store (migrations applied on connect).
|
// DatabaseURL enables PostgreSQL-backed store (migrations applied on connect).
|
||||||
DatabaseURL string
|
DatabaseURL string
|
||||||
InsecureDev bool
|
InsecureDev bool
|
||||||
SeedDemo bool
|
SeedDemo bool
|
||||||
BundleSeedHex string
|
BundleSeedHex string
|
||||||
CORSAllowedOrigins string
|
CORSAllowedOrigins string
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -67,6 +68,7 @@ func New(opts Options) (*Server, error) {
|
|||||||
apiKeys: parseAPIKeysSpec(opts.APIKeys),
|
apiKeys: parseAPIKeysSpec(opts.APIKeys),
|
||||||
insecureDev: opts.InsecureDev && opts.SeedDemo,
|
insecureDev: opts.InsecureDev && opts.SeedDemo,
|
||||||
corsOrigins: parseCORSOrigins(opts.CORSAllowedOrigins),
|
corsOrigins: parseCORSOrigins(opts.CORSAllowedOrigins),
|
||||||
|
cdnHTTP: NewCDNHTTPClient(),
|
||||||
}
|
}
|
||||||
s.mux = http.NewServeMux()
|
s.mux = http.NewServeMux()
|
||||||
s.registerRoutes()
|
s.registerRoutes()
|
||||||
|
|||||||
@@ -13,6 +13,7 @@ import (
|
|||||||
|
|
||||||
"evobgp/internal/jobs"
|
"evobgp/internal/jobs"
|
||||||
"evobgp/internal/signing"
|
"evobgp/internal/signing"
|
||||||
|
"evobgp/internal/version"
|
||||||
)
|
)
|
||||||
|
|
||||||
const testBundleSeed = "0101010101010101010101010101010101010101010101010101010101010101"
|
const testBundleSeed = "0101010101010101010101010101010101010101010101010101010101010101"
|
||||||
@@ -28,7 +29,7 @@ func TestAPIRefreshApplyJobsBundle(t *testing.T) {
|
|||||||
}
|
}
|
||||||
defer srv.Close()
|
defer srv.Close()
|
||||||
tenant, modCDN, modIP, rev, speaker := srv.Store().DemoIDs()
|
tenant, modCDN, modIP, rev, speaker := srv.Store().DemoIDs()
|
||||||
srv.apiKeys = parseAPIKeysSpec("nodekey|" + tenant + "|node,opkey|" + tenant + "|operator")
|
srv.apiKeys = parseAPIKeysSpec("nodekey|" + tenant + "|node,opkey|" + tenant + "|operator,edkey|" + tenant + "|editor")
|
||||||
|
|
||||||
ts := httptest.NewServer(srv.Handler())
|
ts := httptest.NewServer(srv.Handler())
|
||||||
defer ts.Close()
|
defer ts.Close()
|
||||||
@@ -50,7 +51,7 @@ func TestAPIRefreshApplyJobsBundle(t *testing.T) {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
defer resp.Body.Close()
|
defer func() { _ = resp.Body.Close() }()
|
||||||
if resp.StatusCode != http.StatusOK {
|
if resp.StatusCode != http.StatusOK {
|
||||||
b, _ := io.ReadAll(resp.Body)
|
b, _ := io.ReadAll(resp.Body)
|
||||||
t.Fatalf("status %d: %s", resp.StatusCode, b)
|
t.Fatalf("status %d: %s", resp.StatusCode, b)
|
||||||
@@ -75,7 +76,7 @@ func TestAPIRefreshApplyJobsBundle(t *testing.T) {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
defer resp.Body.Close()
|
defer func() { _ = resp.Body.Close() }()
|
||||||
if resp.StatusCode != http.StatusAccepted {
|
if resp.StatusCode != http.StatusAccepted {
|
||||||
b, _ := io.ReadAll(resp.Body)
|
b, _ := io.ReadAll(resp.Body)
|
||||||
t.Fatalf("status %d: %s", resp.StatusCode, b)
|
t.Fatalf("status %d: %s", resp.StatusCode, b)
|
||||||
@@ -96,7 +97,7 @@ func TestAPIRefreshApplyJobsBundle(t *testing.T) {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
defer resp.Body.Close()
|
defer func() { _ = resp.Body.Close() }()
|
||||||
if resp.StatusCode != http.StatusAccepted {
|
if resp.StatusCode != http.StatusAccepted {
|
||||||
b, _ := io.ReadAll(resp.Body)
|
b, _ := io.ReadAll(resp.Body)
|
||||||
t.Fatalf("status %d: %s", resp.StatusCode, b)
|
t.Fatalf("status %d: %s", resp.StatusCode, b)
|
||||||
@@ -117,7 +118,7 @@ func TestAPIRefreshApplyJobsBundle(t *testing.T) {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
defer resp.Body.Close()
|
defer func() { _ = resp.Body.Close() }()
|
||||||
if resp.StatusCode != http.StatusOK {
|
if resp.StatusCode != http.StatusOK {
|
||||||
b, _ := io.ReadAll(resp.Body)
|
b, _ := io.ReadAll(resp.Body)
|
||||||
t.Fatalf("status %d: %s", resp.StatusCode, b)
|
t.Fatalf("status %d: %s", resp.StatusCode, b)
|
||||||
@@ -131,7 +132,7 @@ func TestAPIRefreshApplyJobsBundle(t *testing.T) {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
defer resp.Body.Close()
|
defer func() { _ = resp.Body.Close() }()
|
||||||
if resp.StatusCode != http.StatusOK {
|
if resp.StatusCode != http.StatusOK {
|
||||||
b, _ := io.ReadAll(resp.Body)
|
b, _ := io.ReadAll(resp.Body)
|
||||||
t.Fatalf("status %d: %s", resp.StatusCode, b)
|
t.Fatalf("status %d: %s", resp.StatusCode, b)
|
||||||
@@ -161,7 +162,7 @@ func TestAPIRefreshApplyJobsBundle(t *testing.T) {
|
|||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
b, _ := io.ReadAll(resp.Body)
|
b, _ := io.ReadAll(resp.Body)
|
||||||
resp.Body.Close()
|
_ = resp.Body.Close()
|
||||||
if resp.StatusCode != http.StatusOK {
|
if resp.StatusCode != http.StatusOK {
|
||||||
t.Fatalf("%s status %d: %s", path, resp.StatusCode, b)
|
t.Fatalf("%s status %d: %s", path, resp.StatusCode, b)
|
||||||
}
|
}
|
||||||
@@ -184,7 +185,7 @@ func TestAPIRefreshApplyJobsBundle(t *testing.T) {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
defer resp.Body.Close()
|
defer func() { _ = resp.Body.Close() }()
|
||||||
if resp.StatusCode != http.StatusOK {
|
if resp.StatusCode != http.StatusOK {
|
||||||
b, _ := io.ReadAll(resp.Body)
|
b, _ := io.ReadAll(resp.Body)
|
||||||
t.Fatalf("status %d: %s", resp.StatusCode, b)
|
t.Fatalf("status %d: %s", resp.StatusCode, b)
|
||||||
@@ -214,7 +215,7 @@ func TestAPIRefreshApplyJobsBundle(t *testing.T) {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
defer resp.Body.Close()
|
defer func() { _ = resp.Body.Close() }()
|
||||||
if resp.StatusCode != http.StatusOK {
|
if resp.StatusCode != http.StatusOK {
|
||||||
b, _ := io.ReadAll(resp.Body)
|
b, _ := io.ReadAll(resp.Body)
|
||||||
t.Fatalf("status %d: %s", resp.StatusCode, b)
|
t.Fatalf("status %d: %s", resp.StatusCode, b)
|
||||||
@@ -247,6 +248,20 @@ func TestAPIRefreshApplyJobsBundle(t *testing.T) {
|
|||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
|
t.Run("rollback forbidden for editor", func(t *testing.T) {
|
||||||
|
req, _ := http.NewRequest(http.MethodPost, base+"/v1/revisions/"+rev+"/rollback", nil)
|
||||||
|
req.Header.Set("Authorization", "Bearer edkey")
|
||||||
|
resp, err := client.Do(req)
|
||||||
|
if err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
defer func() { _ = resp.Body.Close() }()
|
||||||
|
if resp.StatusCode != http.StatusForbidden {
|
||||||
|
b, _ := io.ReadAll(resp.Body)
|
||||||
|
t.Fatalf("status %d want 403: %s", resp.StatusCode, b)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
t.Run("rollback queues job", func(t *testing.T) {
|
t.Run("rollback queues job", func(t *testing.T) {
|
||||||
req, _ := http.NewRequest(http.MethodPost, base+"/v1/revisions/"+rev+"/rollback", nil)
|
req, _ := http.NewRequest(http.MethodPost, base+"/v1/revisions/"+rev+"/rollback", nil)
|
||||||
req.Header.Set("Authorization", "Bearer opkey")
|
req.Header.Set("Authorization", "Bearer opkey")
|
||||||
@@ -254,7 +269,7 @@ func TestAPIRefreshApplyJobsBundle(t *testing.T) {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
defer resp.Body.Close()
|
defer func() { _ = resp.Body.Close() }()
|
||||||
if resp.StatusCode != http.StatusAccepted {
|
if resp.StatusCode != http.StatusAccepted {
|
||||||
b, _ := io.ReadAll(resp.Body)
|
b, _ := io.ReadAll(resp.Body)
|
||||||
t.Fatalf("status %d: %s", resp.StatusCode, b)
|
t.Fatalf("status %d: %s", resp.StatusCode, b)
|
||||||
@@ -274,7 +289,7 @@ func TestAPIRefreshApplyJobsBundle(t *testing.T) {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
defer resp.Body.Close()
|
defer func() { _ = resp.Body.Close() }()
|
||||||
if resp.StatusCode != http.StatusAccepted {
|
if resp.StatusCode != http.StatusAccepted {
|
||||||
b, _ := io.ReadAll(resp.Body)
|
b, _ := io.ReadAll(resp.Body)
|
||||||
t.Fatalf("status %d: %s", resp.StatusCode, b)
|
t.Fatalf("status %d: %s", resp.StatusCode, b)
|
||||||
@@ -299,7 +314,7 @@ func TestAPIRefreshApplyJobsBundle(t *testing.T) {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
defer resp.Body.Close()
|
defer func() { _ = resp.Body.Close() }()
|
||||||
if resp.StatusCode != http.StatusOK {
|
if resp.StatusCode != http.StatusOK {
|
||||||
b, _ := io.ReadAll(resp.Body)
|
b, _ := io.ReadAll(resp.Body)
|
||||||
t.Fatalf("status %d: %s", resp.StatusCode, b)
|
t.Fatalf("status %d: %s", resp.StatusCode, b)
|
||||||
@@ -326,7 +341,7 @@ func waitJob(t *testing.T, client *http.Client, base, token, jobID string) {
|
|||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
b, _ := io.ReadAll(resp.Body)
|
b, _ := io.ReadAll(resp.Body)
|
||||||
resp.Body.Close()
|
_ = resp.Body.Close()
|
||||||
var body struct {
|
var body struct {
|
||||||
Status string `json:"status"`
|
Status string `json:"status"`
|
||||||
}
|
}
|
||||||
@@ -357,3 +372,60 @@ evobgp_p_01234567 BGP master start 2026-04-09 Connect
|
|||||||
t.Fatalf("expected protocol state Connect, got %q", got["evobgp_p_01234567"])
|
t.Fatalf("expected protocol state Connect, got %q", got["evobgp_p_01234567"])
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestVersionEndpoints(t *testing.T) {
|
||||||
|
srv, err := New(Options{
|
||||||
|
InsecureDev: true,
|
||||||
|
SeedDemo: true,
|
||||||
|
BundleSeedHex: testBundleSeed,
|
||||||
|
})
|
||||||
|
if err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
defer srv.Close()
|
||||||
|
|
||||||
|
oldVer := version.Version
|
||||||
|
oldSHA := version.GitSHA
|
||||||
|
oldTime := version.BuildTime
|
||||||
|
version.Version = "1.2.3"
|
||||||
|
version.GitSHA = "abc123def456"
|
||||||
|
version.BuildTime = "2026-05-20T12:00:00Z"
|
||||||
|
t.Cleanup(func() {
|
||||||
|
version.Version = oldVer
|
||||||
|
version.GitSHA = oldSHA
|
||||||
|
version.BuildTime = oldTime
|
||||||
|
})
|
||||||
|
|
||||||
|
ts := httptest.NewServer(srv.Handler())
|
||||||
|
defer ts.Close()
|
||||||
|
|
||||||
|
for _, path := range []string{"/version", "/v1/version"} {
|
||||||
|
t.Run(path, func(t *testing.T) {
|
||||||
|
resp, err := http.Get(ts.URL + path)
|
||||||
|
if err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
defer func() { _ = resp.Body.Close() }()
|
||||||
|
if resp.StatusCode != http.StatusOK {
|
||||||
|
b, _ := io.ReadAll(resp.Body)
|
||||||
|
t.Fatalf("status %d: %s", resp.StatusCode, b)
|
||||||
|
}
|
||||||
|
var body map[string]string
|
||||||
|
if err := json.NewDecoder(resp.Body).Decode(&body); err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
if body["version"] != "1.2.3" {
|
||||||
|
t.Fatalf("version=%q want 1.2.3", body["version"])
|
||||||
|
}
|
||||||
|
if body["api_version"] != "1.2.3" {
|
||||||
|
t.Fatalf("api_version=%q want 1.2.3", body["api_version"])
|
||||||
|
}
|
||||||
|
if body["git_sha"] != "abc123def456" {
|
||||||
|
t.Fatalf("git_sha=%q", body["git_sha"])
|
||||||
|
}
|
||||||
|
if body["build_time"] != "2026-05-20T12:00:00Z" {
|
||||||
|
t.Fatalf("build_time=%q", body["build_time"])
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,147 @@
|
|||||||
|
package importer
|
||||||
|
|
||||||
|
import (
|
||||||
|
"encoding/csv"
|
||||||
|
"fmt"
|
||||||
|
"io"
|
||||||
|
"strconv"
|
||||||
|
"strings"
|
||||||
|
|
||||||
|
"evobgp/internal/store"
|
||||||
|
)
|
||||||
|
|
||||||
|
// Result of importing module entries from CSV.
|
||||||
|
type Result struct {
|
||||||
|
Imported int
|
||||||
|
ModuleType string
|
||||||
|
}
|
||||||
|
|
||||||
|
// ImportModuleEntriesCSV parses and creates entries for AS_PREFIXES, DOMAINS, or IP_RANGES modules.
|
||||||
|
func ImportModuleEntriesCSV(st store.Backend, tenantID, moduleID string, body io.Reader) (*Result, error) {
|
||||||
|
mod, err := st.GetModule(tenantID, moduleID)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
cr := csv.NewReader(io.LimitReader(body, 8<<20))
|
||||||
|
cr.TrimLeadingSpace = true
|
||||||
|
cr.FieldsPerRecord = -1
|
||||||
|
rows, err := cr.ReadAll()
|
||||||
|
if err != nil {
|
||||||
|
return nil, fmt.Errorf("importer: invalid csv: %w", err)
|
||||||
|
}
|
||||||
|
if len(rows) == 0 {
|
||||||
|
return nil, fmt.Errorf("importer: %w", store.ErrInvalidInput)
|
||||||
|
}
|
||||||
|
|
||||||
|
communities, err := st.ListCommunities(tenantID)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
communityIDByID := make(map[string]string, len(communities))
|
||||||
|
communityIDByValue := make(map[string]string, len(communities))
|
||||||
|
for _, c := range communities {
|
||||||
|
communityIDByID[c.ID] = c.ID
|
||||||
|
communityIDByValue[strings.TrimSpace(c.Community)] = c.ID
|
||||||
|
}
|
||||||
|
|
||||||
|
resolveCommunity := func(raw string, required bool) (*string, error) {
|
||||||
|
v := strings.TrimSpace(raw)
|
||||||
|
if v == "" {
|
||||||
|
if required {
|
||||||
|
return nil, fmt.Errorf("community is required")
|
||||||
|
}
|
||||||
|
return nil, nil
|
||||||
|
}
|
||||||
|
if id, ok := communityIDByID[v]; ok {
|
||||||
|
return &id, nil
|
||||||
|
}
|
||||||
|
if id, ok := communityIDByValue[v]; ok {
|
||||||
|
return &id, nil
|
||||||
|
}
|
||||||
|
return nil, fmt.Errorf("unknown community %q", v)
|
||||||
|
}
|
||||||
|
|
||||||
|
start := 0
|
||||||
|
if len(rows[0]) >= 2 {
|
||||||
|
key := strings.ToLower(strings.TrimSpace(rows[0][0]))
|
||||||
|
switch key {
|
||||||
|
case "asn", "domain", "iprange":
|
||||||
|
start = 1
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
imported := 0
|
||||||
|
switch mod.Type {
|
||||||
|
case "AS_PREFIXES":
|
||||||
|
for i := start; i < len(rows); i++ {
|
||||||
|
rec := rows[i]
|
||||||
|
if len(rec) == 0 || (strings.TrimSpace(rec[0]) == "" && (len(rec) < 2 || strings.TrimSpace(rec[1]) == "")) {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
if len(rec) < 2 {
|
||||||
|
return nil, fmt.Errorf("importer: line %d: expected 2 columns", i+1)
|
||||||
|
}
|
||||||
|
asn, err := strconv.ParseInt(strings.TrimSpace(rec[0]), 10, 64)
|
||||||
|
if err != nil || asn <= 0 {
|
||||||
|
return nil, fmt.Errorf("importer: line %d: invalid asn", i+1)
|
||||||
|
}
|
||||||
|
cid, err := resolveCommunity(rec[1], false)
|
||||||
|
if err != nil {
|
||||||
|
return nil, fmt.Errorf("importer: line %d: %w", i+1, err)
|
||||||
|
}
|
||||||
|
if _, err := st.CreateASEntry(tenantID, moduleID, &store.ASEntry{ASN: asn, CommunityID: cid}); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
imported++
|
||||||
|
}
|
||||||
|
case "DOMAINS":
|
||||||
|
for i := start; i < len(rows); i++ {
|
||||||
|
rec := rows[i]
|
||||||
|
if len(rec) == 0 || (strings.TrimSpace(rec[0]) == "" && (len(rec) < 2 || strings.TrimSpace(rec[1]) == "")) {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
if len(rec) < 2 {
|
||||||
|
return nil, fmt.Errorf("importer: line %d: expected 2 columns", i+1)
|
||||||
|
}
|
||||||
|
fqdn := strings.TrimSpace(rec[0])
|
||||||
|
if fqdn == "" {
|
||||||
|
return nil, fmt.Errorf("importer: line %d: domain is required", i+1)
|
||||||
|
}
|
||||||
|
cid, err := resolveCommunity(rec[1], false)
|
||||||
|
if err != nil {
|
||||||
|
return nil, fmt.Errorf("importer: line %d: %w", i+1, err)
|
||||||
|
}
|
||||||
|
if _, err := st.CreateDomainEntry(tenantID, moduleID, &store.DomainEntry{FQDN: fqdn, CommunityID: cid}); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
imported++
|
||||||
|
}
|
||||||
|
case "IP_RANGES":
|
||||||
|
for i := start; i < len(rows); i++ {
|
||||||
|
rec := rows[i]
|
||||||
|
if len(rec) == 0 || (strings.TrimSpace(rec[0]) == "" && (len(rec) < 2 || strings.TrimSpace(rec[1]) == "")) {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
if len(rec) < 2 {
|
||||||
|
return nil, fmt.Errorf("importer: line %d: expected 2 columns", i+1)
|
||||||
|
}
|
||||||
|
prefix := strings.TrimSpace(rec[0])
|
||||||
|
if prefix == "" {
|
||||||
|
return nil, fmt.Errorf("importer: line %d: ipRange is required", i+1)
|
||||||
|
}
|
||||||
|
cid, err := resolveCommunity(rec[1], true)
|
||||||
|
if err != nil {
|
||||||
|
return nil, fmt.Errorf("importer: line %d: %w", i+1, err)
|
||||||
|
}
|
||||||
|
if _, err := st.CreateIPRangeEntry(tenantID, moduleID, &store.IPRangeEntry{Prefix: prefix, CommunityID: cid}); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
imported++
|
||||||
|
}
|
||||||
|
default:
|
||||||
|
return nil, fmt.Errorf("importer: csv import/export is supported only for AS_PREFIXES, DOMAINS, IP_RANGES")
|
||||||
|
}
|
||||||
|
|
||||||
|
return &Result{Imported: imported, ModuleType: mod.Type}, nil
|
||||||
|
}
|
||||||
@@ -0,0 +1,77 @@
|
|||||||
|
package jobs
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
"os"
|
||||||
|
"strconv"
|
||||||
|
"time"
|
||||||
|
)
|
||||||
|
|
||||||
|
const (
|
||||||
|
defaultJobTimeoutModuleRefresh = 10 * time.Minute
|
||||||
|
defaultJobTimeoutTenantRefresh = 15 * time.Minute
|
||||||
|
defaultJobTimeoutDeployApply = 5 * time.Minute
|
||||||
|
defaultJobTimeoutPeerReconcile = 10 * time.Minute
|
||||||
|
defaultJobTimeoutRollback = 5 * time.Minute
|
||||||
|
defaultJobTimeoutBirdReload = 2 * time.Minute
|
||||||
|
)
|
||||||
|
|
||||||
|
func jobTimeout(kind string) time.Duration {
|
||||||
|
envKey := map[string]string{
|
||||||
|
KindModuleRefresh: "EVOBGP_JOB_TIMEOUT_MODULE_REFRESH",
|
||||||
|
KindTenantRefresh: "EVOBGP_JOB_TIMEOUT_TENANT_REFRESH",
|
||||||
|
KindDeployApply: "EVOBGP_JOB_TIMEOUT_DEPLOY_APPLY",
|
||||||
|
KindPeerReconcile: "EVOBGP_JOB_TIMEOUT_PEER_RECONCILE",
|
||||||
|
KindRevisionRollback: "EVOBGP_JOB_TIMEOUT_ROLLBACK",
|
||||||
|
KindBirdReload: "EVOBGP_JOB_TIMEOUT_BIRD_RELOAD",
|
||||||
|
}[kind]
|
||||||
|
if envKey != "" {
|
||||||
|
if d, err := time.ParseDuration(os.Getenv(envKey)); err == nil && d > 0 {
|
||||||
|
return d
|
||||||
|
}
|
||||||
|
}
|
||||||
|
switch kind {
|
||||||
|
case KindModuleRefresh:
|
||||||
|
return defaultJobTimeoutModuleRefresh
|
||||||
|
case KindTenantRefresh:
|
||||||
|
return defaultJobTimeoutTenantRefresh
|
||||||
|
case KindDeployApply:
|
||||||
|
return defaultJobTimeoutDeployApply
|
||||||
|
case KindPeerReconcile:
|
||||||
|
return defaultJobTimeoutPeerReconcile
|
||||||
|
case KindRevisionRollback:
|
||||||
|
return defaultJobTimeoutRollback
|
||||||
|
case KindBirdReload:
|
||||||
|
return defaultJobTimeoutBirdReload
|
||||||
|
default:
|
||||||
|
if n, err := strconv.Atoi(os.Getenv("EVOBGP_JOB_TIMEOUT_SEC")); err == nil && n > 0 {
|
||||||
|
return time.Duration(n) * time.Second
|
||||||
|
}
|
||||||
|
return defaultJobTimeoutModuleRefresh
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// workContext returns a timeout context that also cancels when the job is cancelled.
|
||||||
|
func (j *Job) workContext() (context.Context, context.CancelFunc) {
|
||||||
|
if j == nil {
|
||||||
|
return context.Background(), func() {}
|
||||||
|
}
|
||||||
|
timeout := jobTimeout(j.Kind)
|
||||||
|
ctx, cancel := context.WithTimeout(context.Background(), timeout)
|
||||||
|
go func() {
|
||||||
|
ticker := time.NewTicker(500 * time.Millisecond)
|
||||||
|
defer ticker.Stop()
|
||||||
|
for {
|
||||||
|
select {
|
||||||
|
case <-ctx.Done():
|
||||||
|
return
|
||||||
|
case <-ticker.C:
|
||||||
|
if j.IsCancelRequested() {
|
||||||
|
cancel()
|
||||||
|
return
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}()
|
||||||
|
return ctx, cancel
|
||||||
|
}
|
||||||
+51
-2
@@ -9,6 +9,8 @@ import (
|
|||||||
"sync"
|
"sync"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
"evobgp/internal/observability"
|
||||||
|
|
||||||
"github.com/google/uuid"
|
"github.com/google/uuid"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -178,6 +180,8 @@ type Registry struct {
|
|||||||
byID map[string]*Job
|
byID map[string]*Job
|
||||||
byIdempo map[idempoKey]*Job
|
byIdempo map[idempoKey]*Job
|
||||||
workerStart func(j *Job)
|
workerStart func(j *Job)
|
||||||
|
workerSem chan struct{}
|
||||||
|
onTerminal func(j *Job)
|
||||||
}
|
}
|
||||||
|
|
||||||
type idempoKey struct {
|
type idempoKey struct {
|
||||||
@@ -186,13 +190,44 @@ type idempoKey struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func NewRegistry(workerStart func(j *Job)) *Registry {
|
func NewRegistry(workerStart func(j *Job)) *Registry {
|
||||||
|
maxWorkers := registryMaxConcurrentJobs()
|
||||||
return &Registry{
|
return &Registry{
|
||||||
byID: make(map[string]*Job),
|
byID: make(map[string]*Job),
|
||||||
byIdempo: make(map[idempoKey]*Job),
|
byIdempo: make(map[idempoKey]*Job),
|
||||||
workerStart: workerStart,
|
workerStart: workerStart,
|
||||||
|
workerSem: make(chan struct{}, maxWorkers),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// SetTerminalHook registers a best-effort callback when jobs reach a terminal state.
|
||||||
|
func (r *Registry) SetTerminalHook(fn func(j *Job)) {
|
||||||
|
if r == nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
r.mu.Lock()
|
||||||
|
defer r.mu.Unlock()
|
||||||
|
r.onTerminal = fn
|
||||||
|
}
|
||||||
|
|
||||||
|
func (r *Registry) fireTerminal(j *Job) {
|
||||||
|
if r == nil || j == nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
r.mu.RLock()
|
||||||
|
fn := r.onTerminal
|
||||||
|
r.mu.RUnlock()
|
||||||
|
if fn != nil {
|
||||||
|
fn(j)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func registryMaxConcurrentJobs() int {
|
||||||
|
if n, err := strconv.Atoi(strings.TrimSpace(os.Getenv("EVOBGP_JOB_MAX_CONCURRENT"))); err == nil && n > 0 {
|
||||||
|
return n
|
||||||
|
}
|
||||||
|
return 8
|
||||||
|
}
|
||||||
|
|
||||||
// pruneTerminalIfOver удаляет самые старые завершённые джобы (succeeded/failed/cancelled), пока len(byID) > maxJobs.
|
// pruneTerminalIfOver удаляет самые старые завершённые джобы (succeeded/failed/cancelled), пока len(byID) > maxJobs.
|
||||||
func (r *Registry) pruneTerminalIfOver(maxJobs int) {
|
func (r *Registry) pruneTerminalIfOver(maxJobs int) {
|
||||||
if r == nil || maxJobs <= 0 || len(r.byID) <= maxJobs {
|
if r == nil || maxJobs <= 0 || len(r.byID) <= maxJobs {
|
||||||
@@ -244,7 +279,11 @@ func (r *Registry) Enqueue(tenantID, kind string, idempotencyKey *string, module
|
|||||||
if idempotencyKey != nil && *idempotencyKey != "" {
|
if idempotencyKey != nil && *idempotencyKey != "" {
|
||||||
k := idempoKey{tenant: tenantID, key: *idempotencyKey}
|
k := idempoKey{tenant: tenantID, key: *idempotencyKey}
|
||||||
if existing, ok := r.byIdempo[k]; ok {
|
if existing, ok := r.byIdempo[k]; ok {
|
||||||
return existing, false, nil
|
st := existing.statusLocked()
|
||||||
|
if st == StatusQueued || st == StatusRunning {
|
||||||
|
return existing, false, nil
|
||||||
|
}
|
||||||
|
delete(r.byIdempo, k)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -265,7 +304,17 @@ func (r *Registry) Enqueue(tenantID, kind string, idempotencyKey *string, module
|
|||||||
r.pruneTerminalIfOver(maxJobs)
|
r.pruneTerminalIfOver(maxJobs)
|
||||||
|
|
||||||
if r.workerStart != nil {
|
if r.workerStart != nil {
|
||||||
go r.workerStart(j)
|
go func() {
|
||||||
|
r.workerSem <- struct{}{}
|
||||||
|
active := len(r.workerSem)
|
||||||
|
capacity := cap(r.workerSem)
|
||||||
|
observability.RecordJobQueueDepth(active, capacity)
|
||||||
|
defer func() {
|
||||||
|
<-r.workerSem
|
||||||
|
observability.RecordJobQueueDepth(len(r.workerSem), capacity)
|
||||||
|
}()
|
||||||
|
r.workerStart(j)
|
||||||
|
}()
|
||||||
}
|
}
|
||||||
return j, true, nil
|
return j, true, nil
|
||||||
}
|
}
|
||||||
|
|||||||
+56
-8
@@ -82,6 +82,9 @@ func (w *Worker) httpClient() *http.Client {
|
|||||||
func (w *Worker) Process(j *Job) {
|
func (w *Worker) Process(j *Job) {
|
||||||
defer func() {
|
defer func() {
|
||||||
observability.RecordJobTerminal(j.Kind, j.statusLocked())
|
observability.RecordJobTerminal(j.Kind, j.statusLocked())
|
||||||
|
if w != nil && w.Registry != nil {
|
||||||
|
w.Registry.fireTerminal(j)
|
||||||
|
}
|
||||||
}()
|
}()
|
||||||
|
|
||||||
if w == nil || w.Store == nil {
|
if w == nil || w.Store == nil {
|
||||||
@@ -102,7 +105,17 @@ func (w *Worker) Process(j *Job) {
|
|||||||
j.Fail("missing module_id in job meta")
|
j.Fail("missing module_id in job meta")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
if err := pipeline.RefreshModuleIngest(context.Background(), w.Store, w.httpClient(), j.TenantID, mid); err != nil {
|
ctx, cancel := j.workContext()
|
||||||
|
defer cancel()
|
||||||
|
if ctx.Err() != nil {
|
||||||
|
j.MarkCancelled()
|
||||||
|
return
|
||||||
|
}
|
||||||
|
if err := pipeline.RefreshModuleIngest(ctx, w.Store, w.httpClient(), j.TenantID, mid); err != nil {
|
||||||
|
if ctx.Err() != nil {
|
||||||
|
j.MarkCancelled()
|
||||||
|
return
|
||||||
|
}
|
||||||
j.Fail(err.Error())
|
j.Fail(err.Error())
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
@@ -121,11 +134,17 @@ func (w *Worker) Process(j *Job) {
|
|||||||
j.Succeed()
|
j.Succeed()
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
ctx, cancel := j.workContext()
|
||||||
|
defer cancel()
|
||||||
ctl := &birdfmt.BirdCtl{
|
ctl := &birdfmt.BirdCtl{
|
||||||
Socket: sock,
|
Socket: sock,
|
||||||
Birdc: strings.TrimSpace(os.Getenv("EVOBGP_BIRDC_BIN")),
|
Birdc: strings.TrimSpace(os.Getenv("EVOBGP_BIRDC_BIN")),
|
||||||
}
|
}
|
||||||
if err := ctl.Configure(context.Background()); err != nil {
|
if err := ctl.Configure(ctx); err != nil {
|
||||||
|
if ctx.Err() != nil {
|
||||||
|
j.MarkCancelled()
|
||||||
|
return
|
||||||
|
}
|
||||||
j.Fail(err.Error())
|
j.Fail(err.Error())
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
@@ -152,9 +171,14 @@ func (w *Worker) runPeerReconcile(j *Job) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
if len(latest) == 0 {
|
if len(latest) == 0 {
|
||||||
// First run fallback: render full tenant state once if no baseline revision exists yet.
|
ctx, cancel := j.workContext()
|
||||||
rid, err := pipeline.RenderTenantRevision(context.Background(), w.Store, w.httpClient(), j.TenantID, triggerModuleID)
|
defer cancel()
|
||||||
|
rid, err := pipeline.RenderTenantRevision(ctx, w.Store, w.httpClient(), j.TenantID, triggerModuleID)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
if ctx.Err() != nil {
|
||||||
|
j.MarkCancelled()
|
||||||
|
return
|
||||||
|
}
|
||||||
j.Fail(err.Error())
|
j.Fail(err.Error())
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
@@ -171,8 +195,14 @@ func (w *Worker) runPeerReconcile(j *Job) {
|
|||||||
}
|
}
|
||||||
cursor = next
|
cursor = next
|
||||||
}
|
}
|
||||||
rid, err := pipeline.RenderTenantRevisionFromPrefixes(context.Background(), w.Store, w.httpClient(), j.TenantID, triggerModuleID, rows)
|
ctx, cancel := j.workContext()
|
||||||
|
defer cancel()
|
||||||
|
rid, err := pipeline.RenderTenantRevisionFromPrefixes(ctx, w.Store, w.httpClient(), j.TenantID, triggerModuleID, rows)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
if ctx.Err() != nil {
|
||||||
|
j.MarkCancelled()
|
||||||
|
return
|
||||||
|
}
|
||||||
j.Fail(err.Error())
|
j.Fail(err.Error())
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
@@ -230,7 +260,13 @@ func (w *Worker) runTenantRefresh(j *Job) {
|
|||||||
j.Fail("missing module_ids in job meta")
|
j.Fail("missing module_ids in job meta")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
if err := pipeline.RefreshTenantModules(context.Background(), w.Store, w.httpClient(), j.TenantID, moduleIDs); err != nil {
|
ctx, cancel := j.workContext()
|
||||||
|
defer cancel()
|
||||||
|
if err := pipeline.RefreshTenantModules(ctx, w.Store, w.httpClient(), j.TenantID, moduleIDs); err != nil {
|
||||||
|
if ctx.Err() != nil {
|
||||||
|
j.MarkCancelled()
|
||||||
|
return
|
||||||
|
}
|
||||||
j.Fail(err.Error())
|
j.Fail(err.Error())
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
@@ -275,6 +311,8 @@ func (w *Worker) finishModuleRefreshSuccess(j *Job, triggerModuleID string) {
|
|||||||
mu := w.tenantRefreshMu(j.TenantID)
|
mu := w.tenantRefreshMu(j.TenantID)
|
||||||
mu.Lock()
|
mu.Lock()
|
||||||
defer mu.Unlock()
|
defer mu.Unlock()
|
||||||
|
ctx, cancel := j.workContext()
|
||||||
|
defer cancel()
|
||||||
deferDeploy := false
|
deferDeploy := false
|
||||||
if w.Registry != nil {
|
if w.Registry != nil {
|
||||||
deferDeploy = w.Registry.CountOtherActiveRefresh(j.TenantID, j.ID) > 0
|
deferDeploy = w.Registry.CountOtherActiveRefresh(j.TenantID, j.ID) > 0
|
||||||
@@ -288,8 +326,12 @@ func (w *Worker) finishModuleRefreshSuccess(j *Job, triggerModuleID string) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
rev, err := pipeline.RenderTenantRevision(context.Background(), w.Store, w.httpClient(), j.TenantID, triggerModuleID)
|
rev, err := pipeline.RenderTenantRevision(ctx, w.Store, w.httpClient(), j.TenantID, triggerModuleID)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
if ctx.Err() != nil {
|
||||||
|
j.MarkCancelled()
|
||||||
|
return
|
||||||
|
}
|
||||||
j.Fail(err.Error())
|
j.Fail(err.Error())
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
@@ -335,6 +377,8 @@ func (w *Worker) runDeployApply(j *Job) {
|
|||||||
j.Fail("missing revision_id in job meta")
|
j.Fail("missing revision_id in job meta")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
ctx, cancel := j.workContext()
|
||||||
|
defer cancel()
|
||||||
activeDir := strings.TrimSpace(os.Getenv("EVOBGP_BIRD_ACTIVE_DIR"))
|
activeDir := strings.TrimSpace(os.Getenv("EVOBGP_BIRD_ACTIVE_DIR"))
|
||||||
if activeDir != "" {
|
if activeDir != "" {
|
||||||
revObj, err := w.Store.GetRevision(j.TenantID, revID)
|
revObj, err := w.Store.GetRevision(j.TenantID, revID)
|
||||||
@@ -354,7 +398,11 @@ func (w *Worker) runDeployApply(j *Job) {
|
|||||||
Socket: strings.TrimSpace(os.Getenv("EVOBGP_BIRDC_SOCKET")),
|
Socket: strings.TrimSpace(os.Getenv("EVOBGP_BIRDC_SOCKET")),
|
||||||
}
|
}
|
||||||
ctl := &birdfmt.BirdCtl{Bird: cfg.BirdBin, Birdc: cfg.BirdcBin, Socket: cfg.Socket}
|
ctl := &birdfmt.BirdCtl{Bird: cfg.BirdBin, Birdc: cfg.BirdcBin, Socket: cfg.Socket}
|
||||||
if err := birddeploy.ApplyRevision(context.Background(), ctl, revObj, cfg); err != nil {
|
if err := birddeploy.ApplyRevision(ctx, ctl, revObj, cfg); err != nil {
|
||||||
|
if ctx.Err() != nil {
|
||||||
|
j.MarkCancelled()
|
||||||
|
return
|
||||||
|
}
|
||||||
j.Fail(err.Error())
|
j.Fail(err.Error())
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,214 @@
|
|||||||
|
package nodecli
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
"crypto/ed25519"
|
||||||
|
"encoding/base64"
|
||||||
|
"encoding/json"
|
||||||
|
"flag"
|
||||||
|
"fmt"
|
||||||
|
"io"
|
||||||
|
"net/http"
|
||||||
|
"os"
|
||||||
|
"path/filepath"
|
||||||
|
"strings"
|
||||||
|
"time"
|
||||||
|
|
||||||
|
"evobgp/internal/birdfmt"
|
||||||
|
"evobgp/internal/bundle"
|
||||||
|
"evobgp/internal/signing"
|
||||||
|
)
|
||||||
|
|
||||||
|
// CmdPullBundle downloads a signed bundle from the control plane API.
|
||||||
|
func CmdPullBundle(args []string) int {
|
||||||
|
fs := flag.NewFlagSet("pull-bundle", flag.ExitOnError)
|
||||||
|
base := fs.String("base-url", "", "control plane base URL, e.g. http://localhost:8080")
|
||||||
|
token := fs.String("token", "", "Bearer token (node role)")
|
||||||
|
speaker := fs.String("speaker-id", "", "bgp_speaker id")
|
||||||
|
revision := fs.String("revision-id", "", "revision to fetch (empty = latest pointer)")
|
||||||
|
out := fs.String("o", "bundle.tar.gz", "output file")
|
||||||
|
_ = fs.Parse(args)
|
||||||
|
|
||||||
|
if strings.TrimSpace(*base) == "" || *token == "" || *speaker == "" {
|
||||||
|
fmt.Fprintln(os.Stderr, "pull-bundle: -base-url, -token, -speaker-id are required")
|
||||||
|
return 2
|
||||||
|
}
|
||||||
|
rev := strings.TrimSpace(*revision)
|
||||||
|
if rev == "" {
|
||||||
|
var err error
|
||||||
|
rev, err = fetchLatestRevision(*base, *token, *speaker)
|
||||||
|
if err != nil {
|
||||||
|
fmt.Fprintln(os.Stderr, err)
|
||||||
|
return 1
|
||||||
|
}
|
||||||
|
}
|
||||||
|
body, err := fetchBundle(*base, *token, *speaker, rev)
|
||||||
|
if err != nil {
|
||||||
|
fmt.Fprintln(os.Stderr, err)
|
||||||
|
return 1
|
||||||
|
}
|
||||||
|
if err := os.WriteFile(*out, body, 0o644); err != nil {
|
||||||
|
fmt.Fprintln(os.Stderr, err)
|
||||||
|
return 1
|
||||||
|
}
|
||||||
|
fmt.Fprintf(os.Stderr, "wrote %s (revision %s)\n", *out, rev)
|
||||||
|
return 0
|
||||||
|
}
|
||||||
|
|
||||||
|
func fetchLatestRevision(base, token, speaker string) (string, error) {
|
||||||
|
u := strings.TrimRight(base, "/") + "/v1/speakers/" + speaker + "/revisions/latest"
|
||||||
|
req, err := http.NewRequest(http.MethodGet, u, nil)
|
||||||
|
if err != nil {
|
||||||
|
return "", err
|
||||||
|
}
|
||||||
|
req.Header.Set("Authorization", "Bearer "+token)
|
||||||
|
resp, err := http.DefaultClient.Do(req)
|
||||||
|
if err != nil {
|
||||||
|
return "", err
|
||||||
|
}
|
||||||
|
defer func() { _ = resp.Body.Close() }()
|
||||||
|
if resp.StatusCode != http.StatusOK {
|
||||||
|
b, _ := io.ReadAll(resp.Body)
|
||||||
|
return "", fmt.Errorf("latest revision: %s: %s", resp.Status, strings.TrimSpace(string(b)))
|
||||||
|
}
|
||||||
|
var out struct {
|
||||||
|
RevisionID string `json:"revision_id"`
|
||||||
|
}
|
||||||
|
if err := json.NewDecoder(resp.Body).Decode(&out); err != nil {
|
||||||
|
return "", err
|
||||||
|
}
|
||||||
|
if out.RevisionID == "" {
|
||||||
|
return "", fmt.Errorf("empty revision_id in response")
|
||||||
|
}
|
||||||
|
return out.RevisionID, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func fetchBundle(base, token, speaker, revision string) ([]byte, error) {
|
||||||
|
u := strings.TrimRight(base, "/") + "/v1/speakers/" + speaker + "/bundle/" + revision
|
||||||
|
req, err := http.NewRequest(http.MethodGet, u, nil)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
req.Header.Set("Authorization", "Bearer "+token)
|
||||||
|
resp, err := http.DefaultClient.Do(req)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
defer func() { _ = resp.Body.Close() }()
|
||||||
|
if resp.StatusCode != http.StatusOK {
|
||||||
|
b, _ := io.ReadAll(resp.Body)
|
||||||
|
return nil, fmt.Errorf("bundle: %s: %s", resp.Status, strings.TrimSpace(string(b)))
|
||||||
|
}
|
||||||
|
return io.ReadAll(resp.Body)
|
||||||
|
}
|
||||||
|
|
||||||
|
func loadPubKey(pubB64, pubHex string) (ed25519.PublicKey, error) {
|
||||||
|
switch {
|
||||||
|
case strings.TrimSpace(pubB64) != "":
|
||||||
|
raw, err := base64.StdEncoding.DecodeString(strings.TrimSpace(pubB64))
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
if len(raw) != ed25519.PublicKeySize {
|
||||||
|
return nil, fmt.Errorf("pubkey-base64 must decode to %d bytes", ed25519.PublicKeySize)
|
||||||
|
}
|
||||||
|
return ed25519.PublicKey(raw), nil
|
||||||
|
case strings.TrimSpace(pubHex) != "":
|
||||||
|
return bundle.ParsePublicKeyHex(pubHex)
|
||||||
|
default:
|
||||||
|
return nil, fmt.Errorf("public key required")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// CmdVerifyBundle checks bundle signature and manifest.
|
||||||
|
func CmdVerifyBundle(args []string) int {
|
||||||
|
fs := flag.NewFlagSet("verify-bundle", flag.ExitOnError)
|
||||||
|
path := fs.String("f", "", "path to bundle.tar.gz")
|
||||||
|
pubB64 := fs.String("pubkey-base64", "", "Ed25519 public key (base64)")
|
||||||
|
pubHex := fs.String("pubkey-hex", "", "Ed25519 public key (64 hex chars)")
|
||||||
|
_ = fs.Parse(args)
|
||||||
|
|
||||||
|
if *path == "" {
|
||||||
|
fmt.Fprintln(os.Stderr, "verify-bundle: -f required")
|
||||||
|
return 2
|
||||||
|
}
|
||||||
|
pub, err := loadPubKey(*pubB64, *pubHex)
|
||||||
|
if err != nil {
|
||||||
|
fmt.Fprintln(os.Stderr, err)
|
||||||
|
return 2
|
||||||
|
}
|
||||||
|
raw, err := os.ReadFile(*path)
|
||||||
|
if err != nil {
|
||||||
|
fmt.Fprintln(os.Stderr, err)
|
||||||
|
return 1
|
||||||
|
}
|
||||||
|
v, err := signing.VerifyGzippedTar(raw, pub)
|
||||||
|
if err != nil {
|
||||||
|
fmt.Fprintln(os.Stderr, err)
|
||||||
|
return 1
|
||||||
|
}
|
||||||
|
fmt.Fprintf(os.Stderr, "ok: revision %s, %d payload files\n", v.Manifest.RevisionID, len(v.Files))
|
||||||
|
return 0
|
||||||
|
}
|
||||||
|
|
||||||
|
// CmdApplyBundle verifies, extracts, parse-checks, and configures BIRD from a bundle.
|
||||||
|
func CmdApplyBundle(args []string) int {
|
||||||
|
fs := flag.NewFlagSet("apply-bundle", flag.ExitOnError)
|
||||||
|
path := fs.String("f", "", "path to bundle.tar.gz")
|
||||||
|
dir := fs.String("extract-dir", "", "directory to extract into")
|
||||||
|
pubB64 := fs.String("pubkey-base64", "", "Ed25519 public key (base64)")
|
||||||
|
pubHex := fs.String("pubkey-hex", "", "Ed25519 public key (64 hex chars)")
|
||||||
|
bird := fs.String("bird", "", "bird binary (default PATH)")
|
||||||
|
birdc := fs.String("birdc", "", "birdc binary (default PATH)")
|
||||||
|
socket := fs.String("socket", "", "birdc -s socket path")
|
||||||
|
timeout := fs.Duration("timeout", 30*time.Second, "timeout for bird/birdc")
|
||||||
|
_ = fs.Parse(args)
|
||||||
|
|
||||||
|
if *path == "" || *dir == "" {
|
||||||
|
fmt.Fprintln(os.Stderr, "apply-bundle: -f and -extract-dir required")
|
||||||
|
return 2
|
||||||
|
}
|
||||||
|
pub, err := loadPubKey(*pubB64, *pubHex)
|
||||||
|
if err != nil {
|
||||||
|
fmt.Fprintln(os.Stderr, err)
|
||||||
|
return 2
|
||||||
|
}
|
||||||
|
raw, err := os.ReadFile(*path)
|
||||||
|
if err != nil {
|
||||||
|
fmt.Fprintln(os.Stderr, err)
|
||||||
|
return 1
|
||||||
|
}
|
||||||
|
v, err := signing.VerifyGzippedTar(raw, pub)
|
||||||
|
if err != nil {
|
||||||
|
fmt.Fprintln(os.Stderr, err)
|
||||||
|
return 1
|
||||||
|
}
|
||||||
|
root := filepath.Clean(*dir)
|
||||||
|
if err := os.MkdirAll(root, 0o755); err != nil {
|
||||||
|
fmt.Fprintln(os.Stderr, err)
|
||||||
|
return 1
|
||||||
|
}
|
||||||
|
if err := bundle.WriteExtractedFiles(root, v); err != nil {
|
||||||
|
fmt.Fprintln(os.Stderr, err)
|
||||||
|
return 1
|
||||||
|
}
|
||||||
|
mainRel := v.FindMainBirdConf()
|
||||||
|
if mainRel == "" {
|
||||||
|
fmt.Fprintln(os.Stderr, "bundle has no bird.conf path in manifest")
|
||||||
|
return 1
|
||||||
|
}
|
||||||
|
mainPath := filepath.Join(root, filepath.FromSlash(strings.TrimPrefix(mainRel, "/")))
|
||||||
|
ctx, cancel := context.WithTimeout(context.Background(), *timeout)
|
||||||
|
defer cancel()
|
||||||
|
ctl := &birdfmt.BirdCtl{Bird: *bird, Birdc: *birdc, Socket: *socket}
|
||||||
|
if err := ctl.ParseCheck(ctx, mainPath); err != nil {
|
||||||
|
fmt.Fprintln(os.Stderr, err)
|
||||||
|
return 1
|
||||||
|
}
|
||||||
|
if err := ctl.Configure(ctx); err != nil {
|
||||||
|
fmt.Fprintln(os.Stderr, err)
|
||||||
|
return 1
|
||||||
|
}
|
||||||
|
fmt.Fprintf(os.Stderr, "applied revision %s (main config %s)\n", v.Manifest.RevisionID, mainPath)
|
||||||
|
return 0
|
||||||
|
}
|
||||||
@@ -0,0 +1,38 @@
|
|||||||
|
// Package nodecli implements evobgp-node subcommands (pull/verify/apply bundle).
|
||||||
|
package nodecli
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
"os"
|
||||||
|
)
|
||||||
|
|
||||||
|
// Run executes a subcommand from args (without program name). Returns exit code.
|
||||||
|
func Run(args []string) int {
|
||||||
|
if len(args) < 1 {
|
||||||
|
Usage(os.Stderr)
|
||||||
|
return 2
|
||||||
|
}
|
||||||
|
switch args[0] {
|
||||||
|
case "pull-bundle":
|
||||||
|
return CmdPullBundle(args[1:])
|
||||||
|
case "verify-bundle":
|
||||||
|
return CmdVerifyBundle(args[1:])
|
||||||
|
case "apply-bundle":
|
||||||
|
return CmdApplyBundle(args[1:])
|
||||||
|
default:
|
||||||
|
Usage(os.Stderr)
|
||||||
|
return 2
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Usage prints CLI help to w.
|
||||||
|
func Usage(w interface{ Write([]byte) (int, error) }) {
|
||||||
|
_, _ = fmt.Fprintf(w, `Usage:
|
||||||
|
evobgp-node pull-bundle -base-url URL -token TOKEN -speaker-id ID [-revision-id ID] [-o path]
|
||||||
|
evobgp-node verify-bundle -f bundle.tar.gz (-pubkey-base64 B64 | -pubkey-hex HEX)
|
||||||
|
evobgp-node apply-bundle -f bundle.tar.gz -extract-dir DIR (-pubkey-base64 B64 | -pubkey-hex HEX)
|
||||||
|
[-bird PATH] [-birdc PATH] [-socket PATH] [-timeout DURATION]
|
||||||
|
|
||||||
|
apply-bundle verifies, extracts, runs bird -p on main bird.conf, then birdc configure.
|
||||||
|
`)
|
||||||
|
}
|
||||||
@@ -80,6 +80,38 @@ var (
|
|||||||
Help: "Prefix row count after CIDR aggregation on tenant render.",
|
Help: "Prefix row count after CIDR aggregation on tenant render.",
|
||||||
Buckets: prometheus.ExponentialBuckets(1, 2, 16),
|
Buckets: prometheus.ExponentialBuckets(1, 2, 16),
|
||||||
})
|
})
|
||||||
|
|
||||||
|
pipelineRefreshDuration = promauto.NewHistogramVec(prometheus.HistogramOpts{
|
||||||
|
Namespace: namespace,
|
||||||
|
Name: "pipeline_refresh_duration_seconds",
|
||||||
|
Help: "Module refresh ingest duration by module type.",
|
||||||
|
Buckets: prometheus.ExponentialBuckets(0.05, 2, 14),
|
||||||
|
}, []string{"module_type"})
|
||||||
|
|
||||||
|
renderPrefixCount = promauto.NewHistogram(prometheus.HistogramOpts{
|
||||||
|
Namespace: namespace,
|
||||||
|
Name: "render_prefix_count",
|
||||||
|
Help: "Materialized prefix count per tenant render.",
|
||||||
|
Buckets: prometheus.ExponentialBuckets(10, 2, 16),
|
||||||
|
})
|
||||||
|
|
||||||
|
jobQueueActive = promauto.NewGauge(prometheus.GaugeOpts{
|
||||||
|
Namespace: namespace,
|
||||||
|
Name: "job_queue_active",
|
||||||
|
Help: "Currently running in-process async jobs.",
|
||||||
|
})
|
||||||
|
|
||||||
|
jobQueueCapacity = promauto.NewGauge(prometheus.GaugeOpts{
|
||||||
|
Namespace: namespace,
|
||||||
|
Name: "job_queue_capacity",
|
||||||
|
Help: "Maximum concurrent in-process async jobs.",
|
||||||
|
})
|
||||||
|
)
|
||||||
|
|
||||||
|
var (
|
||||||
|
birdProtocolStatesMu sync.RWMutex
|
||||||
|
birdProtocolStates map[string]string
|
||||||
|
birdProtocolStatesAt time.Time
|
||||||
)
|
)
|
||||||
|
|
||||||
// RecordPrefixAggregation records tenant render CIDR aggregation stats.
|
// RecordPrefixAggregation records tenant render CIDR aggregation stats.
|
||||||
@@ -93,6 +125,27 @@ func RecordPrefixAggregation(rawCount, aggregatedCount int, duration time.Durati
|
|||||||
prefixAggregationDuration.Observe(duration.Seconds())
|
prefixAggregationDuration.Observe(duration.Seconds())
|
||||||
prefixAggregationRawCount.Observe(float64(rawCount))
|
prefixAggregationRawCount.Observe(float64(rawCount))
|
||||||
prefixAggregationAggregatedCount.Observe(float64(aggregatedCount))
|
prefixAggregationAggregatedCount.Observe(float64(aggregatedCount))
|
||||||
|
renderPrefixCount.Observe(float64(aggregatedCount))
|
||||||
|
}
|
||||||
|
|
||||||
|
// RecordPipelineRefresh records module ingest duration.
|
||||||
|
func RecordPipelineRefresh(moduleType string, duration time.Duration) {
|
||||||
|
if moduleType == "" {
|
||||||
|
moduleType = "unknown"
|
||||||
|
}
|
||||||
|
pipelineRefreshDuration.WithLabelValues(moduleType).Observe(duration.Seconds())
|
||||||
|
}
|
||||||
|
|
||||||
|
// RecordJobQueueDepth updates in-process job worker utilization gauges.
|
||||||
|
func RecordJobQueueDepth(active, capacity int) {
|
||||||
|
if active < 0 {
|
||||||
|
active = 0
|
||||||
|
}
|
||||||
|
if capacity < 0 {
|
||||||
|
capacity = 0
|
||||||
|
}
|
||||||
|
jobQueueActive.Set(float64(active))
|
||||||
|
jobQueueCapacity.Set(float64(capacity))
|
||||||
}
|
}
|
||||||
|
|
||||||
// RecordJobTerminal increments jobs_finished_total for terminal statuses.
|
// RecordJobTerminal increments jobs_finished_total for terminal statuses.
|
||||||
@@ -205,6 +258,35 @@ func SetBirdSessionMetrics(established int, scrapeOK bool) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// SetBirdProtocolStates caches parsed BGP protocol states from the last birdc scrape.
|
||||||
|
func SetBirdProtocolStates(states map[string]string) {
|
||||||
|
birdProtocolStatesMu.Lock()
|
||||||
|
defer birdProtocolStatesMu.Unlock()
|
||||||
|
if states == nil {
|
||||||
|
birdProtocolStates = map[string]string{}
|
||||||
|
} else {
|
||||||
|
birdProtocolStates = states
|
||||||
|
}
|
||||||
|
birdProtocolStatesAt = time.Now()
|
||||||
|
}
|
||||||
|
|
||||||
|
// CachedBirdProtocolStates returns cached protocol states if younger than maxAge.
|
||||||
|
func CachedBirdProtocolStates(maxAge time.Duration) (map[string]string, bool) {
|
||||||
|
if maxAge <= 0 {
|
||||||
|
maxAge = 60 * time.Second
|
||||||
|
}
|
||||||
|
birdProtocolStatesMu.RLock()
|
||||||
|
defer birdProtocolStatesMu.RUnlock()
|
||||||
|
if birdProtocolStates == nil || time.Since(birdProtocolStatesAt) > maxAge {
|
||||||
|
return nil, false
|
||||||
|
}
|
||||||
|
out := make(map[string]string, len(birdProtocolStates))
|
||||||
|
for k, v := range birdProtocolStates {
|
||||||
|
out[k] = v
|
||||||
|
}
|
||||||
|
return out, true
|
||||||
|
}
|
||||||
|
|
||||||
// MetricsHandler returns the Prometheus scrape handler.
|
// MetricsHandler returns the Prometheus scrape handler.
|
||||||
func MetricsHandler() http.Handler {
|
func MetricsHandler() http.Handler {
|
||||||
return promhttp.HandlerFor(prometheus.DefaultGatherer, promhttp.HandlerOpts{})
|
return promhttp.HandlerFor(prometheus.DefaultGatherer, promhttp.HandlerOpts{})
|
||||||
@@ -231,7 +313,7 @@ func (s *statusRecorder) WriteHeader(code int) {
|
|||||||
|
|
||||||
// StartBirdProtocolsPoller runs birdc "show protocols" on interval when socket is non-empty.
|
// StartBirdProtocolsPoller runs birdc "show protocols" on interval when socket is non-empty.
|
||||||
// Горутина завершается при отмене ctx (корректное завершение вместе с процессом API).
|
// Горутина завершается при отмене ctx (корректное завершение вместе с процессом API).
|
||||||
func StartBirdProtocolsPoller(ctx context.Context, socket string, birdcPath string, interval time.Duration, showFn func(ctx context.Context, socket, birdcBin string) (string, error), countFn func(output string) int) {
|
func StartBirdProtocolsPoller(ctx context.Context, socket string, birdcPath string, interval time.Duration, showFn func(ctx context.Context, socket, birdcBin string) (string, error), countFn func(output string) int, parseFn func(output string) map[string]string) {
|
||||||
socket = trimSpace(socket)
|
socket = trimSpace(socket)
|
||||||
if ctx == nil || socket == "" || interval <= 0 || showFn == nil || countFn == nil {
|
if ctx == nil || socket == "" || interval <= 0 || showFn == nil || countFn == nil {
|
||||||
return
|
return
|
||||||
@@ -245,6 +327,9 @@ func StartBirdProtocolsPoller(ctx context.Context, socket string, birdcPath stri
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
SetBirdSessionMetrics(countFn(out), true)
|
SetBirdSessionMetrics(countFn(out), true)
|
||||||
|
if parseFn != nil {
|
||||||
|
SetBirdProtocolStates(parseFn(out))
|
||||||
|
}
|
||||||
}
|
}
|
||||||
go func() {
|
go func() {
|
||||||
scrape()
|
scrape()
|
||||||
|
|||||||
@@ -44,6 +44,7 @@ func resolveASNForEntry(ctx context.Context, st store.Backend, hc *http.Client,
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, "", err
|
return nil, "", err
|
||||||
}
|
}
|
||||||
|
asnresolve.PolitePause()
|
||||||
holder, _ := asnresolve.ASHolderName(ctx, hc, asn)
|
holder, _ := asnresolve.ASHolderName(ctx, hc, asn)
|
||||||
if st != nil {
|
if st != nil {
|
||||||
strs := make([]string, len(pfxs))
|
strs := make([]string, len(pfxs))
|
||||||
|
|||||||
@@ -25,9 +25,6 @@ func cachedCDNPrefixRows(st store.Backend, tenantID, moduleID string, priorSnaps
|
|||||||
return cached
|
return cached
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if cached := latestCDNRowsBySource(st, tenantID)[sourceKey]; len(cached) > 0 {
|
|
||||||
return cached
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
@@ -45,6 +42,35 @@ func mergeSnapshotDropSource(rows []store.PrefixRow, sourceKey string) []store.P
|
|||||||
return out
|
return out
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// mergeSnapshotDropCDNSources removes all cdn:* rows (used before batch CDN merge).
|
||||||
|
func mergeSnapshotDropCDNSources(rows []store.PrefixRow) []store.PrefixRow {
|
||||||
|
if len(rows) == 0 {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
out := make([]store.PrefixRow, 0, len(rows))
|
||||||
|
for _, row := range rows {
|
||||||
|
if !strings.HasPrefix(strings.TrimSpace(row.Source), "cdn:") {
|
||||||
|
out = append(out, row)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return out
|
||||||
|
}
|
||||||
|
|
||||||
|
// mergeAllCDNSourcesIntoModuleSnapshot replaces all CDN rows in one write (avoids parallel read-modify-write races).
|
||||||
|
func mergeAllCDNSourcesIntoModuleSnapshot(st store.Backend, tenantID string, mod *store.Module, priorSnapshot []store.PrefixRow, cdnRows []store.PrefixRow) error {
|
||||||
|
if st == nil || mod == nil {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
var base []store.PrefixRow
|
||||||
|
if len(priorSnapshot) > 0 {
|
||||||
|
base = mergeSnapshotDropCDNSources(priorSnapshot)
|
||||||
|
} else if snap, ok, _ := st.GetModulePrefixSnapshot(tenantID, mod.ID); ok && snap != nil {
|
||||||
|
base = mergeSnapshotDropCDNSources(snap.Prefixes)
|
||||||
|
}
|
||||||
|
merged := append(base, cdnRows...)
|
||||||
|
return persistModuleSnapshot(st, tenantID, mod, merged)
|
||||||
|
}
|
||||||
|
|
||||||
func cdnRowsFromParsed(mod *store.Module, src *store.CDNSource, pfxStrings []string) []store.PrefixRow {
|
func cdnRowsFromParsed(mod *store.Module, src *store.CDNSource, pfxStrings []string) []store.PrefixRow {
|
||||||
var rows []store.PrefixRow
|
var rows []store.PrefixRow
|
||||||
for _, p := range pfxStrings {
|
for _, p := range pfxStrings {
|
||||||
@@ -126,7 +152,7 @@ func applyCDNSourceHTTPResult(ctx context.Context, st store.Backend, hc *http.Cl
|
|||||||
return nil, fmt.Errorf("cdn url %s: 304 without cached prefixes", u)
|
return nil, fmt.Errorf("cdn url %s: 304 without cached prefixes", u)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
defer resp.Body.Close()
|
defer func() { _ = resp.Body.Close() }()
|
||||||
|
|
||||||
if resp.StatusCode != http.StatusOK {
|
if resp.StatusCode != http.StatusOK {
|
||||||
_, _ = io.Copy(io.Discard, resp.Body)
|
_, _ = io.Copy(io.Discard, resp.Body)
|
||||||
@@ -156,3 +182,68 @@ func applyCDNSourceHTTPResult(ctx context.Context, st store.Backend, hc *http.Cl
|
|||||||
}
|
}
|
||||||
return rows, nil
|
return rows, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// fetchCDNSourceRows loads CDN prefixes without persisting the module snapshot (caller merges once).
|
||||||
|
func fetchCDNSourceRows(ctx context.Context, st store.Backend, hc *http.Client, tenantID, moduleID string, mod *store.Module, src *store.CDNSource, priorSnapshot []store.PrefixRow, now time.Time) ([]store.PrefixRow, error) {
|
||||||
|
u := strings.TrimSpace(src.URL)
|
||||||
|
if u == "" {
|
||||||
|
return nil, nil
|
||||||
|
}
|
||||||
|
sourceKey := cdnSourceKey(src.ID)
|
||||||
|
req, err := http.NewRequestWithContext(ctx, http.MethodGet, u, nil)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
if etag := strings.TrimSpace(src.Etag); etag != "" {
|
||||||
|
req.Header.Set("If-None-Match", etag)
|
||||||
|
}
|
||||||
|
resp, err := hc.Do(req)
|
||||||
|
if err != nil {
|
||||||
|
return nil, fmt.Errorf("cdn fetch %s: %w", u, err)
|
||||||
|
}
|
||||||
|
|
||||||
|
if resp.StatusCode == http.StatusNotModified {
|
||||||
|
if cached := cachedCDNPrefixRows(st, tenantID, moduleID, priorSnapshot, sourceKey); len(cached) > 0 {
|
||||||
|
_ = resp.Body.Close()
|
||||||
|
return cached, nil
|
||||||
|
}
|
||||||
|
_ = resp.Body.Close()
|
||||||
|
req2, err := http.NewRequestWithContext(ctx, http.MethodGet, u, nil)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
resp, err = hc.Do(req2)
|
||||||
|
if err != nil {
|
||||||
|
return nil, fmt.Errorf("cdn fetch %s: %w", u, err)
|
||||||
|
}
|
||||||
|
if resp.StatusCode == http.StatusNotModified {
|
||||||
|
_ = resp.Body.Close()
|
||||||
|
return nil, fmt.Errorf("cdn url %s: 304 without cached prefixes", u)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
defer func() { _ = resp.Body.Close() }()
|
||||||
|
|
||||||
|
if resp.StatusCode != http.StatusOK {
|
||||||
|
_, _ = io.Copy(io.Discard, resp.Body)
|
||||||
|
return nil, fmt.Errorf("cdn url %s: %s", u, resp.Status)
|
||||||
|
}
|
||||||
|
body, err := io.ReadAll(io.LimitReader(resp.Body, 8<<20))
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
prefixStrs, err := parseCDNBody(string(body), src)
|
||||||
|
if err != nil {
|
||||||
|
return nil, fmt.Errorf("cdn parse %s: %w", u, err)
|
||||||
|
}
|
||||||
|
etag := strings.TrimSpace(resp.Header.Get("ETag"))
|
||||||
|
patch := &store.CDNSourcePatch{}
|
||||||
|
if etag != "" && etag != strings.TrimSpace(src.Etag) {
|
||||||
|
e := etag
|
||||||
|
patch.Etag = &e
|
||||||
|
}
|
||||||
|
refreshedAt := now
|
||||||
|
patch.LastRefreshedAt = &refreshedAt
|
||||||
|
_, _ = st.UpdateCDNSource(tenantID, moduleID, src.ID, patch)
|
||||||
|
|
||||||
|
return cdnRowsFromParsed(mod, src, prefixStrs), nil
|
||||||
|
}
|
||||||
@@ -97,15 +97,18 @@ func collectASPrefixRows(ctx context.Context, st store.Backend, hc *http.Client,
|
|||||||
|
|
||||||
seenPfx := make(map[string]struct{})
|
seenPfx := make(map[string]struct{})
|
||||||
var out []store.PrefixRow
|
var out []store.PrefixRow
|
||||||
|
var metaUpdates []store.ASEntryResolveMetaUpdate
|
||||||
now := time.Now().UTC()
|
now := time.Now().UTC()
|
||||||
for _, r := range results {
|
for _, r := range results {
|
||||||
if r.err != nil {
|
if r.err != nil {
|
||||||
return nil, r.err
|
return nil, r.err
|
||||||
}
|
}
|
||||||
if r.metaID != "" {
|
if r.metaID != "" {
|
||||||
if err := st.UpdateASEntryResolveMeta(tenantID, moduleID, r.metaID, r.holder, r.count, now); err != nil {
|
metaUpdates = append(metaUpdates, store.ASEntryResolveMetaUpdate{
|
||||||
return nil, fmt.Errorf("as entry meta AS%d: %w", r.asn, err)
|
EntryID: r.metaID,
|
||||||
}
|
ASNName: r.holder,
|
||||||
|
PrefixCount: r.count,
|
||||||
|
})
|
||||||
}
|
}
|
||||||
for _, row := range r.rows {
|
for _, row := range r.rows {
|
||||||
k := row.Prefix
|
k := row.Prefix
|
||||||
@@ -116,6 +119,11 @@ func collectASPrefixRows(ctx context.Context, st store.Backend, hc *http.Client,
|
|||||||
out = append(out, row)
|
out = append(out, row)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if len(metaUpdates) > 0 {
|
||||||
|
if err := st.UpdateASEntryResolveMetaBatch(tenantID, moduleID, metaUpdates, now); err != nil {
|
||||||
|
return nil, fmt.Errorf("as entry meta batch: %w", err)
|
||||||
|
}
|
||||||
|
}
|
||||||
return out, nil
|
return out, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -150,12 +158,14 @@ func collectCDNPrefixRows(ctx context.Context, st store.Backend, hc *http.Client
|
|||||||
results[idx] = srcResult{rows: cached}
|
results[idx] = srcResult{rows: cached}
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
if cached := latestCDNRowsBySource(st, tenantID)[sourceKey]; len(cached) > 0 {
|
if snap, ok, _ := st.GetModulePrefixSnapshot(tenantID, moduleID); ok && snap != nil {
|
||||||
results[idx] = srcResult{rows: cached}
|
if cached := prefixRowsForSource(snap.Prefixes, sourceKey); len(cached) > 0 {
|
||||||
return
|
results[idx] = srcResult{rows: cached}
|
||||||
|
return
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
rows, err := applyCDNSourceHTTPResult(ctx, st, hc, tenantID, moduleID, mod, src, priorSnapshot, now)
|
rows, err := fetchCDNSourceRows(ctx, st, hc, tenantID, moduleID, mod, src, priorSnapshot, now)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
results[idx] = srcResult{err: err}
|
results[idx] = srcResult{err: err}
|
||||||
return
|
return
|
||||||
@@ -172,6 +182,11 @@ func collectCDNPrefixRows(ctx context.Context, st store.Backend, hc *http.Client
|
|||||||
}
|
}
|
||||||
out = append(out, r.rows...)
|
out = append(out, r.rows...)
|
||||||
}
|
}
|
||||||
|
if len(valid) > 0 {
|
||||||
|
if err := mergeAllCDNSourcesIntoModuleSnapshot(st, tenantID, mod, priorSnapshot, out); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
}
|
||||||
return out, nil
|
return out, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,3 @@
|
|||||||
|
// Package pipeline ingests module inputs (CDN, ASN, domains, IP ranges), materializes
|
||||||
|
// prefixes, and creates BIRD preview revisions via store.
|
||||||
|
package pipeline
|
||||||
@@ -46,4 +46,3 @@ func TestBuildPreviewFragments_SamePrefixDifferentCommunity(t *testing.T) {
|
|||||||
t.Fatalf("expected deterministic static preview text, got first:\n%s\nsecond:\n%s", staticV4, staticV4Second)
|
t.Fatalf("expected deterministic static preview text, got first:\n%s\nsecond:\n%s", staticV4, staticV4Second)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -13,7 +13,7 @@ import (
|
|||||||
// moduleIngestInputHash fingerprints module config and child entries so snapshots invalidate on CRUD.
|
// moduleIngestInputHash fingerprints module config and child entries so snapshots invalidate on CRUD.
|
||||||
func moduleIngestInputHash(st store.Backend, tenantID string, mod *store.Module) (string, error) {
|
func moduleIngestInputHash(st store.Backend, tenantID string, mod *store.Module) (string, error) {
|
||||||
if st == nil || mod == nil {
|
if st == nil || mod == nil {
|
||||||
return "", fmt.Errorf("module hash: missing store or module")
|
return "", fmt.Errorf("pipeline: module hash: missing store or module")
|
||||||
}
|
}
|
||||||
h := sha256.New()
|
h := sha256.New()
|
||||||
_, _ = fmt.Fprintf(h, "type=%s\n", strings.TrimSpace(mod.Type))
|
_, _ = fmt.Fprintf(h, "type=%s\n", strings.TrimSpace(mod.Type))
|
||||||
|
|||||||
@@ -39,7 +39,7 @@ func ParseCIDRLines(body string) []netip.Prefix {
|
|||||||
return out
|
return out
|
||||||
}
|
}
|
||||||
|
|
||||||
// ExtractCIDRs parses CIDRs from either plaintext lines or JSON payload.
|
// ExtractCIDRs parses CIDR prefixes from plaintext lines or a JSON payload (see sourceKind and prefixPath).
|
||||||
// For sourceKind="json", prefixPath supports dotted traversal, with [] for arrays:
|
// For sourceKind="json", prefixPath supports dotted traversal, with [] for arrays:
|
||||||
// e.g. "prefixes[]", "data.items[].cidr".
|
// e.g. "prefixes[]", "data.items[].cidr".
|
||||||
func ExtractCIDRs(body, sourceKind, prefixPath string) ([]netip.Prefix, error) {
|
func ExtractCIDRs(body, sourceKind, prefixPath string) ([]netip.Prefix, error) {
|
||||||
|
|||||||
@@ -36,6 +36,11 @@ const (
|
|||||||
revisionDefaultTTL = 30 * 24 * time.Hour
|
revisionDefaultTTL = 30 * 24 * time.Hour
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// AuxBirdFullExpandedKey returns the preview map key for the expanded BIRD config (generated on demand).
|
||||||
|
func AuxBirdFullExpandedKey() string {
|
||||||
|
return auxBirdFullExpanded
|
||||||
|
}
|
||||||
|
|
||||||
// MaterializedASPrefixKey returns the revision snapshot key for an AS-only entry (not a CIDR).
|
// MaterializedASPrefixKey returns the revision snapshot key for an AS-only entry (not a CIDR).
|
||||||
func MaterializedASPrefixKey(asn int64) string {
|
func MaterializedASPrefixKey(asn int64) string {
|
||||||
return fmt.Sprintf("as:%d", asn)
|
return fmt.Sprintf("as:%d", asn)
|
||||||
@@ -47,12 +52,16 @@ func RefreshModuleIngest(ctx context.Context, st store.Backend, hc *http.Client,
|
|||||||
if hc == nil {
|
if hc == nil {
|
||||||
hc = http.DefaultClient
|
hc = http.DefaultClient
|
||||||
}
|
}
|
||||||
|
start := time.Now()
|
||||||
mod, err := st.GetModule(tenantID, moduleID)
|
mod, err := st.GetModule(tenantID, moduleID)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
defer func() {
|
||||||
|
observability.RecordPipelineRefresh(mod.Type, time.Since(start))
|
||||||
|
}()
|
||||||
if !mod.Enabled {
|
if !mod.Enabled {
|
||||||
return fmt.Errorf("module disabled")
|
return fmt.Errorf("pipeline: module disabled")
|
||||||
}
|
}
|
||||||
|
|
||||||
var prior []store.PrefixRow
|
var prior []store.PrefixRow
|
||||||
@@ -185,7 +194,7 @@ func collectModulePrefixRows(ctx context.Context, st store.Backend, hc *http.Cli
|
|||||||
}
|
}
|
||||||
return collectDomainPrefixRows(ctx, hc, mod, profiles, policy, entries)
|
return collectDomainPrefixRows(ctx, hc, mod, profiles, policy, entries)
|
||||||
default:
|
default:
|
||||||
return nil, fmt.Errorf("unknown module type %q", mod.Type)
|
return nil, fmt.Errorf("pipeline: unknown module type %q", mod.Type)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -197,33 +206,6 @@ func shouldSkipCDNSourceFetch(src *store.CDNSource, now time.Time) bool {
|
|||||||
return now.UTC().Before(nextRefreshAt)
|
return now.UTC().Before(nextRefreshAt)
|
||||||
}
|
}
|
||||||
|
|
||||||
func latestCDNRowsBySource(st store.Backend, tenantID string) map[string][]store.PrefixRow {
|
|
||||||
out := make(map[string][]store.PrefixRow)
|
|
||||||
if st == nil {
|
|
||||||
return out
|
|
||||||
}
|
|
||||||
revs, _, _ := st.ListRevisions(tenantID, "", "", 1)
|
|
||||||
if len(revs) == 0 || strings.TrimSpace(revs[0].ID) == "" {
|
|
||||||
return out
|
|
||||||
}
|
|
||||||
revID := strings.TrimSpace(revs[0].ID)
|
|
||||||
cursor := ""
|
|
||||||
for {
|
|
||||||
page, next, more := st.ListRevisionPrefixes(tenantID, revID, cursor, 2000)
|
|
||||||
for _, row := range page {
|
|
||||||
if !strings.HasPrefix(strings.TrimSpace(row.Source), "cdn:") {
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
out[row.Source] = append(out[row.Source], row)
|
|
||||||
}
|
|
||||||
if !more || strings.TrimSpace(next) == "" {
|
|
||||||
break
|
|
||||||
}
|
|
||||||
cursor = next
|
|
||||||
}
|
|
||||||
return out
|
|
||||||
}
|
|
||||||
|
|
||||||
type dohJSONAnswer struct {
|
type dohJSONAnswer struct {
|
||||||
Type int `json:"type"`
|
Type int `json:"type"`
|
||||||
Data string `json:"data"`
|
Data string `json:"data"`
|
||||||
@@ -306,7 +288,7 @@ func resolveDomainWithDOHMessage(ctx context.Context, hc *http.Client, baseURL,
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
defer resp.Body.Close()
|
defer func() { _ = resp.Body.Close() }()
|
||||||
if resp.StatusCode != http.StatusOK {
|
if resp.StatusCode != http.StatusOK {
|
||||||
body, _ := io.ReadAll(io.LimitReader(resp.Body, 1024))
|
body, _ := io.ReadAll(io.LimitReader(resp.Body, 1024))
|
||||||
return nil, fmt.Errorf("doh dns-message status %s: %s", resp.Status, strings.TrimSpace(string(body)))
|
return nil, fmt.Errorf("doh dns-message status %s: %s", resp.Status, strings.TrimSpace(string(body)))
|
||||||
@@ -378,7 +360,7 @@ func resolveDomainWithDOHJSON(ctx context.Context, hc *http.Client, baseURL, hos
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
defer resp.Body.Close()
|
defer func() { _ = resp.Body.Close() }()
|
||||||
if resp.StatusCode != http.StatusOK {
|
if resp.StatusCode != http.StatusOK {
|
||||||
body, _ := io.ReadAll(io.LimitReader(resp.Body, 1024))
|
body, _ := io.ReadAll(io.LimitReader(resp.Body, 1024))
|
||||||
return nil, fmt.Errorf("doh status %s: %s", resp.Status, strings.TrimSpace(string(body)))
|
return nil, fmt.Errorf("doh status %s: %s", resp.Status, strings.TrimSpace(string(body)))
|
||||||
@@ -725,15 +707,15 @@ func dedupeSortedPrefixLines(rows []store.PrefixRow) []prefixHashLine {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func writePrefixLinesHash(h interface{ Write([]byte) (int, error) }, tenantID string, lines []prefixHashLine) {
|
func writePrefixLinesHash(h interface{ Write([]byte) (int, error) }, tenantID string, lines []prefixHashLine) {
|
||||||
h.Write([]byte(strings.TrimSpace(tenantID)))
|
_, _ = h.Write([]byte(strings.TrimSpace(tenantID)))
|
||||||
h.Write([]byte{0})
|
_, _ = h.Write([]byte{0})
|
||||||
for _, l := range lines {
|
for _, l := range lines {
|
||||||
h.Write([]byte(l.p))
|
_, _ = h.Write([]byte(l.p))
|
||||||
h.Write([]byte{1})
|
_, _ = h.Write([]byte{1})
|
||||||
h.Write([]byte(l.c))
|
_, _ = h.Write([]byte(l.c))
|
||||||
h.Write([]byte{1})
|
_, _ = h.Write([]byte{1})
|
||||||
h.Write([]byte(l.s))
|
_, _ = h.Write([]byte(l.s))
|
||||||
h.Write([]byte{0})
|
_, _ = h.Write([]byte{0})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -836,10 +818,18 @@ func buildPreviewFragments(st store.Backend, tenantID, moduleID, revisionID stri
|
|||||||
px6: birdfmt.JoinFragments(birdfmt.ManagedBanner(revisionID), staticV6),
|
px6: birdfmt.JoinFragments(birdfmt.ManagedBanner(revisionID), staticV6),
|
||||||
pPeers: peersBody,
|
pPeers: peersBody,
|
||||||
}
|
}
|
||||||
out[auxBirdFullExpanded] = buildExpandedBirdText(main, out)
|
|
||||||
return out, nil
|
return out, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// BuildExpandedBirdPreview concatenates bird.conf and deployable includes for UI preview (not persisted in revision).
|
||||||
|
func BuildExpandedBirdPreview(frags map[string]string) string {
|
||||||
|
if frags == nil {
|
||||||
|
return ""
|
||||||
|
}
|
||||||
|
main := frags["bird.conf"]
|
||||||
|
return buildExpandedBirdText(main, frags)
|
||||||
|
}
|
||||||
|
|
||||||
func renderStaticProtocolsByCommunity(groups []staticCommunityRoutes) (string, string) {
|
func renderStaticProtocolsByCommunity(groups []staticCommunityRoutes) (string, string) {
|
||||||
var b4 strings.Builder
|
var b4 strings.Builder
|
||||||
var b6 strings.Builder
|
var b6 strings.Builder
|
||||||
|
|||||||
@@ -76,5 +76,5 @@ func PickTenantRefreshTriggerModule(st store.Backend, tenantID string, moduleIDs
|
|||||||
return mod.ID, nil
|
return mod.ID, nil
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return "", fmt.Errorf("no enabled module for tenant refresh")
|
return "", fmt.Errorf("pipeline: no enabled module for tenant refresh")
|
||||||
}
|
}
|
||||||
@@ -0,0 +1,151 @@
|
|||||||
|
package reports
|
||||||
|
|
||||||
|
import (
|
||||||
|
"time"
|
||||||
|
|
||||||
|
"evobgp/internal/store"
|
||||||
|
)
|
||||||
|
|
||||||
|
// RouterListsCatalog is the aggregated router-lists payload for GET /router-lists/catalog.
|
||||||
|
type RouterListsCatalog struct {
|
||||||
|
Modules []map[string]any
|
||||||
|
Domains []map[string]any
|
||||||
|
ASNs []map[string]any
|
||||||
|
IPRanges []map[string]any
|
||||||
|
Communities []map[string]any
|
||||||
|
}
|
||||||
|
|
||||||
|
// BuildRouterListsCatalog loads modules and entries for the tenant catalog endpoint.
|
||||||
|
func BuildRouterListsCatalog(st store.Backend, tenantID string) (*RouterListsCatalog, error) {
|
||||||
|
mods := st.ListModules(tenantID)
|
||||||
|
out := &RouterListsCatalog{
|
||||||
|
Modules: make([]map[string]any, 0),
|
||||||
|
Domains: make([]map[string]any, 0),
|
||||||
|
ASNs: make([]map[string]any, 0),
|
||||||
|
IPRanges: make([]map[string]any, 0),
|
||||||
|
Communities: make([]map[string]any, 0),
|
||||||
|
}
|
||||||
|
|
||||||
|
for _, mod := range mods {
|
||||||
|
switch mod.Type {
|
||||||
|
case "DOMAINS", "AS_PREFIXES", "IP_RANGES":
|
||||||
|
out.Modules = append(out.Modules, moduleMap(mod))
|
||||||
|
default:
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
|
switch mod.Type {
|
||||||
|
case "DOMAINS":
|
||||||
|
list, err := st.ListDomainEntries(tenantID, mod.ID)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
for _, x := range list {
|
||||||
|
out.Domains = append(out.Domains, map[string]any{
|
||||||
|
"module_id": mod.ID,
|
||||||
|
"entry": domainEntryMap(x),
|
||||||
|
})
|
||||||
|
}
|
||||||
|
case "AS_PREFIXES":
|
||||||
|
list, err := st.ListASEntries(tenantID, mod.ID)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
for _, x := range list {
|
||||||
|
out.ASNs = append(out.ASNs, map[string]any{
|
||||||
|
"module_id": mod.ID,
|
||||||
|
"entry": asEntryMap(x),
|
||||||
|
})
|
||||||
|
}
|
||||||
|
case "IP_RANGES":
|
||||||
|
list, err := st.ListIPRangeEntries(tenantID, mod.ID)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
for _, x := range list {
|
||||||
|
out.IPRanges = append(out.IPRanges, map[string]any{
|
||||||
|
"module_id": mod.ID,
|
||||||
|
"entry": ipRangeMap(x),
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
comms, err := st.ListCommunities(tenantID)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
for _, c := range comms {
|
||||||
|
out.Communities = append(out.Communities, map[string]any{
|
||||||
|
"id": c.ID,
|
||||||
|
"community": c.Community,
|
||||||
|
"title": c.Title,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
return out, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func moduleMap(mod *store.Module) map[string]any {
|
||||||
|
m := map[string]any{
|
||||||
|
"id": mod.ID,
|
||||||
|
"type": mod.Type,
|
||||||
|
"name": mod.Name,
|
||||||
|
"enabled": mod.Enabled,
|
||||||
|
"priority": mod.Priority,
|
||||||
|
"refresh_interval_sec": mod.RefreshIntervalSec,
|
||||||
|
"cron_expr": mod.CronExpr,
|
||||||
|
}
|
||||||
|
if mod.LastRefreshedAt != nil {
|
||||||
|
m["last_refreshed_at"] = mod.LastRefreshedAt.UTC().Format(time.RFC3339Nano)
|
||||||
|
} else {
|
||||||
|
m["last_refreshed_at"] = nil
|
||||||
|
}
|
||||||
|
if mod.DefaultCommunityID != nil {
|
||||||
|
m["default_community_id"] = *mod.DefaultCommunityID
|
||||||
|
} else {
|
||||||
|
m["default_community_id"] = nil
|
||||||
|
}
|
||||||
|
ids := mod.EffectiveDohProfileIDs()
|
||||||
|
if len(ids) > 0 {
|
||||||
|
m["doh_profile_ids"] = ids
|
||||||
|
} else {
|
||||||
|
m["doh_profile_ids"] = []string{}
|
||||||
|
}
|
||||||
|
m["doh_resolver_policy"] = store.NormalizeDohResolverPolicy(mod.DohResolverPolicy)
|
||||||
|
if mod.DohProfileID != nil {
|
||||||
|
m["doh_profile_id"] = *mod.DohProfileID
|
||||||
|
} else {
|
||||||
|
m["doh_profile_id"] = nil
|
||||||
|
}
|
||||||
|
return m
|
||||||
|
}
|
||||||
|
|
||||||
|
func domainEntryMap(x *store.DomainEntry) map[string]any {
|
||||||
|
m := map[string]any{"id": x.ID, "fqdn": x.FQDN}
|
||||||
|
if x.CommunityID != nil {
|
||||||
|
m["community_id"] = *x.CommunityID
|
||||||
|
} else {
|
||||||
|
m["community_id"] = nil
|
||||||
|
}
|
||||||
|
return m
|
||||||
|
}
|
||||||
|
|
||||||
|
func asEntryMap(x *store.ASEntry) map[string]any {
|
||||||
|
m := map[string]any{"id": x.ID, "asn": x.ASN}
|
||||||
|
if x.CommunityID != nil {
|
||||||
|
m["community_id"] = *x.CommunityID
|
||||||
|
} else {
|
||||||
|
m["community_id"] = nil
|
||||||
|
}
|
||||||
|
return m
|
||||||
|
}
|
||||||
|
|
||||||
|
func ipRangeMap(x *store.IPRangeEntry) map[string]any {
|
||||||
|
m := map[string]any{"id": x.ID, "prefix": x.Prefix}
|
||||||
|
if x.CommunityID != nil {
|
||||||
|
m["community_id"] = *x.CommunityID
|
||||||
|
} else {
|
||||||
|
m["community_id"] = nil
|
||||||
|
}
|
||||||
|
return m
|
||||||
|
}
|
||||||
@@ -0,0 +1,236 @@
|
|||||||
|
package reports
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
"sort"
|
||||||
|
"strconv"
|
||||||
|
"strings"
|
||||||
|
"time"
|
||||||
|
|
||||||
|
"evobgp/internal/store"
|
||||||
|
)
|
||||||
|
|
||||||
|
// RevisionDiagnosticLog is plain-text diagnostic output for a revision.
|
||||||
|
type RevisionDiagnosticLog struct {
|
||||||
|
Body []byte
|
||||||
|
Filename string
|
||||||
|
}
|
||||||
|
|
||||||
|
// BuildRevisionDiagnosticLog aggregates revision prefixes by source and community.
|
||||||
|
func BuildRevisionDiagnosticLog(st store.Backend, tenantID string, rev *store.Revision) (*RevisionDiagnosticLog, error) {
|
||||||
|
moduleType := ""
|
||||||
|
moduleName := ""
|
||||||
|
if strings.TrimSpace(rev.ModuleID) != "" {
|
||||||
|
if mod, modErr := st.GetModule(tenantID, rev.ModuleID); modErr == nil && mod != nil {
|
||||||
|
moduleType = strings.TrimSpace(mod.Type)
|
||||||
|
moduleName = strings.TrimSpace(mod.Name)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
communityLabels := map[string]string{}
|
||||||
|
if communities, listErr := st.ListCommunities(tenantID); listErr == nil {
|
||||||
|
for _, c := range communities {
|
||||||
|
if c == nil {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
label := strings.TrimSpace(c.Title)
|
||||||
|
if label == "" {
|
||||||
|
label = strings.TrimSpace(c.Community)
|
||||||
|
}
|
||||||
|
if label == "" {
|
||||||
|
label = c.ID
|
||||||
|
}
|
||||||
|
communityLabels[c.ID] = label
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
type rawRow struct {
|
||||||
|
Prefix string
|
||||||
|
Source string
|
||||||
|
Kind string
|
||||||
|
SourceName string
|
||||||
|
SourceDetail string
|
||||||
|
CommunityID string
|
||||||
|
CommunityLabel string
|
||||||
|
}
|
||||||
|
type summary struct {
|
||||||
|
Kind string
|
||||||
|
Source string
|
||||||
|
SourceDetail string
|
||||||
|
CommunityID string
|
||||||
|
CommunityLabel string
|
||||||
|
Count int
|
||||||
|
Sample []string
|
||||||
|
}
|
||||||
|
|
||||||
|
cdnSourceURLByID := map[string]string{}
|
||||||
|
if moduleType == "CDN_CIDRS" && strings.TrimSpace(rev.ModuleID) != "" {
|
||||||
|
if sources, srcErr := st.ListCDNSources(tenantID, rev.ModuleID); srcErr == nil {
|
||||||
|
for _, src := range sources {
|
||||||
|
if src == nil {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
id := strings.TrimSpace(src.ID)
|
||||||
|
url := strings.TrimSpace(src.URL)
|
||||||
|
if id != "" && url != "" {
|
||||||
|
cdnSourceURLByID[id] = url
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
rows := make([]rawRow, 0, rev.MaterializedPrefixCount)
|
||||||
|
byGroup := map[string]*summary{}
|
||||||
|
cursor := ""
|
||||||
|
for {
|
||||||
|
page, next, more := st.ListRevisionPrefixes(tenantID, rev.ID, cursor, 2000)
|
||||||
|
for _, p := range page {
|
||||||
|
kind, sourceName := classifyRevisionSource(p.Source)
|
||||||
|
sourceDetail := sourceName
|
||||||
|
if kind == "cdn" {
|
||||||
|
if url, ok := cdnSourceURLByID[sourceName]; ok && strings.TrimSpace(url) != "" {
|
||||||
|
sourceDetail = url
|
||||||
|
}
|
||||||
|
}
|
||||||
|
communityID := "none"
|
||||||
|
if p.CommunityID != nil && strings.TrimSpace(*p.CommunityID) != "" {
|
||||||
|
communityID = strings.TrimSpace(*p.CommunityID)
|
||||||
|
}
|
||||||
|
communityLabel := "без community"
|
||||||
|
if communityID != "none" {
|
||||||
|
if lbl, ok := communityLabels[communityID]; ok && strings.TrimSpace(lbl) != "" {
|
||||||
|
communityLabel = lbl
|
||||||
|
} else {
|
||||||
|
communityLabel = communityID
|
||||||
|
}
|
||||||
|
}
|
||||||
|
rows = append(rows, rawRow{
|
||||||
|
Prefix: p.Prefix,
|
||||||
|
Source: p.Source,
|
||||||
|
Kind: kind,
|
||||||
|
SourceName: sourceName,
|
||||||
|
SourceDetail: sourceDetail,
|
||||||
|
CommunityID: communityID,
|
||||||
|
CommunityLabel: communityLabel,
|
||||||
|
})
|
||||||
|
groupKey := kind + "|" + sourceName + "|" + communityID
|
||||||
|
g, ok := byGroup[groupKey]
|
||||||
|
if !ok {
|
||||||
|
g = &summary{
|
||||||
|
Kind: kind,
|
||||||
|
Source: sourceName,
|
||||||
|
SourceDetail: sourceDetail,
|
||||||
|
CommunityID: communityID,
|
||||||
|
CommunityLabel: communityLabel,
|
||||||
|
Sample: make([]string, 0, 5),
|
||||||
|
}
|
||||||
|
byGroup[groupKey] = g
|
||||||
|
}
|
||||||
|
g.Count++
|
||||||
|
if len(g.Sample) < 5 {
|
||||||
|
g.Sample = append(g.Sample, p.Prefix)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if !more || strings.TrimSpace(next) == "" {
|
||||||
|
break
|
||||||
|
}
|
||||||
|
cursor = next
|
||||||
|
}
|
||||||
|
|
||||||
|
summaryKeys := make([]string, 0, len(byGroup))
|
||||||
|
for k := range byGroup {
|
||||||
|
summaryKeys = append(summaryKeys, k)
|
||||||
|
}
|
||||||
|
sort.Strings(summaryKeys)
|
||||||
|
|
||||||
|
sort.Slice(rows, func(i, j int) bool {
|
||||||
|
if rows[i].Kind != rows[j].Kind {
|
||||||
|
return rows[i].Kind < rows[j].Kind
|
||||||
|
}
|
||||||
|
if rows[i].SourceName != rows[j].SourceName {
|
||||||
|
return rows[i].SourceName < rows[j].SourceName
|
||||||
|
}
|
||||||
|
if rows[i].CommunityID != rows[j].CommunityID {
|
||||||
|
return rows[i].CommunityID < rows[j].CommunityID
|
||||||
|
}
|
||||||
|
return rows[i].Prefix < rows[j].Prefix
|
||||||
|
})
|
||||||
|
|
||||||
|
var b strings.Builder
|
||||||
|
b.WriteString("EvoBGP revision diagnostic log\n")
|
||||||
|
b.WriteString("generated_at=" + time.Now().UTC().Format(time.RFC3339Nano) + "\n")
|
||||||
|
b.WriteString("tenant_id=" + tenantID + "\n")
|
||||||
|
b.WriteString("revision_id=" + rev.ID + "\n")
|
||||||
|
b.WriteString("revision_created_at=" + rev.CreatedAt.UTC().Format(time.RFC3339Nano) + "\n")
|
||||||
|
b.WriteString("content_hash=" + rev.ContentHash + "\n")
|
||||||
|
b.WriteString("materialized_prefix_count=" + strconv.Itoa(rev.MaterializedPrefixCount) + "\n")
|
||||||
|
if rev.ModuleID != "" {
|
||||||
|
b.WriteString("module_id=" + rev.ModuleID + "\n")
|
||||||
|
} else {
|
||||||
|
b.WriteString("module_id=\n")
|
||||||
|
}
|
||||||
|
b.WriteString("module_type=" + moduleType + "\n")
|
||||||
|
b.WriteString("module_name=" + moduleName + "\n")
|
||||||
|
b.WriteString("fetched_rows=" + strconv.Itoa(len(rows)) + "\n\n")
|
||||||
|
|
||||||
|
b.WriteString("## Aggregation by source and community\n")
|
||||||
|
for _, k := range summaryKeys {
|
||||||
|
g := byGroup[k]
|
||||||
|
b.WriteString("- kind=" + g.Kind +
|
||||||
|
" source=" + g.Source +
|
||||||
|
" source_detail=" + g.SourceDetail +
|
||||||
|
" community_id=" + g.CommunityID +
|
||||||
|
" community_label=" + g.CommunityLabel +
|
||||||
|
" count=" + strconv.Itoa(g.Count))
|
||||||
|
if len(g.Sample) > 0 {
|
||||||
|
b.WriteString(" sample=" + strings.Join(g.Sample, ","))
|
||||||
|
}
|
||||||
|
b.WriteByte('\n')
|
||||||
|
}
|
||||||
|
|
||||||
|
b.WriteString("\n## Raw rows\n")
|
||||||
|
b.WriteString("prefix\tkind\tsource\tsource_detail\tcommunity_id\tcommunity_label\n")
|
||||||
|
for _, row := range rows {
|
||||||
|
b.WriteString(row.Prefix)
|
||||||
|
b.WriteByte('\t')
|
||||||
|
b.WriteString(row.Kind)
|
||||||
|
b.WriteByte('\t')
|
||||||
|
b.WriteString(row.Source)
|
||||||
|
b.WriteByte('\t')
|
||||||
|
b.WriteString(strings.ReplaceAll(row.SourceDetail, "\t", " "))
|
||||||
|
b.WriteByte('\t')
|
||||||
|
b.WriteString(row.CommunityID)
|
||||||
|
b.WriteByte('\t')
|
||||||
|
b.WriteString(strings.ReplaceAll(row.CommunityLabel, "\t", " "))
|
||||||
|
b.WriteByte('\n')
|
||||||
|
}
|
||||||
|
|
||||||
|
filename := fmt.Sprintf("revision-%s-diagnostic.log", shortRevisionID(rev.ID))
|
||||||
|
return &RevisionDiagnosticLog{Body: []byte(b.String()), Filename: filename}, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func classifyRevisionSource(src string) (kind, sourceName string) {
|
||||||
|
switch {
|
||||||
|
case strings.HasPrefix(src, "as:"):
|
||||||
|
return "asn", strings.TrimPrefix(src, "as:")
|
||||||
|
case strings.HasPrefix(src, "domain:"):
|
||||||
|
return "domain", strings.TrimPrefix(src, "domain:")
|
||||||
|
case strings.HasPrefix(src, "cdn:"):
|
||||||
|
return "cdn", strings.TrimPrefix(src, "cdn:")
|
||||||
|
case src == "ip_range":
|
||||||
|
return "ip_range", "manual_ranges"
|
||||||
|
default:
|
||||||
|
if strings.TrimSpace(src) == "" {
|
||||||
|
return "unknown", "unknown"
|
||||||
|
}
|
||||||
|
return "source", strings.TrimSpace(src)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func shortRevisionID(id string) string {
|
||||||
|
s := strings.TrimSpace(id)
|
||||||
|
if len(s) <= 8 {
|
||||||
|
return s
|
||||||
|
}
|
||||||
|
return s[:8]
|
||||||
|
}
|
||||||
@@ -0,0 +1,70 @@
|
|||||||
|
package repository
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
"os"
|
||||||
|
"testing"
|
||||||
|
|
||||||
|
"evobgp/internal/db"
|
||||||
|
"evobgp/internal/store"
|
||||||
|
)
|
||||||
|
|
||||||
|
func TestPostgresImplementsBackend(t *testing.T) {
|
||||||
|
var _ store.Backend = (*Postgres)(nil)
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestPostgresPingIntegration(t *testing.T) {
|
||||||
|
dsn := os.Getenv("EVOBGP_TEST_DATABASE_URL")
|
||||||
|
if dsn == "" {
|
||||||
|
t.Skip("EVOBGP_TEST_DATABASE_URL not set")
|
||||||
|
}
|
||||||
|
ctx := context.Background()
|
||||||
|
pool, err := db.OpenPostgresPool(ctx, dsn)
|
||||||
|
if err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
defer pool.Close()
|
||||||
|
pg, err := NewPostgres(ctx, pool, false)
|
||||||
|
if err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
if err := pg.Ping(ctx); err != nil {
|
||||||
|
t.Fatalf("ping: %v", err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestPostgresModuleCRUDIntegration(t *testing.T) {
|
||||||
|
dsn := os.Getenv("EVOBGP_TEST_DATABASE_URL")
|
||||||
|
if dsn == "" {
|
||||||
|
t.Skip("EVOBGP_TEST_DATABASE_URL not set")
|
||||||
|
}
|
||||||
|
ctx := context.Background()
|
||||||
|
pool, err := db.OpenPostgresPool(ctx, dsn)
|
||||||
|
if err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
defer pool.Close()
|
||||||
|
pg, err := NewPostgres(ctx, pool, false)
|
||||||
|
if err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
tenant := "01TESTTENANT00000000000001"
|
||||||
|
mod, err := pg.CreateModule(tenant, &store.Module{
|
||||||
|
Name: "audit-test",
|
||||||
|
Type: "IP_RANGES",
|
||||||
|
Enabled: true,
|
||||||
|
})
|
||||||
|
if err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
got, err := pg.GetModule(tenant, mod.ID)
|
||||||
|
if err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
if got.Name != "audit-test" {
|
||||||
|
t.Fatalf("name: got %q", got.Name)
|
||||||
|
}
|
||||||
|
if err := pg.SoftDeleteModule(tenant, mod.ID); err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,50 @@
|
|||||||
|
package repository
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
"encoding/json"
|
||||||
|
"time"
|
||||||
|
|
||||||
|
"github.com/jackc/pgx/v5/pgxpool"
|
||||||
|
)
|
||||||
|
|
||||||
|
// JobAuditWriter persists async job lifecycle rows to job_audit (optional cross-process queue foundation).
|
||||||
|
type JobAuditWriter struct {
|
||||||
|
pool *pgxpool.Pool
|
||||||
|
}
|
||||||
|
|
||||||
|
func NewJobAuditWriter(pool *pgxpool.Pool) *JobAuditWriter {
|
||||||
|
if pool == nil {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
return &JobAuditWriter{pool: pool}
|
||||||
|
}
|
||||||
|
|
||||||
|
// UpsertRunning inserts or updates a running job row (best-effort).
|
||||||
|
func (w *JobAuditWriter) UpsertRunning(ctx context.Context, tenantID, jobID, kind string, idempotencyKey *string, meta map[string]any) {
|
||||||
|
if w == nil || w.pool == nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
metaJSON, _ := json.Marshal(meta)
|
||||||
|
var idem any
|
||||||
|
if idempotencyKey != nil && *idempotencyKey != "" {
|
||||||
|
idem = *idempotencyKey
|
||||||
|
}
|
||||||
|
_, _ = w.pool.Exec(ctx, `
|
||||||
|
INSERT INTO job_audit (id, tenant_id, kind, status, idempotency_key, meta_json, created_at, started_at)
|
||||||
|
VALUES ($1::uuid, $2::uuid, $3, 'running', $4, $5::jsonb, now(), now())
|
||||||
|
ON CONFLICT (tenant_id, idempotency_key) WHERE idempotency_key IS NOT NULL
|
||||||
|
DO UPDATE SET status='running', started_at=now(), meta_json=EXCLUDED.meta_json`,
|
||||||
|
jobID, tenantID, kind, idem, metaJSON)
|
||||||
|
}
|
||||||
|
|
||||||
|
// MarkTerminal updates job_audit terminal state (best-effort).
|
||||||
|
func (w *JobAuditWriter) MarkTerminal(ctx context.Context, tenantID, jobID, status string, errMsg *string, finishedAt time.Time) {
|
||||||
|
if w == nil || w.pool == nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
_, _ = w.pool.Exec(ctx, `
|
||||||
|
UPDATE job_audit SET status=$3, error_message=$4, finished_at=$5
|
||||||
|
WHERE id=$1::uuid AND tenant_id=$2::uuid`,
|
||||||
|
jobID, tenantID, status, errMsg, finishedAt.UTC())
|
||||||
|
}
|
||||||
+133
-28
@@ -28,7 +28,7 @@ func agentDebugNDJSON3214(hypothesisID, location, message string, data map[strin
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
defer f.Close()
|
defer func() { _ = f.Close() }()
|
||||||
var ms runtime.MemStats
|
var ms runtime.MemStats
|
||||||
runtime.ReadMemStats(&ms)
|
runtime.ReadMemStats(&ms)
|
||||||
payload := map[string]any{
|
payload := map[string]any{
|
||||||
@@ -71,6 +71,11 @@ func (p *Postgres) DemoIDs() (tenant, moduleCDN, moduleIP, revision, speaker str
|
|||||||
return p.demoTenant, p.demoCDN, p.demoIP, p.demoRev, p.demoSpk
|
return p.demoTenant, p.demoCDN, p.demoIP, p.demoRev, p.demoSpk
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Ping checks PostgreSQL connectivity.
|
||||||
|
func (p *Postgres) Ping(ctx context.Context) error {
|
||||||
|
return p.pool.Ping(ctx)
|
||||||
|
}
|
||||||
|
|
||||||
func (p *Postgres) MaterializedPrefixStats() (max int, sum int) {
|
func (p *Postgres) MaterializedPrefixStats() (max int, sum int) {
|
||||||
ctx := context.Background()
|
ctx := context.Background()
|
||||||
// Агрегация в БД — не тащим все строки config_revision в память.
|
// Агрегация в БД — не тащим все строки config_revision в память.
|
||||||
@@ -121,6 +126,7 @@ func (p *Postgres) ListModules(tenantID string) []*store.Module {
|
|||||||
}
|
}
|
||||||
defer rows.Close()
|
defer rows.Close()
|
||||||
var out []*store.Module
|
var out []*store.Module
|
||||||
|
moduleByID := make(map[string]*store.Module)
|
||||||
for rows.Next() {
|
for rows.Next() {
|
||||||
var m store.Module
|
var m store.Module
|
||||||
m.TenantID = tenantID
|
m.TenantID = tenantID
|
||||||
@@ -147,14 +153,84 @@ func (p *Postgres) ListModules(tenantID string) []*store.Module {
|
|||||||
t := last.UTC()
|
t := last.UTC()
|
||||||
m.LastRefreshedAt = &t
|
m.LastRefreshedAt = &t
|
||||||
}
|
}
|
||||||
if err := p.fillModuleDohFields(ctx, &m); err != nil {
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
out = append(out, &m)
|
out = append(out, &m)
|
||||||
|
moduleByID[m.ID] = &m
|
||||||
|
}
|
||||||
|
if err := p.batchFillModuleDohFields(ctx, moduleByID); err != nil {
|
||||||
|
return nil
|
||||||
}
|
}
|
||||||
return out
|
return out
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (p *Postgres) ListModulesPage(tenantID, cursor string, limit int) ([]*store.Module, string, bool) {
|
||||||
|
if limit <= 0 {
|
||||||
|
limit = 50
|
||||||
|
}
|
||||||
|
off := 0
|
||||||
|
if cursor != "" {
|
||||||
|
if n, err := strconv.Atoi(cursor); err == nil && n >= 0 {
|
||||||
|
off = n
|
||||||
|
}
|
||||||
|
}
|
||||||
|
ctx := context.Background()
|
||||||
|
rows, err := p.pool.Query(ctx, `
|
||||||
|
SELECT id, type, name, enabled, priority, doh_profile_id::text, doh_resolver_policy,
|
||||||
|
refresh_interval_sec, cron_expr, default_community_id::text, last_refreshed_at
|
||||||
|
FROM module WHERE tenant_id = $1 AND deleted_at IS NULL
|
||||||
|
ORDER BY priority, name
|
||||||
|
LIMIT $2 OFFSET $3`, tenantID, limit+1, off)
|
||||||
|
if err != nil {
|
||||||
|
return nil, "", false
|
||||||
|
}
|
||||||
|
defer rows.Close()
|
||||||
|
var out []*store.Module
|
||||||
|
moduleByID := make(map[string]*store.Module)
|
||||||
|
for rows.Next() {
|
||||||
|
var m store.Module
|
||||||
|
m.TenantID = tenantID
|
||||||
|
var doh, dc, cron *string
|
||||||
|
var refresh *int32
|
||||||
|
var last *time.Time
|
||||||
|
if err := rows.Scan(&m.ID, &m.Type, &m.Name, &m.Enabled, &m.Priority, &doh, &m.DohResolverPolicy, &refresh, &cron, &dc, &last); err != nil {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
m.DohResolverPolicy = store.NormalizeDohResolverPolicy(m.DohResolverPolicy)
|
||||||
|
if refresh != nil {
|
||||||
|
m.RefreshIntervalSec = int(*refresh)
|
||||||
|
}
|
||||||
|
if cron != nil {
|
||||||
|
m.CronExpr = *cron
|
||||||
|
}
|
||||||
|
if doh != nil && *doh != "" {
|
||||||
|
m.DohProfileID = doh
|
||||||
|
}
|
||||||
|
if dc != nil && *dc != "" {
|
||||||
|
m.DefaultCommunityID = dc
|
||||||
|
}
|
||||||
|
if last != nil {
|
||||||
|
t := last.UTC()
|
||||||
|
m.LastRefreshedAt = &t
|
||||||
|
}
|
||||||
|
out = append(out, &m)
|
||||||
|
moduleByID[m.ID] = &m
|
||||||
|
}
|
||||||
|
if err := p.batchFillModuleDohFields(ctx, moduleByID); err != nil {
|
||||||
|
return nil, "", false
|
||||||
|
}
|
||||||
|
more := len(out) > limit
|
||||||
|
if more {
|
||||||
|
out = out[:limit]
|
||||||
|
}
|
||||||
|
next := ""
|
||||||
|
if more {
|
||||||
|
next = fmt.Sprintf("%d", off+limit)
|
||||||
|
}
|
||||||
|
if len(out) == 0 {
|
||||||
|
return nil, "", false
|
||||||
|
}
|
||||||
|
return out, next, more
|
||||||
|
}
|
||||||
|
|
||||||
func (p *Postgres) GetModule(tenantID, moduleID string) (*store.Module, error) {
|
func (p *Postgres) GetModule(tenantID, moduleID string) (*store.Module, error) {
|
||||||
ctx := context.Background()
|
ctx := context.Background()
|
||||||
var m store.Module
|
var m store.Module
|
||||||
@@ -680,7 +756,13 @@ func (p *Postgres) ListRevisionPrefixes(tenantID, revisionID string, cursor stri
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
ctx := context.Background()
|
ctx := context.Background()
|
||||||
if _, err := p.GetRevision(tenantID, revisionID); err != nil {
|
var one int
|
||||||
|
if err := p.pool.QueryRow(ctx, `
|
||||||
|
SELECT 1 FROM config_revision WHERE id = $1::uuid AND tenant_id = $2::uuid`,
|
||||||
|
revisionID, tenantID).Scan(&one); err != nil {
|
||||||
|
if errors.Is(err, pgx.ErrNoRows) {
|
||||||
|
return nil, "", false
|
||||||
|
}
|
||||||
return nil, "", false
|
return nil, "", false
|
||||||
}
|
}
|
||||||
rows, err := p.pool.Query(ctx, `
|
rows, err := p.pool.Query(ctx, `
|
||||||
@@ -749,6 +831,8 @@ func (p *Postgres) CreateRollbackRevision(tenantID, sourceRevisionID string) (st
|
|||||||
return newID, nil
|
return newID, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const maxRevisionDiffRows = 5000
|
||||||
|
|
||||||
func (p *Postgres) RevisionDiff(tenantID, aID, bID string) (map[string]any, error) {
|
func (p *Postgres) RevisionDiff(tenantID, aID, bID string) (map[string]any, error) {
|
||||||
if _, err := p.GetRevision(tenantID, aID); err != nil {
|
if _, err := p.GetRevision(tenantID, aID); err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
@@ -773,7 +857,7 @@ func (p *Postgres) RevisionDiff(tenantID, aID, bID string) (map[string]any, erro
|
|||||||
SELECT prefix FROM revision_materialized_prefix WHERE revision_id=$1::uuid
|
SELECT prefix FROM revision_materialized_prefix WHERE revision_id=$1::uuid
|
||||||
EXCEPT
|
EXCEPT
|
||||||
SELECT prefix FROM revision_materialized_prefix WHERE revision_id=$2::uuid
|
SELECT prefix FROM revision_materialized_prefix WHERE revision_id=$2::uuid
|
||||||
) s ORDER BY 1`, bID, aID)
|
) s ORDER BY 1 LIMIT $3`, bID, aID, maxRevisionDiffRows+1)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
@@ -785,13 +869,18 @@ func (p *Postgres) RevisionDiff(tenantID, aID, bID string) (map[string]any, erro
|
|||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
added = append(added, s)
|
added = append(added, s)
|
||||||
|
if len(added) > maxRevisionDiffRows {
|
||||||
|
added = added[:maxRevisionDiffRows]
|
||||||
|
break
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
addedTruncated := len(added) >= maxRevisionDiffRows
|
||||||
rowsRem, err := p.pool.Query(ctx, `
|
rowsRem, err := p.pool.Query(ctx, `
|
||||||
SELECT prefix::text FROM (
|
SELECT prefix::text FROM (
|
||||||
SELECT prefix FROM revision_materialized_prefix WHERE revision_id=$1::uuid
|
SELECT prefix FROM revision_materialized_prefix WHERE revision_id=$1::uuid
|
||||||
EXCEPT
|
EXCEPT
|
||||||
SELECT prefix FROM revision_materialized_prefix WHERE revision_id=$2::uuid
|
SELECT prefix FROM revision_materialized_prefix WHERE revision_id=$2::uuid
|
||||||
) s ORDER BY 1`, aID, bID)
|
) s ORDER BY 1 LIMIT $3`, aID, bID, maxRevisionDiffRows+1)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
@@ -803,40 +892,56 @@ func (p *Postgres) RevisionDiff(tenantID, aID, bID string) (map[string]any, erro
|
|||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
removed = append(removed, s)
|
removed = append(removed, s)
|
||||||
|
if len(removed) > maxRevisionDiffRows {
|
||||||
|
removed = removed[:maxRevisionDiffRows]
|
||||||
|
break
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return map[string]any{
|
return map[string]any{
|
||||||
"revision_a": aID,
|
"revision_a": aID,
|
||||||
"revision_b": bID,
|
"revision_b": bID,
|
||||||
"prefixes": map[string]any{
|
"prefixes": map[string]any{
|
||||||
"added": added, "removed": removed, "unchanged_count": unchanged,
|
"added": added, "removed": removed, "unchanged_count": unchanged,
|
||||||
|
"truncated": addedTruncated || len(removed) >= maxRevisionDiffRows,
|
||||||
},
|
},
|
||||||
}, nil
|
}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p *Postgres) PruneRevisionsBefore(tenantID string, cutoff time.Time) (int, error) {
|
func (p *Postgres) PruneRevisionsBefore(tenantID string, cutoff time.Time) (int, error) {
|
||||||
ctx := context.Background()
|
ctx := context.Background()
|
||||||
cmd, err := p.pool.Exec(ctx, `
|
total := 0
|
||||||
DELETE FROM config_revision AS cr
|
const batchSize = 50
|
||||||
WHERE cr.tenant_id = $1
|
for {
|
||||||
AND cr.created_at < $2
|
cmd, err := p.pool.Exec(ctx, `
|
||||||
AND cr.id <> (
|
DELETE FROM config_revision AS cr
|
||||||
SELECT id
|
WHERE cr.id IN (
|
||||||
FROM config_revision
|
SELECT id FROM config_revision
|
||||||
WHERE tenant_id = $1
|
WHERE tenant_id = $1
|
||||||
ORDER BY created_at DESC
|
AND created_at < $2
|
||||||
LIMIT 1
|
AND id <> (
|
||||||
)
|
SELECT id FROM config_revision
|
||||||
AND NOT EXISTS (
|
WHERE tenant_id = $1
|
||||||
SELECT 1
|
ORDER BY created_at DESC
|
||||||
FROM bgp_speaker AS sp
|
LIMIT 1
|
||||||
WHERE sp.tenant_id = $1
|
)
|
||||||
AND (sp.last_applied_revision_id = cr.id OR sp.published_revision_id = cr.id)
|
AND NOT EXISTS (
|
||||||
)`,
|
SELECT 1 FROM bgp_speaker AS sp
|
||||||
tenantID, cutoff.UTC())
|
WHERE sp.tenant_id = $1
|
||||||
if err != nil {
|
AND (sp.last_applied_revision_id = config_revision.id OR sp.published_revision_id = config_revision.id)
|
||||||
return 0, err
|
)
|
||||||
|
ORDER BY created_at ASC
|
||||||
|
LIMIT $3
|
||||||
|
)`, tenantID, cutoff.UTC(), batchSize)
|
||||||
|
if err != nil {
|
||||||
|
return total, err
|
||||||
|
}
|
||||||
|
n := int(cmd.RowsAffected())
|
||||||
|
total += n
|
||||||
|
if n < batchSize {
|
||||||
|
break
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return int(cmd.RowsAffected()), nil
|
return total, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p *Postgres) SetLastAppliedRevision(tenantID, speakerID, revisionID string) error {
|
func (p *Postgres) SetLastAppliedRevision(tenantID, speakerID, revisionID string) error {
|
||||||
|
|||||||
@@ -325,6 +325,38 @@ func (p *Postgres) UpdateASEntryResolveMeta(tenantID, moduleID, entryID string,
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (p *Postgres) UpdateASEntryResolveMetaBatch(tenantID, moduleID string, updates []store.ASEntryResolveMetaUpdate, resolvedAt time.Time) error {
|
||||||
|
if len(updates) == 0 {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
if _, err := p.GetModule(tenantID, moduleID); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
ctx := context.Background()
|
||||||
|
batch := &pgx.Batch{}
|
||||||
|
for _, u := range updates {
|
||||||
|
var nameArg any
|
||||||
|
sn := strings.TrimSpace(u.ASNName)
|
||||||
|
if sn == "" {
|
||||||
|
nameArg = nil
|
||||||
|
} else {
|
||||||
|
nameArg = sn
|
||||||
|
}
|
||||||
|
batch.Queue(`
|
||||||
|
UPDATE module_as_entry SET asn_name=$3, prefix_count=$4, asn_resolved_at=$5, updated_at=now()
|
||||||
|
WHERE id=$1 AND module_id=$2`,
|
||||||
|
u.EntryID, moduleID, nameArg, u.PrefixCount, resolvedAt.UTC())
|
||||||
|
}
|
||||||
|
br := p.pool.SendBatch(ctx, batch)
|
||||||
|
defer func() { _ = br.Close() }()
|
||||||
|
for range updates {
|
||||||
|
if _, err := br.Exec(); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
func (p *Postgres) DeleteASEntry(tenantID, moduleID, entryID string) error {
|
func (p *Postgres) DeleteASEntry(tenantID, moduleID, entryID string) error {
|
||||||
if _, err := p.GetModule(tenantID, moduleID); err != nil {
|
if _, err := p.GetModule(tenantID, moduleID); err != nil {
|
||||||
return err
|
return err
|
||||||
|
|||||||
@@ -10,28 +10,41 @@ func (p *Postgres) fillModuleDohFields(ctx context.Context, m *store.Module) err
|
|||||||
if m == nil {
|
if m == nil {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
return p.batchFillModuleDohFields(ctx, map[string]*store.Module{m.ID: m})
|
||||||
|
}
|
||||||
|
|
||||||
|
func (p *Postgres) batchFillModuleDohFields(ctx context.Context, modules map[string]*store.Module) error {
|
||||||
|
if len(modules) == 0 {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
ids := make([]string, 0, len(modules))
|
||||||
|
for id := range modules {
|
||||||
|
ids = append(ids, id)
|
||||||
|
}
|
||||||
rows, err := p.pool.Query(ctx, `
|
rows, err := p.pool.Query(ctx, `
|
||||||
SELECT doh_profile_id::text
|
SELECT module_id::text, doh_profile_id::text
|
||||||
FROM module_doh_profile
|
FROM module_doh_profile
|
||||||
WHERE module_id = $1
|
WHERE module_id = ANY($1::uuid[])
|
||||||
ORDER BY sort_order, doh_profile_id`, m.ID)
|
ORDER BY module_id, sort_order, doh_profile_id`, ids)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
defer rows.Close()
|
defer rows.Close()
|
||||||
var ids []string
|
byModule := make(map[string][]string, len(modules))
|
||||||
for rows.Next() {
|
for rows.Next() {
|
||||||
var id string
|
var moduleID, profileID string
|
||||||
if err := rows.Scan(&id); err != nil {
|
if err := rows.Scan(&moduleID, &profileID); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
ids = append(ids, id)
|
byModule[moduleID] = append(byModule[moduleID], profileID)
|
||||||
}
|
}
|
||||||
if err := rows.Err(); err != nil {
|
if err := rows.Err(); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
m.DohProfileIDs = store.NormalizeDohProfileIDList(ids)
|
for id, m := range modules {
|
||||||
m.SyncLegacyDohProfileID()
|
m.DohProfileIDs = store.NormalizeDohProfileIDList(byModule[id])
|
||||||
|
m.SyncLegacyDohProfileID()
|
||||||
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -121,7 +121,7 @@ func postTenantRefresh(ctx context.Context, deps *Deps, moduleIDs []string, idem
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
defer resp.Body.Close()
|
defer func() { _ = resp.Body.Close() }()
|
||||||
if resp.StatusCode == http.StatusNoContent || resp.StatusCode == http.StatusAccepted {
|
if resp.StatusCode == http.StatusNoContent || resp.StatusCode == http.StatusAccepted {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,8 @@
|
|||||||
|
package store
|
||||||
|
|
||||||
|
// ASEntryResolveMetaUpdate is one row for batch AS resolve metadata writes.
|
||||||
|
type ASEntryResolveMetaUpdate struct {
|
||||||
|
EntryID string
|
||||||
|
ASNName string
|
||||||
|
PrefixCount int64
|
||||||
|
}
|
||||||
@@ -1,6 +1,9 @@
|
|||||||
package store
|
package store
|
||||||
|
|
||||||
import "time"
|
import (
|
||||||
|
"context"
|
||||||
|
"time"
|
||||||
|
)
|
||||||
|
|
||||||
// Backend is the persistence abstraction for the control plane (memory, PostgreSQL, SQLite).
|
// Backend is the persistence abstraction for the control plane (memory, PostgreSQL, SQLite).
|
||||||
type Backend interface {
|
type Backend interface {
|
||||||
@@ -13,7 +16,10 @@ type Backend interface {
|
|||||||
// ListTenantIDs returns distinct tenant identifiers (for background workers).
|
// ListTenantIDs returns distinct tenant identifiers (for background workers).
|
||||||
ListTenantIDs() ([]string, error)
|
ListTenantIDs() ([]string, error)
|
||||||
|
|
||||||
|
// ListModules returns all modules for a tenant (control plane may paginate in httpapi).
|
||||||
ListModules(tenantID string) []*Module
|
ListModules(tenantID string) []*Module
|
||||||
|
// ListModulesPage returns one page of modules (limit capped by caller).
|
||||||
|
ListModulesPage(tenantID, cursor string, limit int) ([]*Module, string, bool)
|
||||||
GetModule(tenantID, moduleID string) (*Module, error)
|
GetModule(tenantID, moduleID string) (*Module, error)
|
||||||
CreateModule(tenantID string, in *Module) (*Module, error)
|
CreateModule(tenantID string, in *Module) (*Module, error)
|
||||||
UpdateModule(tenantID, moduleID string, patch *ModulePatch) (*Module, error)
|
UpdateModule(tenantID, moduleID string, patch *ModulePatch) (*Module, error)
|
||||||
@@ -30,6 +36,7 @@ type Backend interface {
|
|||||||
DeleteASEntry(tenantID, moduleID, entryID string) error
|
DeleteASEntry(tenantID, moduleID, entryID string) error
|
||||||
// UpdateASEntryResolveMeta записывает имя AS, число объявленных префиксов и время успешного резолва (pipeline).
|
// UpdateASEntryResolveMeta записывает имя AS, число объявленных префиксов и время успешного резолва (pipeline).
|
||||||
UpdateASEntryResolveMeta(tenantID, moduleID, entryID string, asnName string, prefixCount int64, resolvedAt time.Time) error
|
UpdateASEntryResolveMeta(tenantID, moduleID, entryID string, asnName string, prefixCount int64, resolvedAt time.Time) error
|
||||||
|
UpdateASEntryResolveMetaBatch(tenantID, moduleID string, updates []ASEntryResolveMetaUpdate, resolvedAt time.Time) error
|
||||||
|
|
||||||
ListDomainEntries(tenantID, moduleID string) ([]*DomainEntry, error)
|
ListDomainEntries(tenantID, moduleID string) ([]*DomainEntry, error)
|
||||||
CreateDomainEntry(tenantID, moduleID string, in *DomainEntry) (*DomainEntry, error)
|
CreateDomainEntry(tenantID, moduleID string, in *DomainEntry) (*DomainEntry, error)
|
||||||
@@ -53,6 +60,7 @@ type Backend interface {
|
|||||||
UpdateCommunity(tenantID, id string, patch *CommunityPatch) (*Community, error)
|
UpdateCommunity(tenantID, id string, patch *CommunityPatch) (*Community, error)
|
||||||
DeleteCommunity(tenantID, id string) error
|
DeleteCommunity(tenantID, id string) error
|
||||||
|
|
||||||
|
// ListPeers returns all BGP peers for a tenant (control plane may paginate in httpapi).
|
||||||
ListPeers(tenantID string) []*BGPPeer
|
ListPeers(tenantID string) []*BGPPeer
|
||||||
GetPeer(tenantID, id string) (*BGPPeer, error)
|
GetPeer(tenantID, id string) (*BGPPeer, error)
|
||||||
CreatePeer(tenantID string, in *BGPPeer) (*BGPPeer, error)
|
CreatePeer(tenantID string, in *BGPPeer) (*BGPPeer, error)
|
||||||
@@ -88,6 +96,9 @@ type Backend interface {
|
|||||||
// ASNPrefixCache stores RIPEstat announced-prefixes per ASN (global TTL cache).
|
// ASNPrefixCache stores RIPEstat announced-prefixes per ASN (global TTL cache).
|
||||||
GetASNPrefixCache(asn int64) (*ASNPrefixCacheEntry, bool, error)
|
GetASNPrefixCache(asn int64) (*ASNPrefixCacheEntry, bool, error)
|
||||||
SetASNPrefixCache(asn int64, holder string, prefixes []string) error
|
SetASNPrefixCache(asn int64, holder string, prefixes []string) error
|
||||||
|
|
||||||
|
// Ping verifies backend connectivity (no-op for in-memory).
|
||||||
|
Ping(ctx context.Context) error
|
||||||
}
|
}
|
||||||
|
|
||||||
// ASNPrefixCacheEntry is a cached RIPEstat response for one ASN.
|
// ASNPrefixCacheEntry is a cached RIPEstat response for one ASN.
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
package store
|
package store
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"context"
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"sort"
|
"sort"
|
||||||
@@ -32,13 +33,13 @@ type Memory struct {
|
|||||||
|
|
||||||
peers map[string]*BGPPeer
|
peers map[string]*BGPPeer
|
||||||
|
|
||||||
dohProfiles map[string]*DohProfile
|
dohProfiles map[string]*DohProfile
|
||||||
communities map[string]*Community
|
communities map[string]*Community
|
||||||
cdnSources map[string]*CDNSource
|
cdnSources map[string]*CDNSource
|
||||||
asEntries map[string]*ASEntry
|
asEntries map[string]*ASEntry
|
||||||
domainEnt map[string]*DomainEntry
|
domainEnt map[string]*DomainEntry
|
||||||
ipRanges map[string]*IPRangeEntry
|
ipRanges map[string]*IPRangeEntry
|
||||||
settings map[string]map[string]any // tenantID -> key -> JSON-compatible value
|
settings map[string]map[string]any // tenantID -> key -> JSON-compatible value
|
||||||
revPrefixes map[string][]PrefixRow
|
revPrefixes map[string][]PrefixRow
|
||||||
moduleSnapshots map[string]*moduleSnapshotRec
|
moduleSnapshots map[string]*moduleSnapshotRec
|
||||||
asnPrefixCache map[int64]*ASNPrefixCacheEntry
|
asnPrefixCache map[int64]*ASNPrefixCacheEntry
|
||||||
@@ -291,6 +292,12 @@ func (m *Memory) DemoIDs() (tenant, moduleCDN, moduleIP, revision, speaker strin
|
|||||||
return m.demoTenantID, m.demoModuleCDN, m.demoModuleIP, m.demoRevisionID, m.demoSpeakerID
|
return m.demoTenantID, m.demoModuleCDN, m.demoModuleIP, m.demoRevisionID, m.demoSpeakerID
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Ping is a no-op for the in-memory backend.
|
||||||
|
func (m *Memory) Ping(ctx context.Context) error {
|
||||||
|
_ = ctx
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
// ListTenantIDs returns tenant ids sorted lexicographically.
|
// ListTenantIDs returns tenant ids sorted lexicographically.
|
||||||
func (m *Memory) ListTenantIDs() ([]string, error) {
|
func (m *Memory) ListTenantIDs() ([]string, error) {
|
||||||
m.mu.RLock()
|
m.mu.RLock()
|
||||||
@@ -375,6 +382,11 @@ func (m *Memory) ListModules(tenantID string) []*Module {
|
|||||||
return out
|
return out
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (m *Memory) ListModulesPage(tenantID, cursor string, limit int) ([]*Module, string, bool) {
|
||||||
|
all := m.ListModules(tenantID)
|
||||||
|
return PaginateOffset(all, cursor, limit)
|
||||||
|
}
|
||||||
|
|
||||||
// ListPeers returns BGP peers for a tenant (sorted by name).
|
// ListPeers returns BGP peers for a tenant (sorted by name).
|
||||||
func (m *Memory) ListPeers(tenantID string) []*BGPPeer {
|
func (m *Memory) ListPeers(tenantID string) []*BGPPeer {
|
||||||
m.mu.RLock()
|
m.mu.RLock()
|
||||||
|
|||||||
@@ -301,6 +301,15 @@ func (m *Memory) UpdateASEntryResolveMeta(tenantID, moduleID, entryID string, as
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (m *Memory) UpdateASEntryResolveMetaBatch(tenantID, moduleID string, updates []ASEntryResolveMetaUpdate, resolvedAt time.Time) error {
|
||||||
|
for _, u := range updates {
|
||||||
|
if err := m.UpdateASEntryResolveMeta(tenantID, moduleID, u.EntryID, u.ASNName, u.PrefixCount, resolvedAt); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
func (m *Memory) DeleteASEntry(tenantID, moduleID, entryID string) error {
|
func (m *Memory) DeleteASEntry(tenantID, moduleID, entryID string) error {
|
||||||
m.mu.Lock()
|
m.mu.Lock()
|
||||||
defer m.mu.Unlock()
|
defer m.mu.Unlock()
|
||||||
|
|||||||
@@ -0,0 +1,29 @@
|
|||||||
|
package store
|
||||||
|
|
||||||
|
import "strconv"
|
||||||
|
|
||||||
|
// PaginateOffset returns a page from a pre-sorted slice using numeric string cursors (same scheme as ListRevisions).
|
||||||
|
func PaginateOffset[T any](all []T, cursor string, limit int) (page []T, nextCursor string, hasMore bool) {
|
||||||
|
if limit <= 0 {
|
||||||
|
limit = 50
|
||||||
|
}
|
||||||
|
off := 0
|
||||||
|
if cursor != "" {
|
||||||
|
if n, err := strconv.Atoi(cursor); err == nil && n >= 0 {
|
||||||
|
off = n
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if off > len(all) {
|
||||||
|
off = len(all)
|
||||||
|
}
|
||||||
|
end := off + limit
|
||||||
|
if end > len(all) {
|
||||||
|
end = len(all)
|
||||||
|
}
|
||||||
|
page = all[off:end]
|
||||||
|
if end < len(all) {
|
||||||
|
nextCursor = strconv.Itoa(end)
|
||||||
|
hasMore = true
|
||||||
|
}
|
||||||
|
return page, nextCursor, hasMore
|
||||||
|
}
|
||||||
@@ -19,9 +19,9 @@ func TestEffectivePeerEnabledOnCreate(t *testing.T) {
|
|||||||
|
|
||||||
func TestParsePeerNeighbor(t *testing.T) {
|
func TestParsePeerNeighbor(t *testing.T) {
|
||||||
tests := []struct {
|
tests := []struct {
|
||||||
in string
|
in string
|
||||||
want string
|
want string
|
||||||
wantOK bool
|
wantOK bool
|
||||||
}{
|
}{
|
||||||
{"192.168.0.2", "192.168.0.2", true},
|
{"192.168.0.2", "192.168.0.2", true},
|
||||||
{"192.168.0.2/32", "192.168.0.2", true},
|
{"192.168.0.2/32", "192.168.0.2", true},
|
||||||
|
|||||||
@@ -0,0 +1,23 @@
|
|||||||
|
// Package version holds build metadata injected at link time via -ldflags.
|
||||||
|
package version
|
||||||
|
|
||||||
|
// Link-time variables (defaults for local development).
|
||||||
|
var (
|
||||||
|
Version = "dev"
|
||||||
|
GitSHA = "unknown"
|
||||||
|
BuildTime = ""
|
||||||
|
)
|
||||||
|
|
||||||
|
// Info returns build metadata, substituting safe defaults for empty values.
|
||||||
|
func Info() (ver, gitSHA, buildTime string) {
|
||||||
|
ver = Version
|
||||||
|
if ver == "" {
|
||||||
|
ver = "dev"
|
||||||
|
}
|
||||||
|
gitSHA = GitSHA
|
||||||
|
if gitSHA == "" {
|
||||||
|
gitSHA = "unknown"
|
||||||
|
}
|
||||||
|
buildTime = BuildTime
|
||||||
|
return ver, gitSHA, buildTime
|
||||||
|
}
|
||||||
@@ -0,0 +1,6 @@
|
|||||||
|
DROP INDEX IF EXISTS idx_rev_mat_prefix_rev_id;
|
||||||
|
DROP INDEX IF EXISTS idx_config_revision_tenant_module_created;
|
||||||
|
DROP INDEX IF EXISTS idx_bgp_speaker_published;
|
||||||
|
DROP INDEX IF EXISTS idx_bgp_speaker_last_applied;
|
||||||
|
DROP INDEX IF EXISTS idx_module_default_community;
|
||||||
|
DROP INDEX IF EXISTS idx_module_doh_profile_id;
|
||||||
@@ -0,0 +1,17 @@
|
|||||||
|
CREATE INDEX IF NOT EXISTS idx_module_doh_profile_id
|
||||||
|
ON module (doh_profile_id) WHERE deleted_at IS NULL AND doh_profile_id IS NOT NULL;
|
||||||
|
|
||||||
|
CREATE INDEX IF NOT EXISTS idx_module_default_community
|
||||||
|
ON module (default_community_id) WHERE deleted_at IS NULL AND default_community_id IS NOT NULL;
|
||||||
|
|
||||||
|
CREATE INDEX IF NOT EXISTS idx_bgp_speaker_last_applied
|
||||||
|
ON bgp_speaker (last_applied_revision_id) WHERE last_applied_revision_id IS NOT NULL;
|
||||||
|
|
||||||
|
CREATE INDEX IF NOT EXISTS idx_bgp_speaker_published
|
||||||
|
ON bgp_speaker (published_revision_id) WHERE published_revision_id IS NOT NULL;
|
||||||
|
|
||||||
|
CREATE INDEX IF NOT EXISTS idx_config_revision_tenant_module_created
|
||||||
|
ON config_revision (tenant_id, module_id, created_at DESC);
|
||||||
|
|
||||||
|
CREATE INDEX IF NOT EXISTS idx_rev_mat_prefix_rev_id
|
||||||
|
ON revision_materialized_prefix (revision_id, id);
|
||||||
@@ -0,0 +1,6 @@
|
|||||||
|
DROP INDEX IF EXISTS idx_rev_mat_prefix_rev_id;
|
||||||
|
DROP INDEX IF EXISTS idx_config_revision_tenant_module_created;
|
||||||
|
DROP INDEX IF EXISTS idx_bgp_speaker_published;
|
||||||
|
DROP INDEX IF EXISTS idx_bgp_speaker_last_applied;
|
||||||
|
DROP INDEX IF EXISTS idx_module_default_community;
|
||||||
|
DROP INDEX IF EXISTS idx_module_doh_profile_id;
|
||||||
@@ -0,0 +1,17 @@
|
|||||||
|
CREATE INDEX IF NOT EXISTS idx_module_doh_profile_id
|
||||||
|
ON module (doh_profile_id) WHERE deleted_at IS NULL AND doh_profile_id IS NOT NULL;
|
||||||
|
|
||||||
|
CREATE INDEX IF NOT EXISTS idx_module_default_community
|
||||||
|
ON module (default_community_id) WHERE deleted_at IS NULL AND default_community_id IS NOT NULL;
|
||||||
|
|
||||||
|
CREATE INDEX IF NOT EXISTS idx_bgp_speaker_last_applied
|
||||||
|
ON bgp_speaker (last_applied_revision_id) WHERE last_applied_revision_id IS NOT NULL;
|
||||||
|
|
||||||
|
CREATE INDEX IF NOT EXISTS idx_bgp_speaker_published
|
||||||
|
ON bgp_speaker (published_revision_id) WHERE published_revision_id IS NOT NULL;
|
||||||
|
|
||||||
|
CREATE INDEX IF NOT EXISTS idx_config_revision_tenant_module_created
|
||||||
|
ON config_revision (tenant_id, module_id, created_at DESC);
|
||||||
|
|
||||||
|
CREATE INDEX IF NOT EXISTS idx_rev_mat_prefix_rev_id
|
||||||
|
ON revision_materialized_prefix (revision_id, id);
|
||||||
Generated
+7720
File diff suppressed because it is too large.
Load diff
@@ -0,0 +1,14 @@
|
|||||||
|
{
|
||||||
|
"name": "evobgp-release",
|
||||||
|
"private": true,
|
||||||
|
"devDependencies": {
|
||||||
|
"@commitlint/cli": "^19.8.1",
|
||||||
|
"@commitlint/config-conventional": "^19.8.1",
|
||||||
|
"@markwylde/semantic-release-gitea": "^2.2.0",
|
||||||
|
"@semantic-release/changelog": "^6.0.3",
|
||||||
|
"@semantic-release/commit-analyzer": "^13.0.1",
|
||||||
|
"@semantic-release/exec": "^7.0.0",
|
||||||
|
"@semantic-release/release-notes-generator": "^14.0.3",
|
||||||
|
"semantic-release": "^25.0.2"
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,74 @@
|
|||||||
|
#!/usr/bin/env sh
|
||||||
|
# DEP-03: postgres and sqlite migration sets must have matching numbered pairs.
|
||||||
|
set -eu
|
||||||
|
|
||||||
|
ROOT="$(CDPATH= cd -- "$(dirname "$0")/.." && pwd)"
|
||||||
|
PG="$ROOT/migrations/postgres"
|
||||||
|
SQL="$ROOT/migrations/sqlite"
|
||||||
|
|
||||||
|
list_nums() {
|
||||||
|
dir="$1"
|
||||||
|
ls "$dir" 2>/dev/null | sed -n 's/^\([0-9]\{6\}\)_.*\.up\.sql$/\1/p' | sort -u
|
||||||
|
}
|
||||||
|
|
||||||
|
migration_only_in() {
|
||||||
|
# Prints numbers present in $1 but not in $2 (space-separated lists).
|
||||||
|
haystack="$2 "
|
||||||
|
for n in $1; do
|
||||||
|
case "$haystack" in
|
||||||
|
*" $n "*) ;;
|
||||||
|
*) echo "$n" ;;
|
||||||
|
esac
|
||||||
|
done
|
||||||
|
}
|
||||||
|
|
||||||
|
pg_nums="$(list_nums "$PG")"
|
||||||
|
sql_nums="$(list_nums "$SQL")"
|
||||||
|
|
||||||
|
if [ "$pg_nums" != "$sql_nums" ]; then
|
||||||
|
echo "check-migrations-pair: postgres and sqlite migration numbers differ" >&2
|
||||||
|
only_pg="$(migration_only_in "$pg_nums" "$sql_nums")"
|
||||||
|
only_sql="$(migration_only_in "$sql_nums" "$pg_nums")"
|
||||||
|
if [ -n "$only_pg" ]; then
|
||||||
|
echo "postgres only:" >&2
|
||||||
|
for n in $only_pg; do
|
||||||
|
echo " $n" >&2
|
||||||
|
done
|
||||||
|
fi
|
||||||
|
if [ -n "$only_sql" ]; then
|
||||||
|
echo "sqlite only:" >&2
|
||||||
|
for n in $only_sql; do
|
||||||
|
echo " $n" >&2
|
||||||
|
done
|
||||||
|
fi
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
for n in $pg_nums; do
|
||||||
|
pg_up=""
|
||||||
|
sql_up=""
|
||||||
|
for f in "$PG"/${n}_*.up.sql; do
|
||||||
|
if [ -f "$f" ]; then
|
||||||
|
pg_up="$f"
|
||||||
|
break
|
||||||
|
fi
|
||||||
|
done
|
||||||
|
for f in "$SQL"/${n}_*.up.sql; do
|
||||||
|
if [ -f "$f" ]; then
|
||||||
|
sql_up="$f"
|
||||||
|
break
|
||||||
|
fi
|
||||||
|
done
|
||||||
|
if [ -z "$pg_up" ] || [ -z "$sql_up" ]; then
|
||||||
|
echo "check-migrations-pair: missing .up.sql for $n" >&2
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
pg_base="$(basename "$pg_up" .up.sql)"
|
||||||
|
sql_base="$(basename "$sql_up" .up.sql)"
|
||||||
|
if [ "$pg_base" != "$sql_base" ]; then
|
||||||
|
echo "check-migrations-pair: name mismatch for $n: $pg_base vs $sql_base" >&2
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
done
|
||||||
|
|
||||||
|
echo "check-migrations-pair: ok ($PG and $SQL)"
|
||||||
@@ -0,0 +1,181 @@
|
|||||||
|
#Requires -Version 5.1
|
||||||
|
<#
|
||||||
|
.SYNOPSIS
|
||||||
|
Staged git changes grouped by EvoBGP scope for Conventional Commit generation.
|
||||||
|
|
||||||
|
.DESCRIPTION
|
||||||
|
Outputs JSON to stdout: file groups, --stat, and truncated patch per group.
|
||||||
|
Exit 1 if nothing is staged. Does not write commit messages.
|
||||||
|
|
||||||
|
.EXAMPLE
|
||||||
|
powershell -NoProfile -File scripts/commit/staged-context.ps1
|
||||||
|
powershell -NoProfile -File scripts/commit/staged-context.ps1 | ConvertFrom-Json
|
||||||
|
#>
|
||||||
|
Set-StrictMode -Version Latest
|
||||||
|
$ErrorActionPreference = 'Stop'
|
||||||
|
|
||||||
|
$MaxLinesPerGroup = 120
|
||||||
|
$MaxLinesTotal = 500
|
||||||
|
|
||||||
|
function Test-GitRepository {
|
||||||
|
$null = git rev-parse --git-dir 2>$null
|
||||||
|
if ($LASTEXITCODE -ne 0) {
|
||||||
|
Write-Error 'staged-context: not a git repository'
|
||||||
|
exit 2
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function Get-ScopeForPath {
|
||||||
|
param([string]$Path)
|
||||||
|
$p = $Path -replace '\\', '/'
|
||||||
|
|
||||||
|
# Longest / most specific prefixes first
|
||||||
|
$rules = @(
|
||||||
|
@{ Prefix = 'docs/openapi.yaml'; Scope = 'openapi' }
|
||||||
|
@{ Prefix = 'redocly.yaml'; Scope = 'openapi' }
|
||||||
|
@{ Prefix = 'internal/httpapi/'; Scope = 'httpapi' }
|
||||||
|
@{ Prefix = 'internal/store/'; Scope = 'store' }
|
||||||
|
@{ Prefix = 'internal/repository/'; Scope = 'store' }
|
||||||
|
@{ Prefix = 'internal/db/'; Scope = 'store' }
|
||||||
|
@{ Prefix = 'internal/jobs/'; Scope = 'jobs' }
|
||||||
|
@{ Prefix = 'internal/pipeline/'; Scope = 'pipeline' }
|
||||||
|
@{ Prefix = 'internal/birdfmt/'; Scope = 'birdfmt' }
|
||||||
|
@{ Prefix = 'internal/birddeploy/'; Scope = 'birddeploy' }
|
||||||
|
@{ Prefix = 'internal/bundle/'; Scope = 'bundle' }
|
||||||
|
@{ Prefix = 'internal/signing/'; Scope = 'bundle' }
|
||||||
|
@{ Prefix = 'cmd/'; Scope = 'cmd' }
|
||||||
|
@{ Prefix = 'web/'; Scope = 'web' }
|
||||||
|
@{ Prefix = 'migrations/'; Scope = 'db' }
|
||||||
|
@{ Prefix = 'docs/'; Scope = 'docs' }
|
||||||
|
@{ Prefix = '.gitea/'; Scope = 'ci' }
|
||||||
|
@{ Prefix = 'deploy/'; Scope = 'deploy' }
|
||||||
|
@{ Prefix = '.cursor/'; Scope = 'chore' }
|
||||||
|
)
|
||||||
|
|
||||||
|
foreach ($rule in $rules) {
|
||||||
|
if ($p -eq $rule.Prefix.TrimEnd('/') -or $p.StartsWith($rule.Prefix)) {
|
||||||
|
return $rule.Scope
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return 'chore'
|
||||||
|
}
|
||||||
|
|
||||||
|
function Get-ScopeSortOrder {
|
||||||
|
param([string]$Scope)
|
||||||
|
$order = @{
|
||||||
|
openapi = 10
|
||||||
|
httpapi = 20
|
||||||
|
store = 21
|
||||||
|
jobs = 22
|
||||||
|
pipeline = 30
|
||||||
|
birdfmt = 31
|
||||||
|
birddeploy = 32
|
||||||
|
bundle = 33
|
||||||
|
web = 40
|
||||||
|
ci = 50
|
||||||
|
deploy = 51
|
||||||
|
db = 52
|
||||||
|
docs = 60
|
||||||
|
cmd = 70
|
||||||
|
chore = 80
|
||||||
|
}
|
||||||
|
if ($order.ContainsKey($Scope)) { return $order[$Scope] }
|
||||||
|
return 99
|
||||||
|
}
|
||||||
|
|
||||||
|
function Invoke-Git {
|
||||||
|
param([string[]]$GitArgs)
|
||||||
|
$out = & git @GitArgs 2>&1
|
||||||
|
if ($LASTEXITCODE -ne 0) {
|
||||||
|
$msg = ($out | Out-String).Trim()
|
||||||
|
throw "git $($GitArgs -join ' ') failed: $msg"
|
||||||
|
}
|
||||||
|
return ($out | Out-String).TrimEnd()
|
||||||
|
}
|
||||||
|
|
||||||
|
function New-GitArgs {
|
||||||
|
param([string[]]$Base, [string[]]$Paths)
|
||||||
|
if ($Paths.Count -eq 0) { return $Base }
|
||||||
|
return $Base + '--' + $Paths
|
||||||
|
}
|
||||||
|
|
||||||
|
function Get-TruncatedDiff {
|
||||||
|
param(
|
||||||
|
[string[]]$Files,
|
||||||
|
[int]$MaxLines,
|
||||||
|
[ref]$TotalLinesUsed
|
||||||
|
)
|
||||||
|
if ($Files.Count -eq 0) { return '' }
|
||||||
|
|
||||||
|
$remaining = $MaxLinesTotal - $TotalLinesUsed.Value
|
||||||
|
if ($remaining -le 0) {
|
||||||
|
return '[diff truncated: global line budget exceeded]'
|
||||||
|
}
|
||||||
|
|
||||||
|
$cap = [Math]::Min($MaxLines, $remaining)
|
||||||
|
$diff = Invoke-Git -GitArgs (New-GitArgs -Base @(
|
||||||
|
'diff', '--cached', '--no-color', '--unified=3'
|
||||||
|
) -Paths $Files)
|
||||||
|
if ([string]::IsNullOrWhiteSpace($diff)) { return '' }
|
||||||
|
|
||||||
|
$lines = $diff -split "`n", -1
|
||||||
|
if ($lines.Count -le $cap) {
|
||||||
|
$TotalLinesUsed.Value += $lines.Count
|
||||||
|
return $diff
|
||||||
|
}
|
||||||
|
|
||||||
|
$truncated = ($lines[0..($cap - 1)] -join "`n") + "`n... [truncated: $($lines.Count - $cap) more lines]"
|
||||||
|
$TotalLinesUsed.Value += $cap
|
||||||
|
return $truncated
|
||||||
|
}
|
||||||
|
|
||||||
|
Test-GitRepository
|
||||||
|
|
||||||
|
$stagedRaw = Invoke-Git -GitArgs @('diff', '--cached', '--name-only')
|
||||||
|
if ([string]::IsNullOrWhiteSpace($stagedRaw)) {
|
||||||
|
[Console]::Error.WriteLine('staged-context: no staged changes (git index is empty)')
|
||||||
|
exit 1
|
||||||
|
}
|
||||||
|
|
||||||
|
$stagedFiles = @(
|
||||||
|
$stagedRaw -split "`n" | ForEach-Object { $_.Trim() } | Where-Object { $_ -ne '' }
|
||||||
|
)
|
||||||
|
$stagedFiles = $stagedFiles | Sort-Object -Unique
|
||||||
|
|
||||||
|
$scopeBuckets = @{}
|
||||||
|
foreach ($f in $stagedFiles) {
|
||||||
|
$scope = Get-ScopeForPath -Path $f
|
||||||
|
if (-not $scopeBuckets.ContainsKey($scope)) {
|
||||||
|
$scopeBuckets[$scope] = [System.Collections.Generic.List[string]]::new()
|
||||||
|
}
|
||||||
|
$scopeBuckets[$scope].Add($f) | Out-Null
|
||||||
|
}
|
||||||
|
|
||||||
|
$totalLinesUsed = 0
|
||||||
|
$groups = New-Object System.Collections.Generic.List[object]
|
||||||
|
|
||||||
|
$scopeKeys = @($scopeBuckets.Keys | Sort-Object { Get-ScopeSortOrder $_ })
|
||||||
|
|
||||||
|
foreach ($scope in $scopeKeys) {
|
||||||
|
$files = @($scopeBuckets[$scope] | Sort-Object)
|
||||||
|
$stat = Invoke-Git -GitArgs (New-GitArgs -Base @('diff', '--cached', '--stat') -Paths $files)
|
||||||
|
$diffExcerpt = Get-TruncatedDiff -Files $files -MaxLines $MaxLinesPerGroup -TotalLinesUsed ([ref]$totalLinesUsed)
|
||||||
|
|
||||||
|
$groups.Add([ordered]@{
|
||||||
|
scope = $scope
|
||||||
|
files = $files
|
||||||
|
stat = $stat
|
||||||
|
diff_excerpt = $diffExcerpt
|
||||||
|
}) | Out-Null
|
||||||
|
}
|
||||||
|
|
||||||
|
$result = [ordered]@{
|
||||||
|
staged_count = $stagedFiles.Count
|
||||||
|
groups = $groups.ToArray()
|
||||||
|
}
|
||||||
|
|
||||||
|
$json = $result | ConvertTo-Json -Depth 6 -Compress:$false
|
||||||
|
# UTF-8 stdout for agents / ConvertFrom-Json
|
||||||
|
[Console]::OutputEncoding = [System.Text.UTF8Encoding]::new($false)
|
||||||
|
Write-Output $json
|
||||||
|
exit 0
|
||||||
@@ -0,0 +1,36 @@
|
|||||||
|
#!/usr/bin/env sh
|
||||||
|
# Engineering gates for internal/httpapi (ERR-01, ARCH-01).
|
||||||
|
set -eu
|
||||||
|
|
||||||
|
ROOT="$(CDPATH= cd -- "$(dirname "$0")/.." && pwd)"
|
||||||
|
cd "$ROOT"
|
||||||
|
|
||||||
|
HTTPAPI="internal/httpapi"
|
||||||
|
FAIL=0
|
||||||
|
|
||||||
|
echo "==> ERR-01: no err.Error() in 5xx problem details"
|
||||||
|
if grep -rE 'writeProblem\(w, http\.StatusInternalServerError.*err\.Error\(\)' "$HTTPAPI" 2>/dev/null; then
|
||||||
|
FAIL=1
|
||||||
|
fi
|
||||||
|
if grep -rE 'writeProblem\(w, http\.StatusBadGateway.*err\.Error\(\)' "$HTTPAPI" 2>/dev/null; then
|
||||||
|
FAIL=1
|
||||||
|
fi
|
||||||
|
|
||||||
|
echo "==> ERR-01: no err.Error() in 4xx writeProblem (store/cdn/csv)"
|
||||||
|
if grep -rE 'writeProblem\(w, http\.Status(NotFound|UnprocessableEntity|BadRequest).*, err\.Error\(\)' "$HTTPAPI" 2>/dev/null; then
|
||||||
|
FAIL=1
|
||||||
|
fi
|
||||||
|
if grep -rE 'writeStoreErr.*err\.Error|writeProblem.*Unprocessable.*err\.Error' "$HTTPAPI" 2>/dev/null; then
|
||||||
|
FAIL=1
|
||||||
|
fi
|
||||||
|
|
||||||
|
echo "==> ARCH-01: no SQL/pgx queries in httpapi"
|
||||||
|
if grep -rE 'pool\.(Query|Exec|QueryRow)|SELECT |INSERT INTO |UPDATE .* SET |DELETE FROM ' "$HTTPAPI" 2>/dev/null; then
|
||||||
|
FAIL=1
|
||||||
|
fi
|
||||||
|
|
||||||
|
if [ "$FAIL" -ne 0 ]; then
|
||||||
|
echo "lint-httpapi: failed" >&2
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
echo "lint-httpapi: ok"
|
||||||
+1
-4
@@ -3,10 +3,7 @@
|
|||||||
"singleQuote": true,
|
"singleQuote": true,
|
||||||
"trailingComma": "none",
|
"trailingComma": "none",
|
||||||
"printWidth": 100,
|
"printWidth": 100,
|
||||||
"plugins": [
|
"plugins": ["prettier-plugin-svelte", "prettier-plugin-tailwindcss"],
|
||||||
"prettier-plugin-svelte",
|
|
||||||
"prettier-plugin-tailwindcss"
|
|
||||||
],
|
|
||||||
"tailwindStylesheet": "./src/routes/layout.css",
|
"tailwindStylesheet": "./src/routes/layout.css",
|
||||||
"overrides": [
|
"overrides": [
|
||||||
{
|
{
|
||||||
|
|||||||
Vendored
+1
-5
@@ -1,7 +1,3 @@
|
|||||||
{
|
{
|
||||||
"recommendations": [
|
"recommendations": ["svelte.svelte-vscode", "bradlc.vscode-tailwindcss", "esbenp.prettier-vscode"]
|
||||||
"svelte.svelte-vscode",
|
|
||||||
"bradlc.vscode-tailwindcss",
|
|
||||||
"esbenp.prettier-vscode"
|
|
||||||
]
|
|
||||||
}
|
}
|
||||||
+6
-6
@@ -6,12 +6,12 @@ SvelteKit-приложение панели управления EvoBGP. Зап
|
|||||||
|
|
||||||
## UI-архитектура
|
## UI-архитектура
|
||||||
|
|
||||||
| Путь | Назначение |
|
| Путь | Назначение |
|
||||||
|------|------------|
|
| ------------------------ | ------------------------------------------------------------------- |
|
||||||
| `src/lib/ui/core/` | shadcn-svelte (только через `npx shadcn-svelte@latest add … -y -o`) |
|
| `src/lib/ui/core/` | shadcn-svelte (только через `npx shadcn-svelte@latest add … -y -o`) |
|
||||||
| `src/lib/ui/app/` | Layout, PageHeader, toast (`notify`) |
|
| `src/lib/ui/app/` | Layout, PageHeader, toast (`notify`) |
|
||||||
| `src/lib/ui/patterns/` | FormField, AppDataTable, ConfirmDialog, EmptyState |
|
| `src/lib/ui/patterns/` | FormField, AppDataTable, ConfirmDialog, EmptyState |
|
||||||
| `src/lib/components/ui/` | Re-export на `ui/core` (совместимость) |
|
| `src/lib/components/ui/` | Re-export на `ui/core` (совместимость) |
|
||||||
|
|
||||||
Токены темы: `src/routes/layout.css`. Справочник: `src/lib/ui/app/tokens.md`.
|
Токены темы: `src/routes/layout.css`. Справочник: `src/lib/ui/app/tokens.md`.
|
||||||
|
|
||||||
|
|||||||
Generated
+2
-3
@@ -14,7 +14,8 @@
|
|||||||
"svelte-sonner": "^1.1.0",
|
"svelte-sonner": "^1.1.0",
|
||||||
"tailwind-merge": "^3.5.0",
|
"tailwind-merge": "^3.5.0",
|
||||||
"tailwind-variants": "^3.2.2",
|
"tailwind-variants": "^3.2.2",
|
||||||
"tw-animate-css": "^1.4.0"
|
"tw-animate-css": "^1.4.0",
|
||||||
|
"zod": "^4.4.3"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@internationalized/date": "^3.12.0",
|
"@internationalized/date": "^3.12.0",
|
||||||
@@ -3137,9 +3138,7 @@
|
|||||||
"version": "4.4.3",
|
"version": "4.4.3",
|
||||||
"resolved": "https://registry.npmjs.org/zod/-/zod-4.4.3.tgz",
|
"resolved": "https://registry.npmjs.org/zod/-/zod-4.4.3.tgz",
|
||||||
"integrity": "sha512-ytENFjIJFl2UwYglde2jchW2Hwm4GJFLDiSXWdTrJQBIN9Fcyp7n4DhxJEiWNAJMV1/BqWfW/kkg71UDcHJyTQ==",
|
"integrity": "sha512-ytENFjIJFl2UwYglde2jchW2Hwm4GJFLDiSXWdTrJQBIN9Fcyp7n4DhxJEiWNAJMV1/BqWfW/kkg71UDcHJyTQ==",
|
||||||
"dev": true,
|
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"optional": true,
|
|
||||||
"funding": {
|
"funding": {
|
||||||
"url": "https://github.com/sponsors/colinhacks"
|
"url": "https://github.com/sponsors/colinhacks"
|
||||||
}
|
}
|
||||||
|
|||||||
+2
-1
@@ -39,6 +39,7 @@
|
|||||||
"svelte-sonner": "^1.1.0",
|
"svelte-sonner": "^1.1.0",
|
||||||
"tailwind-merge": "^3.5.0",
|
"tailwind-merge": "^3.5.0",
|
||||||
"tailwind-variants": "^3.2.2",
|
"tailwind-variants": "^3.2.2",
|
||||||
"tw-animate-css": "^1.4.0"
|
"tw-animate-css": "^1.4.0",
|
||||||
|
"zod": "^4.4.3"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -124,11 +124,13 @@ export type IpRangeEntriesResponse = Page<IpRangeEntry>;
|
|||||||
// ---- DoH Profiles ----
|
// ---- DoH Profiles ----
|
||||||
export type DohProfile = {
|
export type DohProfile = {
|
||||||
id: string;
|
id: string;
|
||||||
|
name?: string;
|
||||||
url: string;
|
url: string;
|
||||||
timeout_ms: number | null;
|
timeout_ms: number | null;
|
||||||
vault_secret_ref: string | null;
|
vault_secret_ref: string | null;
|
||||||
};
|
};
|
||||||
export type DohProfileCreate = {
|
export type DohProfileCreate = {
|
||||||
|
name?: string;
|
||||||
url: string;
|
url: string;
|
||||||
timeout_ms?: number | null;
|
timeout_ms?: number | null;
|
||||||
vault_secret_ref?: string | null;
|
vault_secret_ref?: string | null;
|
||||||
|
|||||||
@@ -0,0 +1,49 @@
|
|||||||
|
/** Ответ GET /v1/version (см. docs/openapi.yaml VersionInfo). */
|
||||||
|
export type VersionInfo = {
|
||||||
|
version?: string;
|
||||||
|
api_version?: string;
|
||||||
|
git_sha?: string;
|
||||||
|
build_time?: string;
|
||||||
|
};
|
||||||
|
|
||||||
|
const PLACEHOLDER_SHA = new Set(['', 'unknown']);
|
||||||
|
|
||||||
|
function nonEmptyString(value: unknown): string {
|
||||||
|
if (typeof value === 'string') {
|
||||||
|
const s = value.trim();
|
||||||
|
return s;
|
||||||
|
}
|
||||||
|
if (value == null) return '';
|
||||||
|
return String(value).trim();
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Semver или legacy api_version; пустая строка, если полей нет. */
|
||||||
|
export function resolveVersionString(info: VersionInfo | null | undefined): string {
|
||||||
|
if (!info) return '';
|
||||||
|
return nonEmptyString(info.version) || nonEmptyString(info.api_version);
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Короткий git SHA; пусто для placeholder «unknown». */
|
||||||
|
export function resolveGitSha(info: VersionInfo | null | undefined): string {
|
||||||
|
if (!info) return '';
|
||||||
|
const sha = nonEmptyString(info.git_sha);
|
||||||
|
if (!sha || PLACEHOLDER_SHA.has(sha.toLowerCase())) return '';
|
||||||
|
return sha;
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Заголовок карточки «Версия» на /monitoring. */
|
||||||
|
export function formatVersionHeadline(info: VersionInfo | null | undefined): string {
|
||||||
|
if (!info) return '—';
|
||||||
|
const ver = resolveVersionString(info);
|
||||||
|
const sha = resolveGitSha(info);
|
||||||
|
if (ver && sha) return `${ver} (${sha.slice(0, 12)})`;
|
||||||
|
if (ver) return ver;
|
||||||
|
if (sha) return sha.slice(0, 12);
|
||||||
|
return '—';
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Подпись в сайдбаре (v1.2.3). */
|
||||||
|
export function formatVersionSidebarLabel(info: VersionInfo | null | undefined): string | null {
|
||||||
|
const ver = resolveVersionString(info);
|
||||||
|
return ver ? `v${ver}` : null;
|
||||||
|
}
|
||||||
@@ -0,0 +1,188 @@
|
|||||||
|
<script lang="ts">
|
||||||
|
import { apiMutate } from '$lib/api/client.js';
|
||||||
|
import type { BgpCommunity, BgpCommunityCreate } from '$lib/api/types.js';
|
||||||
|
import { Button } from '$lib/ui/core/button/index.js';
|
||||||
|
import {
|
||||||
|
Card,
|
||||||
|
CardContent,
|
||||||
|
CardHeader,
|
||||||
|
CardTitle,
|
||||||
|
CardDescription
|
||||||
|
} from '$lib/ui/core/card/index.js';
|
||||||
|
import {
|
||||||
|
Dialog,
|
||||||
|
DialogContent,
|
||||||
|
DialogHeader,
|
||||||
|
DialogTitle,
|
||||||
|
DialogFooter
|
||||||
|
} from '$lib/ui/core/dialog/index.js';
|
||||||
|
import FormField from '$lib/ui/patterns/form/form-field.svelte';
|
||||||
|
import AppInput from '$lib/ui/patterns/form/app-input.svelte';
|
||||||
|
import AppDataTable from '$lib/ui/patterns/data-table/app-data-table.svelte';
|
||||||
|
import { confirm } from '$lib/ui/patterns/confirm/confirm-state.svelte.js';
|
||||||
|
import { notify, notifyApiError } from '$lib/ui/app/toast.js';
|
||||||
|
import Plus from '@lucide/svelte/icons/plus';
|
||||||
|
import Pencil from '@lucide/svelte/icons/pencil';
|
||||||
|
import Trash2 from '@lucide/svelte/icons/trash-2';
|
||||||
|
|
||||||
|
type Props = {
|
||||||
|
items: BgpCommunity[];
|
||||||
|
loading?: boolean;
|
||||||
|
initialLoading?: boolean;
|
||||||
|
error?: string | null;
|
||||||
|
onRefresh: () => void | Promise<void>;
|
||||||
|
};
|
||||||
|
|
||||||
|
let { items, loading = false, initialLoading = false, error = null, onRefresh }: Props = $props();
|
||||||
|
|
||||||
|
let dialogOpen = $state(false);
|
||||||
|
let editTarget = $state<BgpCommunity | null>(null);
|
||||||
|
let form = $state<BgpCommunityCreate>({ community: '', title: '' });
|
||||||
|
let saving = $state(false);
|
||||||
|
|
||||||
|
const columns = [
|
||||||
|
{
|
||||||
|
id: 'community',
|
||||||
|
label: 'Код сообщества',
|
||||||
|
sortable: true,
|
||||||
|
sortValue: (c: BgpCommunity) => c.community
|
||||||
|
},
|
||||||
|
{
|
||||||
|
id: 'title',
|
||||||
|
label: 'Название',
|
||||||
|
sortable: true,
|
||||||
|
sortValue: (c: BgpCommunity) => c.title ?? ''
|
||||||
|
},
|
||||||
|
{ id: 'id', label: 'ID' },
|
||||||
|
{ id: 'actions', label: '', class: 'w-20' }
|
||||||
|
] as const;
|
||||||
|
|
||||||
|
function displayName(c: BgpCommunity | null) {
|
||||||
|
if (!c) return '';
|
||||||
|
const t = c.title?.trim();
|
||||||
|
return t || c.community;
|
||||||
|
}
|
||||||
|
|
||||||
|
function openCreate() {
|
||||||
|
editTarget = null;
|
||||||
|
form = { community: '', title: '' };
|
||||||
|
dialogOpen = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
function openEdit(c: BgpCommunity) {
|
||||||
|
editTarget = c;
|
||||||
|
form = { community: c.community, title: c.title ?? '' };
|
||||||
|
dialogOpen = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
function requestDelete(c: BgpCommunity) {
|
||||||
|
void confirm({
|
||||||
|
title: `Удалить сообщество «${displayName(c)}»?`,
|
||||||
|
description: 'Это приведёт к удалению привязки во всех модулях.',
|
||||||
|
confirmLabel: 'Удалить',
|
||||||
|
destructive: true,
|
||||||
|
onConfirm: async () => {
|
||||||
|
await apiMutate(`/v1/communities/${c.id}`, 'DELETE', undefined, { idempotent: false });
|
||||||
|
notify.success('Удалено');
|
||||||
|
await onRefresh();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
async function save() {
|
||||||
|
if (!form.community.trim()) {
|
||||||
|
notify.error('Укажите community');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
saving = true;
|
||||||
|
try {
|
||||||
|
const body = { ...form, title: form.title?.trim() || undefined };
|
||||||
|
if (editTarget) {
|
||||||
|
await apiMutate(`/v1/communities/${editTarget.id}`, 'PATCH', body);
|
||||||
|
notify.success('Запись сообщества обновлена');
|
||||||
|
} else {
|
||||||
|
await apiMutate('/v1/communities', 'POST', body);
|
||||||
|
notify.success('Сообщество создано');
|
||||||
|
}
|
||||||
|
dialogOpen = false;
|
||||||
|
await onRefresh();
|
||||||
|
} catch (e) {
|
||||||
|
notifyApiError(e);
|
||||||
|
} finally {
|
||||||
|
saving = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<Card>
|
||||||
|
<CardHeader
|
||||||
|
class="flex flex-col gap-3 border-b py-3 sm:flex-row sm:items-center sm:justify-between"
|
||||||
|
>
|
||||||
|
<div class="min-w-0 flex-1">
|
||||||
|
<CardTitle class="text-base">Сообщества BGP</CardTitle>
|
||||||
|
<CardDescription>Используются для тегирования префиксов в AS- и CDN-модулях</CardDescription>
|
||||||
|
</div>
|
||||||
|
<div class="flex shrink-0 flex-wrap items-center justify-end gap-2">
|
||||||
|
<Button size="sm" onclick={openCreate}><Plus />Добавить</Button>
|
||||||
|
</div>
|
||||||
|
</CardHeader>
|
||||||
|
<CardContent class="p-4 pt-0">
|
||||||
|
<AppDataTable
|
||||||
|
columns={[...columns]}
|
||||||
|
rows={items}
|
||||||
|
rowKey={(c) => c.id}
|
||||||
|
loading={initialLoading || loading}
|
||||||
|
{error}
|
||||||
|
emptyTitle="Нет сообществ BGP"
|
||||||
|
emptyDescription="Создайте первое сообщество для тегирования префиксов."
|
||||||
|
>
|
||||||
|
{#snippet cell({ row: c, column })}
|
||||||
|
{#if column.id === 'community'}
|
||||||
|
<span class="font-mono text-sm font-medium">{c.community}</span>
|
||||||
|
{:else if column.id === 'title'}
|
||||||
|
<span>{c.title?.trim() || '—'}</span>
|
||||||
|
{:else if column.id === 'id'}
|
||||||
|
<span class="font-mono text-xs text-muted-foreground">{c.id}</span>
|
||||||
|
{:else if column.id === 'actions'}
|
||||||
|
<div class="flex gap-1">
|
||||||
|
<Button variant="ghost" size="icon-sm" onclick={() => openEdit(c)}>
|
||||||
|
<Pencil class="size-3.5" />
|
||||||
|
</Button>
|
||||||
|
<Button
|
||||||
|
variant="ghost"
|
||||||
|
size="icon-sm"
|
||||||
|
class="text-destructive"
|
||||||
|
onclick={() => requestDelete(c)}
|
||||||
|
>
|
||||||
|
<Trash2 class="size-3.5" />
|
||||||
|
</Button>
|
||||||
|
</div>
|
||||||
|
{/if}
|
||||||
|
{/snippet}
|
||||||
|
</AppDataTable>
|
||||||
|
</CardContent>
|
||||||
|
</Card>
|
||||||
|
|
||||||
|
<Dialog bind:open={dialogOpen}>
|
||||||
|
<DialogContent class="sm:max-w-sm">
|
||||||
|
<DialogHeader>
|
||||||
|
<DialogTitle
|
||||||
|
>{editTarget ? 'Редактировать сообщество BGP' : 'Новое сообщество BGP'}</DialogTitle
|
||||||
|
>
|
||||||
|
</DialogHeader>
|
||||||
|
<div class="flex flex-col gap-4 py-2">
|
||||||
|
<FormField label="Код сообщества" id="c-community" required>
|
||||||
|
<AppInput id="c-community" bind:value={form.community} placeholder="65001:120" />
|
||||||
|
</FormField>
|
||||||
|
<FormField label="Название" id="c-title" description="Человекочитаемое имя для списков">
|
||||||
|
<AppInput id="c-title" bind:value={form.title} placeholder="Название" />
|
||||||
|
</FormField>
|
||||||
|
</div>
|
||||||
|
<DialogFooter>
|
||||||
|
<Button variant="outline" onclick={() => (dialogOpen = false)}>Отмена</Button>
|
||||||
|
<Button onclick={save} disabled={saving}>
|
||||||
|
{saving ? 'Сохранение…' : editTarget ? 'Сохранить' : 'Создать'}
|
||||||
|
</Button>
|
||||||
|
</DialogFooter>
|
||||||
|
</DialogContent>
|
||||||
|
</Dialog>
|
||||||
@@ -0,0 +1,178 @@
|
|||||||
|
<script lang="ts">
|
||||||
|
import { apiMutate } from '$lib/api/client.js';
|
||||||
|
import type { DohProfile, DohProfileCreate } from '$lib/api/types.js';
|
||||||
|
import { Button } from '$lib/ui/core/button/index.js';
|
||||||
|
import {
|
||||||
|
Card,
|
||||||
|
CardContent,
|
||||||
|
CardHeader,
|
||||||
|
CardTitle,
|
||||||
|
CardDescription
|
||||||
|
} from '$lib/ui/core/card/index.js';
|
||||||
|
import {
|
||||||
|
Dialog,
|
||||||
|
DialogContent,
|
||||||
|
DialogHeader,
|
||||||
|
DialogTitle,
|
||||||
|
DialogFooter
|
||||||
|
} from '$lib/ui/core/dialog/index.js';
|
||||||
|
import FormField from '$lib/ui/patterns/form/form-field.svelte';
|
||||||
|
import AppInput from '$lib/ui/patterns/form/app-input.svelte';
|
||||||
|
import AppDataTable from '$lib/ui/patterns/data-table/app-data-table.svelte';
|
||||||
|
import { confirm } from '$lib/ui/patterns/confirm/confirm-state.svelte.js';
|
||||||
|
import { notify, notifyApiError } from '$lib/ui/app/toast.js';
|
||||||
|
import Plus from '@lucide/svelte/icons/plus';
|
||||||
|
import Pencil from '@lucide/svelte/icons/pencil';
|
||||||
|
import Trash2 from '@lucide/svelte/icons/trash-2';
|
||||||
|
|
||||||
|
type Props = {
|
||||||
|
items: DohProfile[];
|
||||||
|
loading?: boolean;
|
||||||
|
initialLoading?: boolean;
|
||||||
|
error?: string | null;
|
||||||
|
onRefresh: () => void | Promise<void>;
|
||||||
|
};
|
||||||
|
|
||||||
|
let { items, loading = false, initialLoading = false, error = null, onRefresh }: Props = $props();
|
||||||
|
|
||||||
|
let dialogOpen = $state(false);
|
||||||
|
let editTarget = $state<DohProfile | null>(null);
|
||||||
|
let form = $state<DohProfileCreate & { timeout_ms?: number | null }>({
|
||||||
|
url: '',
|
||||||
|
timeout_ms: null,
|
||||||
|
vault_secret_ref: null
|
||||||
|
});
|
||||||
|
let saving = $state(false);
|
||||||
|
|
||||||
|
const columns = [
|
||||||
|
{ id: 'url', label: 'URL', sortable: true, sortValue: (d: DohProfile) => d.url },
|
||||||
|
{
|
||||||
|
id: 'timeout_ms',
|
||||||
|
label: 'Таймаут (мс)',
|
||||||
|
sortable: true,
|
||||||
|
sortValue: (d: DohProfile) => d.timeout_ms ?? 0
|
||||||
|
},
|
||||||
|
{ id: 'id', label: 'ID' },
|
||||||
|
{ id: 'actions', label: '', class: 'w-20' }
|
||||||
|
] as const;
|
||||||
|
|
||||||
|
function openCreate() {
|
||||||
|
editTarget = null;
|
||||||
|
form = { url: '', timeout_ms: null, vault_secret_ref: null };
|
||||||
|
dialogOpen = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
function openEdit(d: DohProfile) {
|
||||||
|
editTarget = d;
|
||||||
|
form = { url: d.url, timeout_ms: d.timeout_ms, vault_secret_ref: d.vault_secret_ref };
|
||||||
|
dialogOpen = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
function requestDelete(d: DohProfile) {
|
||||||
|
void confirm({
|
||||||
|
title: 'Удалить DoH профиль?',
|
||||||
|
description: d.url,
|
||||||
|
confirmLabel: 'Удалить',
|
||||||
|
destructive: true,
|
||||||
|
onConfirm: async () => {
|
||||||
|
await apiMutate(`/v1/doh-profiles/${d.id}`, 'DELETE', undefined, { idempotent: false });
|
||||||
|
notify.success('Удалено');
|
||||||
|
await onRefresh();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
async function save() {
|
||||||
|
if (!form.url.trim()) {
|
||||||
|
notify.error('Укажите URL');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
saving = true;
|
||||||
|
try {
|
||||||
|
if (editTarget) {
|
||||||
|
await apiMutate(`/v1/doh-profiles/${editTarget.id}`, 'PATCH', form);
|
||||||
|
notify.success('DoH профиль обновлён');
|
||||||
|
} else {
|
||||||
|
await apiMutate('/v1/doh-profiles', 'POST', form);
|
||||||
|
notify.success('DoH профиль создан');
|
||||||
|
}
|
||||||
|
dialogOpen = false;
|
||||||
|
await onRefresh();
|
||||||
|
} catch (e) {
|
||||||
|
notifyApiError(e);
|
||||||
|
} finally {
|
||||||
|
saving = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<Card>
|
||||||
|
<CardHeader
|
||||||
|
class="flex flex-col gap-3 border-b py-3 sm:flex-row sm:items-center sm:justify-between"
|
||||||
|
>
|
||||||
|
<div class="min-w-0 flex-1">
|
||||||
|
<CardTitle class="text-base">DoH профили</CardTitle>
|
||||||
|
<CardDescription>DNS-over-HTTPS серверы для резолвинга доменных модулей</CardDescription>
|
||||||
|
</div>
|
||||||
|
<div class="flex shrink-0 flex-wrap items-center justify-end gap-2">
|
||||||
|
<Button size="sm" onclick={openCreate}><Plus />Добавить</Button>
|
||||||
|
</div>
|
||||||
|
</CardHeader>
|
||||||
|
<CardContent class="p-4 pt-0">
|
||||||
|
<AppDataTable
|
||||||
|
columns={[...columns]}
|
||||||
|
rows={items}
|
||||||
|
rowKey={(d) => d.id}
|
||||||
|
loading={initialLoading || loading}
|
||||||
|
{error}
|
||||||
|
emptyTitle="Нет DoH профилей"
|
||||||
|
emptyDescription="Добавьте DNS-over-HTTPS сервер для доменных модулей."
|
||||||
|
>
|
||||||
|
{#snippet cell({ row: d, column })}
|
||||||
|
{#if column.id === 'url'}
|
||||||
|
<span class="font-mono text-sm">{d.url}</span>
|
||||||
|
{:else if column.id === 'timeout_ms'}
|
||||||
|
<span class="text-muted-foreground">{d.timeout_ms ?? '—'}</span>
|
||||||
|
{:else if column.id === 'id'}
|
||||||
|
<span class="font-mono text-xs text-muted-foreground">{d.id}</span>
|
||||||
|
{:else if column.id === 'actions'}
|
||||||
|
<div class="flex gap-1">
|
||||||
|
<Button variant="ghost" size="icon-sm" onclick={() => openEdit(d)}>
|
||||||
|
<Pencil class="size-3.5" />
|
||||||
|
</Button>
|
||||||
|
<Button
|
||||||
|
variant="ghost"
|
||||||
|
size="icon-sm"
|
||||||
|
class="text-destructive"
|
||||||
|
onclick={() => requestDelete(d)}
|
||||||
|
>
|
||||||
|
<Trash2 class="size-3.5" />
|
||||||
|
</Button>
|
||||||
|
</div>
|
||||||
|
{/if}
|
||||||
|
{/snippet}
|
||||||
|
</AppDataTable>
|
||||||
|
</CardContent>
|
||||||
|
</Card>
|
||||||
|
|
||||||
|
<Dialog bind:open={dialogOpen}>
|
||||||
|
<DialogContent class="sm:max-w-sm">
|
||||||
|
<DialogHeader>
|
||||||
|
<DialogTitle>{editTarget ? 'Редактировать' : 'Новый'} DoH профиль</DialogTitle>
|
||||||
|
</DialogHeader>
|
||||||
|
<div class="flex flex-col gap-4 py-2">
|
||||||
|
<FormField label="URL" id="doh-url" required>
|
||||||
|
<AppInput id="doh-url" bind:value={form.url} placeholder="https://dns.google/dns-query" />
|
||||||
|
</FormField>
|
||||||
|
<FormField label="Таймаут (мс)" id="doh-timeout">
|
||||||
|
<AppInput id="doh-timeout" type="number" bind:value={form.timeout_ms} placeholder="5000" />
|
||||||
|
</FormField>
|
||||||
|
</div>
|
||||||
|
<DialogFooter>
|
||||||
|
<Button variant="outline" onclick={() => (dialogOpen = false)}>Отмена</Button>
|
||||||
|
<Button onclick={save} disabled={saving}>
|
||||||
|
{saving ? 'Сохранение…' : editTarget ? 'Сохранить' : 'Создать'}
|
||||||
|
</Button>
|
||||||
|
</DialogFooter>
|
||||||
|
</DialogContent>
|
||||||
|
</Dialog>
|
||||||
@@ -0,0 +1,342 @@
|
|||||||
|
<script lang="ts">
|
||||||
|
import { apiFetch, apiMutate } from '$lib/api/client.js';
|
||||||
|
import type { AsEntry, BgpCommunity, ModuleRow } from '$lib/api/types.js';
|
||||||
|
import { formatDateTime } from '$lib/modules/display.js';
|
||||||
|
import {
|
||||||
|
communityLabel,
|
||||||
|
sanitizeFilenamePart,
|
||||||
|
supportsCsvIO
|
||||||
|
} from '$lib/components/modules/module-helpers.js';
|
||||||
|
|
||||||
|
import { Button } from '$lib/ui/core/button/index.js';
|
||||||
|
import { Checkbox } from '$lib/ui/core/checkbox/index.js';
|
||||||
|
import {
|
||||||
|
Card,
|
||||||
|
CardContent,
|
||||||
|
CardHeader,
|
||||||
|
CardTitle,
|
||||||
|
CardDescription
|
||||||
|
} from '$lib/ui/core/card/index.js';
|
||||||
|
import AppDataTable from '$lib/ui/patterns/data-table/app-data-table.svelte';
|
||||||
|
import { confirm } from '$lib/ui/patterns/confirm/confirm-state.svelte.js';
|
||||||
|
import { notify, notifyApiError } from '$lib/ui/app/toast.js';
|
||||||
|
import ModuleAsEntryDialog from '$lib/components/modules/ModuleAsEntryDialog.svelte';
|
||||||
|
import Plus from '@lucide/svelte/icons/plus';
|
||||||
|
import Pencil from '@lucide/svelte/icons/pencil';
|
||||||
|
import Trash2 from '@lucide/svelte/icons/trash-2';
|
||||||
|
import Upload from '@lucide/svelte/icons/upload';
|
||||||
|
import Download from '@lucide/svelte/icons/download';
|
||||||
|
|
||||||
|
type Props = {
|
||||||
|
moduleId: string;
|
||||||
|
mod: ModuleRow;
|
||||||
|
entries: AsEntry[];
|
||||||
|
communities: BgpCommunity[];
|
||||||
|
loading?: boolean;
|
||||||
|
onChanged: () => void | Promise<void>;
|
||||||
|
};
|
||||||
|
|
||||||
|
let { moduleId, mod, entries, communities, loading = false, onChanged }: Props = $props();
|
||||||
|
|
||||||
|
let dialogOpen = $state(false);
|
||||||
|
let editTarget = $state<AsEntry | null>(null);
|
||||||
|
let selectedIds = $state(new Set<string>());
|
||||||
|
let deletingBulk = $state(false);
|
||||||
|
let csvImporting = $state(false);
|
||||||
|
let csvExporting = $state(false);
|
||||||
|
let csvFileInput = $state<HTMLInputElement | null>(null);
|
||||||
|
|
||||||
|
const activeSelected = $derived.by(() => {
|
||||||
|
const allowed = new Set(entries.map((e) => e.id));
|
||||||
|
return [...selectedIds].filter((id) => allowed.has(id));
|
||||||
|
});
|
||||||
|
const selectedCount = $derived(activeSelected.length);
|
||||||
|
|
||||||
|
const allSelected = $derived(entries.length > 0 && entries.every((e) => selectedIds.has(e.id)));
|
||||||
|
|
||||||
|
const columns = [
|
||||||
|
{ id: 'select', label: '', class: 'w-10' },
|
||||||
|
{ id: 'asn', label: 'ASN', sortable: true, sortValue: (e: AsEntry) => e.asn },
|
||||||
|
{
|
||||||
|
id: 'name',
|
||||||
|
label: 'Название AS',
|
||||||
|
sortable: true,
|
||||||
|
sortValue: (e: AsEntry) => e.asn_name ?? ''
|
||||||
|
},
|
||||||
|
{
|
||||||
|
id: 'prefixes',
|
||||||
|
label: 'Префиксов',
|
||||||
|
sortable: true,
|
||||||
|
sortValue: (e: AsEntry) => e.prefix_count ?? 0,
|
||||||
|
class: 'text-right'
|
||||||
|
},
|
||||||
|
{
|
||||||
|
id: 'updated',
|
||||||
|
label: 'Обновлено',
|
||||||
|
sortable: true,
|
||||||
|
sortValue: (e: AsEntry) => e.asn_resolved_at ?? ''
|
||||||
|
},
|
||||||
|
{ id: 'community', label: 'Community' },
|
||||||
|
{ id: 'actions', label: '', class: 'w-20' }
|
||||||
|
] as const;
|
||||||
|
|
||||||
|
function toggleSelection(id: string) {
|
||||||
|
const next = new Set(selectedIds);
|
||||||
|
if (next.has(id)) next.delete(id);
|
||||||
|
else next.add(id);
|
||||||
|
selectedIds = next;
|
||||||
|
}
|
||||||
|
|
||||||
|
function toggleAll(checked: boolean) {
|
||||||
|
selectedIds = checked ? new Set(entries.map((e) => e.id)) : new Set<string>();
|
||||||
|
}
|
||||||
|
|
||||||
|
function openCreate() {
|
||||||
|
editTarget = null;
|
||||||
|
dialogOpen = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
function openEdit(entry: AsEntry) {
|
||||||
|
editTarget = entry;
|
||||||
|
dialogOpen = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
function requestDelete(entry: AsEntry) {
|
||||||
|
void confirm({
|
||||||
|
title: 'Удалить запись?',
|
||||||
|
description: `ASN: ${entry.asn}`,
|
||||||
|
confirmLabel: 'Удалить',
|
||||||
|
destructive: true,
|
||||||
|
onConfirm: async () => {
|
||||||
|
await apiMutate(`/v1/modules/${moduleId}/as-entries/${entry.id}`, 'DELETE', undefined, {
|
||||||
|
idempotent: false
|
||||||
|
});
|
||||||
|
notify.success('Удалено');
|
||||||
|
await onChanged();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
function requestBulkDelete() {
|
||||||
|
if (selectedCount === 0) return;
|
||||||
|
void confirm({
|
||||||
|
title: 'Удалить выбранные AS-записи?',
|
||||||
|
description: `Будет удалено: ${selectedCount}`,
|
||||||
|
confirmLabel: 'Удалить',
|
||||||
|
destructive: true,
|
||||||
|
onConfirm: bulkDelete
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
async function bulkDelete() {
|
||||||
|
if (selectedCount === 0) return;
|
||||||
|
deletingBulk = true;
|
||||||
|
let deleted = 0;
|
||||||
|
try {
|
||||||
|
for (const id of activeSelected) {
|
||||||
|
try {
|
||||||
|
await apiMutate(`/v1/modules/${moduleId}/as-entries/${id}`, 'DELETE', undefined, {
|
||||||
|
idempotent: false
|
||||||
|
});
|
||||||
|
deleted += 1;
|
||||||
|
} catch (e) {
|
||||||
|
notifyApiError(e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (deleted > 0) notify.success(`Удалено AS-записей: ${deleted}`);
|
||||||
|
await onChanged();
|
||||||
|
} finally {
|
||||||
|
deletingBulk = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
async function readErrorText(res: Response): Promise<string> {
|
||||||
|
const body = (await res.text()).trim();
|
||||||
|
return body || `HTTP ${res.status}`;
|
||||||
|
}
|
||||||
|
|
||||||
|
async function exportCsv() {
|
||||||
|
if (!supportsCsvIO(mod.type) || csvExporting) return;
|
||||||
|
csvExporting = true;
|
||||||
|
try {
|
||||||
|
const res = await apiFetch(`/v1/modules/${moduleId}/entries.csv`, {
|
||||||
|
method: 'GET',
|
||||||
|
headers: { Accept: 'text/csv' }
|
||||||
|
});
|
||||||
|
if (!res.ok) {
|
||||||
|
notify.error(await readErrorText(res));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
const blob = await res.blob();
|
||||||
|
const url = URL.createObjectURL(blob);
|
||||||
|
const a = document.createElement('a');
|
||||||
|
a.href = url;
|
||||||
|
a.download = `${sanitizeFilenamePart(mod.name)}-${mod.type.toLowerCase()}-entries.csv`;
|
||||||
|
document.body.appendChild(a);
|
||||||
|
a.click();
|
||||||
|
a.remove();
|
||||||
|
URL.revokeObjectURL(url);
|
||||||
|
} catch (e) {
|
||||||
|
notifyApiError(e);
|
||||||
|
} finally {
|
||||||
|
csvExporting = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function openImportPicker() {
|
||||||
|
if (!supportsCsvIO(mod.type) || csvImporting) return;
|
||||||
|
csvFileInput?.click();
|
||||||
|
}
|
||||||
|
|
||||||
|
async function handleImportChange(event: Event) {
|
||||||
|
const input = event.currentTarget as HTMLInputElement | null;
|
||||||
|
const file = input?.files?.[0];
|
||||||
|
if (!file || csvImporting) return;
|
||||||
|
csvImporting = true;
|
||||||
|
try {
|
||||||
|
const fileText = await file.text();
|
||||||
|
const res = await apiFetch(`/v1/modules/${moduleId}/entries.csv`, {
|
||||||
|
method: 'POST',
|
||||||
|
headers: { 'Content-Type': 'text/csv' },
|
||||||
|
body: fileText
|
||||||
|
});
|
||||||
|
if (!res.ok) {
|
||||||
|
notify.error(await readErrorText(res));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
const payload = (await res.json()) as { imported?: number };
|
||||||
|
notify.success(`Импортировано записей: ${payload.imported ?? 0}`);
|
||||||
|
await onChanged();
|
||||||
|
} catch (e) {
|
||||||
|
notifyApiError(e);
|
||||||
|
} finally {
|
||||||
|
csvImporting = false;
|
||||||
|
if (input) input.value = '';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<input
|
||||||
|
class="hidden"
|
||||||
|
type="file"
|
||||||
|
accept=".csv,text/csv"
|
||||||
|
bind:this={csvFileInput}
|
||||||
|
onchange={handleImportChange}
|
||||||
|
/>
|
||||||
|
|
||||||
|
<Card>
|
||||||
|
<CardHeader class="flex flex-col gap-3 pb-2 sm:flex-row sm:items-center sm:justify-between">
|
||||||
|
<div class="min-w-0 flex-1">
|
||||||
|
<CardTitle class="text-base">AS-записи</CardTitle>
|
||||||
|
<CardDescription>
|
||||||
|
Номер AS и community; имя, число префиксов и дата обновляются при успешном refresh
|
||||||
|
(RIPEstat).
|
||||||
|
</CardDescription>
|
||||||
|
</div>
|
||||||
|
<div class="flex shrink-0 flex-wrap items-center justify-end gap-2 self-start sm:self-auto">
|
||||||
|
<Button
|
||||||
|
variant="outline"
|
||||||
|
size="sm"
|
||||||
|
onclick={openImportPicker}
|
||||||
|
disabled={!supportsCsvIO(mod.type) || csvImporting || csvExporting}
|
||||||
|
>
|
||||||
|
<Upload />
|
||||||
|
{csvImporting ? 'Импорт…' : 'Импорт CSV'}
|
||||||
|
</Button>
|
||||||
|
<Button
|
||||||
|
variant="outline"
|
||||||
|
size="sm"
|
||||||
|
onclick={exportCsv}
|
||||||
|
disabled={!supportsCsvIO(mod.type) || csvExporting || csvImporting}
|
||||||
|
>
|
||||||
|
<Download />
|
||||||
|
{csvExporting ? 'Экспорт…' : 'Экспорт CSV'}
|
||||||
|
</Button>
|
||||||
|
<Button size="sm" onclick={openCreate}><Plus />Добавить</Button>
|
||||||
|
{#if selectedCount > 0}
|
||||||
|
<Button variant="destructive" size="sm" onclick={requestBulkDelete} disabled={deletingBulk}>
|
||||||
|
<Trash2 />
|
||||||
|
Удалить ({selectedCount})
|
||||||
|
</Button>
|
||||||
|
{/if}
|
||||||
|
</div>
|
||||||
|
</CardHeader>
|
||||||
|
<CardContent class="p-4 pt-0">
|
||||||
|
<AppDataTable
|
||||||
|
columns={[...columns]}
|
||||||
|
rows={entries}
|
||||||
|
rowKey={(e) => e.id}
|
||||||
|
{loading}
|
||||||
|
emptyTitle="Нет AS-записей"
|
||||||
|
emptyDescription="Добавьте ASN или импортируйте CSV."
|
||||||
|
>
|
||||||
|
{#snippet toolbar()}
|
||||||
|
{#if entries.length > 0}
|
||||||
|
<div class="flex items-center gap-2">
|
||||||
|
<Checkbox
|
||||||
|
checked={allSelected}
|
||||||
|
onCheckedChange={(v) => toggleAll(v === true)}
|
||||||
|
aria-label="Выбрать все AS-записи"
|
||||||
|
/>
|
||||||
|
<span class="text-sm text-muted-foreground">Выбрать все</span>
|
||||||
|
</div>
|
||||||
|
{/if}
|
||||||
|
{/snippet}
|
||||||
|
{#snippet cell({ row: entry, column })}
|
||||||
|
{#if column.id === 'select'}
|
||||||
|
<Checkbox
|
||||||
|
checked={selectedIds.has(entry.id)}
|
||||||
|
aria-label={`Выбрать AS ${entry.asn}`}
|
||||||
|
onCheckedChange={() => toggleSelection(entry.id)}
|
||||||
|
/>
|
||||||
|
{:else if column.id === 'asn'}
|
||||||
|
<span class="font-mono">{entry.asn}</span>
|
||||||
|
{:else if column.id === 'name'}
|
||||||
|
<span
|
||||||
|
class="max-w-[14rem] truncate text-sm text-muted-foreground"
|
||||||
|
title={entry.asn_name ?? ''}
|
||||||
|
>
|
||||||
|
{entry.asn_name?.trim() ? entry.asn_name : '—'}
|
||||||
|
</span>
|
||||||
|
{:else if column.id === 'prefixes'}
|
||||||
|
<span class="font-mono text-sm">
|
||||||
|
{entry.prefix_count != null ? entry.prefix_count : '—'}
|
||||||
|
</span>
|
||||||
|
{:else if column.id === 'updated'}
|
||||||
|
<span class="text-sm whitespace-nowrap text-muted-foreground">
|
||||||
|
{formatDateTime(entry.asn_resolved_at)}
|
||||||
|
</span>
|
||||||
|
{:else if column.id === 'community'}
|
||||||
|
<span class="text-sm text-muted-foreground">
|
||||||
|
{communityLabel(entry.community_id, communities)}
|
||||||
|
</span>
|
||||||
|
{:else if column.id === 'actions'}
|
||||||
|
<div class="flex gap-1">
|
||||||
|
<Button variant="ghost" size="icon-sm" onclick={() => openEdit(entry)}>
|
||||||
|
<Pencil class="size-3.5" />
|
||||||
|
</Button>
|
||||||
|
<Button
|
||||||
|
variant="ghost"
|
||||||
|
size="icon-sm"
|
||||||
|
class="text-destructive"
|
||||||
|
onclick={() => requestDelete(entry)}
|
||||||
|
>
|
||||||
|
<Trash2 class="size-3.5" />
|
||||||
|
</Button>
|
||||||
|
</div>
|
||||||
|
{/if}
|
||||||
|
{/snippet}
|
||||||
|
</AppDataTable>
|
||||||
|
</CardContent>
|
||||||
|
</Card>
|
||||||
|
|
||||||
|
<ModuleAsEntryDialog
|
||||||
|
bind:open={dialogOpen}
|
||||||
|
{moduleId}
|
||||||
|
edit={editTarget}
|
||||||
|
{communities}
|
||||||
|
onSaved={onChanged}
|
||||||
|
onClose={() => {
|
||||||
|
editTarget = null;
|
||||||
|
}}
|
||||||
|
/>
|
||||||
@@ -0,0 +1,137 @@
|
|||||||
|
<script lang="ts">
|
||||||
|
import { apiMutate } from '$lib/api/client.js';
|
||||||
|
import type { AsEntry, AsEntryCreate, AsEntryPatch, BgpCommunity } from '$lib/api/types.js';
|
||||||
|
import {
|
||||||
|
communityLabel,
|
||||||
|
communityOptionLabel,
|
||||||
|
fromNullableSelect,
|
||||||
|
NONE_OPTION,
|
||||||
|
nullableSelectValue
|
||||||
|
} from '$lib/components/modules/module-helpers.js';
|
||||||
|
import { Button } from '$lib/ui/core/button/index.js';
|
||||||
|
import { Input } from '$lib/ui/core/input/index.js';
|
||||||
|
import { Label } from '$lib/ui/core/label/index.js';
|
||||||
|
import {
|
||||||
|
Dialog,
|
||||||
|
DialogContent,
|
||||||
|
DialogHeader,
|
||||||
|
DialogTitle,
|
||||||
|
DialogFooter,
|
||||||
|
DialogDescription
|
||||||
|
} from '$lib/ui/core/dialog/index.js';
|
||||||
|
import { Select, SelectContent, SelectItem, SelectTrigger } from '$lib/ui/core/select/index.js';
|
||||||
|
import { notify, notifyApiError } from '$lib/ui/app/toast.js';
|
||||||
|
|
||||||
|
type Props = {
|
||||||
|
open: boolean;
|
||||||
|
moduleId: string;
|
||||||
|
edit: AsEntry | null;
|
||||||
|
communities: BgpCommunity[];
|
||||||
|
onSaved: () => void | Promise<void>;
|
||||||
|
onClose: () => void;
|
||||||
|
};
|
||||||
|
|
||||||
|
let { open = $bindable(), moduleId, edit, communities, onSaved, onClose }: Props = $props();
|
||||||
|
|
||||||
|
let saving = $state(false);
|
||||||
|
let form = $state<AsEntryCreate>({ asn: 0, community_id: null });
|
||||||
|
let initKey = $state('');
|
||||||
|
|
||||||
|
function resetForm() {
|
||||||
|
form = edit
|
||||||
|
? { asn: edit.asn, community_id: edit.community_id }
|
||||||
|
: { asn: 0, community_id: null };
|
||||||
|
}
|
||||||
|
|
||||||
|
$effect(() => {
|
||||||
|
if (!open) {
|
||||||
|
initKey = '';
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
const nextKey = edit?.id ?? 'new';
|
||||||
|
if (nextKey !== initKey) {
|
||||||
|
initKey = nextKey;
|
||||||
|
resetForm();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
async function save() {
|
||||||
|
const asn = Number(form.asn);
|
||||||
|
if (!Number.isFinite(asn) || asn < 1 || asn > 4294967295) {
|
||||||
|
notify.error('Укажите корректный ASN (1–4294967295)');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
saving = true;
|
||||||
|
try {
|
||||||
|
const body: AsEntryCreate | AsEntryPatch = { asn, community_id: form.community_id };
|
||||||
|
if (edit) {
|
||||||
|
await apiMutate(`/v1/modules/${moduleId}/as-entries/${edit.id}`, 'PATCH', body);
|
||||||
|
notify.success('Запись обновлена');
|
||||||
|
} else {
|
||||||
|
await apiMutate(`/v1/modules/${moduleId}/as-entries`, 'POST', body as AsEntryCreate);
|
||||||
|
notify.success('Запись добавлена');
|
||||||
|
}
|
||||||
|
open = false;
|
||||||
|
await onSaved();
|
||||||
|
} catch (e) {
|
||||||
|
notifyApiError(e);
|
||||||
|
} finally {
|
||||||
|
saving = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function handleOpenChange(next: boolean) {
|
||||||
|
open = next;
|
||||||
|
if (!next) onClose();
|
||||||
|
}
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<Dialog bind:open onOpenChange={handleOpenChange}>
|
||||||
|
<DialogContent class="sm:max-w-sm">
|
||||||
|
<DialogHeader>
|
||||||
|
<DialogTitle>{edit ? 'Редактировать запись' : 'Новая AS-запись'}</DialogTitle>
|
||||||
|
<DialogDescription>
|
||||||
|
Номер автономной системы и community для политики анонса.
|
||||||
|
</DialogDescription>
|
||||||
|
</DialogHeader>
|
||||||
|
<div class="space-y-4 py-2">
|
||||||
|
<div class="space-y-1.5">
|
||||||
|
<Label for="as-asn">ASN</Label>
|
||||||
|
<Input
|
||||||
|
id="as-asn"
|
||||||
|
type="number"
|
||||||
|
placeholder="12345"
|
||||||
|
bind:value={form.asn}
|
||||||
|
min={1}
|
||||||
|
max={4294967295}
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
<div class="space-y-1.5">
|
||||||
|
<Label for="as-comm">Community</Label>
|
||||||
|
<Select
|
||||||
|
type="single"
|
||||||
|
value={nullableSelectValue(form.community_id)}
|
||||||
|
onValueChange={(v) => {
|
||||||
|
form.community_id = fromNullableSelect(v);
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
<SelectTrigger id="as-comm" class="w-full">
|
||||||
|
{form.community_id ? communityLabel(form.community_id, communities) : 'Не выбрано'}
|
||||||
|
</SelectTrigger>
|
||||||
|
<SelectContent>
|
||||||
|
<SelectItem value={NONE_OPTION}>Не выбрано</SelectItem>
|
||||||
|
{#each communities as c (c.id)}
|
||||||
|
<SelectItem value={c.id}>{communityOptionLabel(c)}</SelectItem>
|
||||||
|
{/each}
|
||||||
|
</SelectContent>
|
||||||
|
</Select>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<DialogFooter>
|
||||||
|
<Button variant="outline" onclick={() => handleOpenChange(false)}>Отмена</Button>
|
||||||
|
<Button onclick={save} disabled={saving}>
|
||||||
|
{saving ? 'Сохранение…' : edit ? 'Сохранить' : 'Добавить'}
|
||||||
|
</Button>
|
||||||
|
</DialogFooter>
|
||||||
|
</DialogContent>
|
||||||
|
</Dialog>
|
||||||
@@ -0,0 +1,270 @@
|
|||||||
|
<script lang="ts">
|
||||||
|
import { apiMutate } from '$lib/api/client.js';
|
||||||
|
import type {
|
||||||
|
BgpCommunity,
|
||||||
|
CdnPreviewResponse,
|
||||||
|
CdnSource,
|
||||||
|
CdnSourceCreate
|
||||||
|
} from '$lib/api/types.js';
|
||||||
|
import {
|
||||||
|
communityLabel,
|
||||||
|
communityOptionLabel,
|
||||||
|
fromNullableSelect,
|
||||||
|
normalizeCdnSourceKind,
|
||||||
|
NONE_OPTION,
|
||||||
|
nullableSelectValue
|
||||||
|
} from '$lib/components/modules/module-helpers.js';
|
||||||
|
import { Button } from '$lib/ui/core/button/index.js';
|
||||||
|
import { Input } from '$lib/ui/core/input/index.js';
|
||||||
|
import { Label } from '$lib/ui/core/label/index.js';
|
||||||
|
import {
|
||||||
|
Dialog,
|
||||||
|
DialogContent,
|
||||||
|
DialogHeader,
|
||||||
|
DialogTitle,
|
||||||
|
DialogFooter
|
||||||
|
} from '$lib/ui/core/dialog/index.js';
|
||||||
|
import { Select, SelectContent, SelectItem, SelectTrigger } from '$lib/ui/core/select/index.js';
|
||||||
|
import { notify, notifyApiError } from '$lib/ui/app/toast.js';
|
||||||
|
|
||||||
|
type Props = {
|
||||||
|
open: boolean;
|
||||||
|
moduleId: string;
|
||||||
|
edit: CdnSource | null;
|
||||||
|
communities: BgpCommunity[];
|
||||||
|
onSaved: () => void | Promise<void>;
|
||||||
|
onClose: () => void;
|
||||||
|
};
|
||||||
|
|
||||||
|
let { open = $bindable(), moduleId, edit, communities, onSaved, onClose }: Props = $props();
|
||||||
|
|
||||||
|
let saving = $state(false);
|
||||||
|
let previewLoading = $state(false);
|
||||||
|
let previewItems = $state<string[]>([]);
|
||||||
|
let previewTotal = $state(0);
|
||||||
|
let previewTruncated = $state(false);
|
||||||
|
let previewError = $state<string | null>(null);
|
||||||
|
let previewOk = $state(false);
|
||||||
|
let form = $state<CdnSourceCreate & { refresh_interval_sec?: number | null }>({
|
||||||
|
url: '',
|
||||||
|
source_kind: 'plaintext',
|
||||||
|
prefix_path: '',
|
||||||
|
community_id: null
|
||||||
|
});
|
||||||
|
let initKey = $state('');
|
||||||
|
|
||||||
|
function clearPreview() {
|
||||||
|
previewLoading = false;
|
||||||
|
previewItems = [];
|
||||||
|
previewTotal = 0;
|
||||||
|
previewTruncated = false;
|
||||||
|
previewError = null;
|
||||||
|
previewOk = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
function resetForm() {
|
||||||
|
clearPreview();
|
||||||
|
form = edit
|
||||||
|
? {
|
||||||
|
url: edit.url,
|
||||||
|
source_kind: normalizeCdnSourceKind(edit.source_kind),
|
||||||
|
prefix_path: edit.prefix_path ?? '',
|
||||||
|
community_id: edit.community_id,
|
||||||
|
refresh_interval_sec: edit.refresh_interval_sec
|
||||||
|
}
|
||||||
|
: { url: '', source_kind: 'plaintext', prefix_path: '', community_id: null };
|
||||||
|
}
|
||||||
|
|
||||||
|
$effect(() => {
|
||||||
|
if (!open) {
|
||||||
|
initKey = '';
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
const nextKey = edit?.id ?? 'new';
|
||||||
|
if (nextKey !== initKey) {
|
||||||
|
initKey = nextKey;
|
||||||
|
resetForm();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
async function previewCdn() {
|
||||||
|
const urlTrim = form.url.trim();
|
||||||
|
if (!urlTrim) {
|
||||||
|
notify.error('Укажите URL');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
previewLoading = true;
|
||||||
|
previewError = null;
|
||||||
|
previewOk = false;
|
||||||
|
try {
|
||||||
|
const res = await apiMutate<CdnPreviewResponse>(
|
||||||
|
`/v1/modules/${moduleId}/cdn-sources/preview`,
|
||||||
|
'POST',
|
||||||
|
{
|
||||||
|
url: urlTrim,
|
||||||
|
source_kind: form.source_kind,
|
||||||
|
prefix_path: form.prefix_path?.trim() ?? ''
|
||||||
|
}
|
||||||
|
);
|
||||||
|
previewItems = res.items;
|
||||||
|
previewTotal = res.total;
|
||||||
|
previewTruncated = res.truncated;
|
||||||
|
previewOk = true;
|
||||||
|
} catch (e) {
|
||||||
|
previewError = e instanceof Error ? e.message : String(e);
|
||||||
|
previewItems = [];
|
||||||
|
previewTotal = 0;
|
||||||
|
previewTruncated = false;
|
||||||
|
previewOk = false;
|
||||||
|
} finally {
|
||||||
|
previewLoading = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
async function save() {
|
||||||
|
const urlTrim = form.url.trim();
|
||||||
|
if (!urlTrim) {
|
||||||
|
notify.error('Укажите URL');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
saving = true;
|
||||||
|
try {
|
||||||
|
const body = {
|
||||||
|
...form,
|
||||||
|
url: urlTrim,
|
||||||
|
source_kind: form.source_kind,
|
||||||
|
prefix_path: form.prefix_path?.trim() ?? ''
|
||||||
|
};
|
||||||
|
if (edit) {
|
||||||
|
await apiMutate(`/v1/modules/${moduleId}/cdn-sources/${edit.id}`, 'PATCH', body);
|
||||||
|
notify.success('Источник обновлён');
|
||||||
|
} else {
|
||||||
|
await apiMutate(`/v1/modules/${moduleId}/cdn-sources`, 'POST', body);
|
||||||
|
notify.success('Источник добавлен');
|
||||||
|
}
|
||||||
|
clearPreview();
|
||||||
|
open = false;
|
||||||
|
await onSaved();
|
||||||
|
} catch (e) {
|
||||||
|
notifyApiError(e);
|
||||||
|
} finally {
|
||||||
|
saving = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function handleOpenChange(next: boolean) {
|
||||||
|
open = next;
|
||||||
|
if (!next) {
|
||||||
|
clearPreview();
|
||||||
|
onClose();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<Dialog bind:open onOpenChange={handleOpenChange}>
|
||||||
|
<DialogContent class="sm:max-w-lg">
|
||||||
|
<DialogHeader>
|
||||||
|
<DialogTitle>{edit ? 'Редактировать источник' : 'Новый CDN-источник'}</DialogTitle>
|
||||||
|
</DialogHeader>
|
||||||
|
<div class="space-y-4 py-2">
|
||||||
|
<div class="space-y-1.5">
|
||||||
|
<Label for="cdn-url">URL</Label>
|
||||||
|
<Input id="cdn-url" placeholder="https://example.com/list.txt" bind:value={form.url} />
|
||||||
|
</div>
|
||||||
|
<div class="space-y-1.5">
|
||||||
|
<Label for="cdn-kind">Тип источника</Label>
|
||||||
|
<Select
|
||||||
|
type="single"
|
||||||
|
value={form.source_kind}
|
||||||
|
onValueChange={(v) => {
|
||||||
|
form.source_kind = v || 'plaintext';
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
<SelectTrigger id="cdn-kind" class="w-full">
|
||||||
|
{form.source_kind === 'json' ? 'json' : 'plaintext'}
|
||||||
|
</SelectTrigger>
|
||||||
|
<SelectContent>
|
||||||
|
<SelectItem value="plaintext">plaintext</SelectItem>
|
||||||
|
<SelectItem value="json">json</SelectItem>
|
||||||
|
</SelectContent>
|
||||||
|
</Select>
|
||||||
|
</div>
|
||||||
|
<div class="space-y-1.5">
|
||||||
|
<Label for="cdn-prefix-path">JSON path (prefix_path)</Label>
|
||||||
|
<Input
|
||||||
|
id="cdn-prefix-path"
|
||||||
|
placeholder="напр. prefixes[] или data.items[].cidr"
|
||||||
|
bind:value={form.prefix_path}
|
||||||
|
/>
|
||||||
|
{#if form.source_kind === 'json' && !form.prefix_path?.trim()}
|
||||||
|
<p class="text-xs text-muted-foreground">
|
||||||
|
Для JSON укажите путь к полям с CIDR; пустой путь может не дать префиксов.
|
||||||
|
</p>
|
||||||
|
{/if}
|
||||||
|
</div>
|
||||||
|
<div class="space-y-1.5">
|
||||||
|
<Label for="cdn-comm">Community</Label>
|
||||||
|
<Select
|
||||||
|
type="single"
|
||||||
|
value={nullableSelectValue(form.community_id)}
|
||||||
|
onValueChange={(v) => {
|
||||||
|
form.community_id = fromNullableSelect(v);
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
<SelectTrigger id="cdn-comm" class="w-full">
|
||||||
|
{form.community_id ? communityLabel(form.community_id, communities) : 'Не выбрано'}
|
||||||
|
</SelectTrigger>
|
||||||
|
<SelectContent>
|
||||||
|
<SelectItem value={NONE_OPTION}>Не выбрано</SelectItem>
|
||||||
|
{#each communities as c (c.id)}
|
||||||
|
<SelectItem value={c.id}>{communityOptionLabel(c)}</SelectItem>
|
||||||
|
{/each}
|
||||||
|
</SelectContent>
|
||||||
|
</Select>
|
||||||
|
</div>
|
||||||
|
<div class="space-y-1.5">
|
||||||
|
<Label for="cdn-interval">Интервал обновления (сек)</Label>
|
||||||
|
<Input
|
||||||
|
id="cdn-interval"
|
||||||
|
type="number"
|
||||||
|
placeholder="3600"
|
||||||
|
bind:value={form.refresh_interval_sec}
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
<div class="flex flex-col gap-2 rounded-lg border border-border p-3">
|
||||||
|
<div class="flex flex-wrap items-center gap-2">
|
||||||
|
<Button
|
||||||
|
type="button"
|
||||||
|
variant="secondary"
|
||||||
|
size="sm"
|
||||||
|
onclick={previewCdn}
|
||||||
|
disabled={previewLoading}
|
||||||
|
>
|
||||||
|
{previewLoading ? 'Загрузка…' : 'Предпросмотр'}
|
||||||
|
</Button>
|
||||||
|
{#if previewError}
|
||||||
|
<span class="text-sm text-destructive">{previewError}</span>
|
||||||
|
{:else if previewOk}
|
||||||
|
<span class="text-sm text-muted-foreground">
|
||||||
|
Всего: {previewTotal}{#if previewTruncated}
|
||||||
|
<span class="text-amber-600 dark:text-amber-500"> (обрезано)</span>{/if}
|
||||||
|
</span>
|
||||||
|
{/if}
|
||||||
|
</div>
|
||||||
|
{#if previewItems.length}
|
||||||
|
<ul class="max-h-48 overflow-y-auto rounded-md border bg-muted/40 p-2 font-mono text-xs">
|
||||||
|
{#each previewItems as item, i (`${i}-${item}`)}
|
||||||
|
<li class="py-0.5">{item}</li>
|
||||||
|
{/each}
|
||||||
|
</ul>
|
||||||
|
{/if}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<DialogFooter>
|
||||||
|
<Button variant="outline" onclick={() => handleOpenChange(false)}>Отмена</Button>
|
||||||
|
<Button onclick={save} disabled={saving}>
|
||||||
|
{saving ? 'Сохранение…' : edit ? 'Сохранить' : 'Добавить'}
|
||||||
|
</Button>
|
||||||
|
</DialogFooter>
|
||||||
|
</DialogContent>
|
||||||
|
</Dialog>
|
||||||
@@ -0,0 +1,237 @@
|
|||||||
|
<script lang="ts">
|
||||||
|
import { apiMutate } from '$lib/api/client.js';
|
||||||
|
import type { BgpCommunity, CdnSource } from '$lib/api/types.js';
|
||||||
|
import { formatDateTime } from '$lib/modules/display.js';
|
||||||
|
import {
|
||||||
|
communityLabel,
|
||||||
|
normalizeCdnSourceKind
|
||||||
|
} from '$lib/components/modules/module-helpers.js';
|
||||||
|
import { Badge } from '$lib/ui/core/badge/index.js';
|
||||||
|
import { Button } from '$lib/ui/core/button/index.js';
|
||||||
|
import { Checkbox } from '$lib/ui/core/checkbox/index.js';
|
||||||
|
import {
|
||||||
|
Card,
|
||||||
|
CardContent,
|
||||||
|
CardHeader,
|
||||||
|
CardTitle,
|
||||||
|
CardDescription
|
||||||
|
} from '$lib/ui/core/card/index.js';
|
||||||
|
import AppDataTable from '$lib/ui/patterns/data-table/app-data-table.svelte';
|
||||||
|
import { confirm } from '$lib/ui/patterns/confirm/confirm-state.svelte.js';
|
||||||
|
import { notify, notifyApiError } from '$lib/ui/app/toast.js';
|
||||||
|
import ModuleCdnSourceDialog from '$lib/components/modules/ModuleCdnSourceDialog.svelte';
|
||||||
|
import Plus from '@lucide/svelte/icons/plus';
|
||||||
|
import Pencil from '@lucide/svelte/icons/pencil';
|
||||||
|
import Trash2 from '@lucide/svelte/icons/trash-2';
|
||||||
|
|
||||||
|
type Props = {
|
||||||
|
moduleId: string;
|
||||||
|
sources: CdnSource[];
|
||||||
|
communities: BgpCommunity[];
|
||||||
|
loading?: boolean;
|
||||||
|
onChanged: () => void | Promise<void>;
|
||||||
|
};
|
||||||
|
|
||||||
|
let { moduleId, sources, communities, loading = false, onChanged }: Props = $props();
|
||||||
|
|
||||||
|
let dialogOpen = $state(false);
|
||||||
|
let editTarget = $state<CdnSource | null>(null);
|
||||||
|
let selectedIds = $state(new Set<string>());
|
||||||
|
let deletingBulk = $state(false);
|
||||||
|
|
||||||
|
const activeSelected = $derived.by(() => {
|
||||||
|
const allowed = new Set(sources.map((s) => s.id));
|
||||||
|
return [...selectedIds].filter((id) => allowed.has(id));
|
||||||
|
});
|
||||||
|
const selectedCount = $derived(activeSelected.length);
|
||||||
|
const allSelected = $derived(sources.length > 0 && sources.every((s) => selectedIds.has(s.id)));
|
||||||
|
|
||||||
|
const columns = [
|
||||||
|
{ id: 'select', label: '', class: 'w-10' },
|
||||||
|
{ id: 'url', label: 'URL', sortable: true, sortValue: (s: CdnSource) => s.url },
|
||||||
|
{ id: 'kind', label: 'Тип', sortable: true, sortValue: (s: CdnSource) => s.source_kind },
|
||||||
|
{ id: 'community', label: 'Community' },
|
||||||
|
{
|
||||||
|
id: 'interval',
|
||||||
|
label: 'Интервал',
|
||||||
|
sortable: true,
|
||||||
|
sortValue: (s: CdnSource) => s.refresh_interval_sec ?? 0
|
||||||
|
},
|
||||||
|
{
|
||||||
|
id: 'refreshed',
|
||||||
|
label: 'Последнее обновление',
|
||||||
|
sortable: true,
|
||||||
|
sortValue: (s: CdnSource) => s.last_refreshed_at ?? ''
|
||||||
|
},
|
||||||
|
{ id: 'actions', label: '', class: 'w-20' }
|
||||||
|
] as const;
|
||||||
|
|
||||||
|
function toggleSelection(id: string) {
|
||||||
|
const next = new Set(selectedIds);
|
||||||
|
if (next.has(id)) next.delete(id);
|
||||||
|
else next.add(id);
|
||||||
|
selectedIds = next;
|
||||||
|
}
|
||||||
|
|
||||||
|
function toggleAll(checked: boolean) {
|
||||||
|
selectedIds = checked ? new Set(sources.map((s) => s.id)) : new Set<string>();
|
||||||
|
}
|
||||||
|
|
||||||
|
function openCreate() {
|
||||||
|
editTarget = null;
|
||||||
|
dialogOpen = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
function openEdit(src: CdnSource) {
|
||||||
|
editTarget = src;
|
||||||
|
dialogOpen = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
function requestDelete(src: CdnSource) {
|
||||||
|
void confirm({
|
||||||
|
title: 'Удалить CDN-источник?',
|
||||||
|
description: src.url,
|
||||||
|
confirmLabel: 'Удалить',
|
||||||
|
destructive: true,
|
||||||
|
onConfirm: async () => {
|
||||||
|
await apiMutate(`/v1/modules/${moduleId}/cdn-sources/${src.id}`, 'DELETE', undefined, {
|
||||||
|
idempotent: false
|
||||||
|
});
|
||||||
|
notify.success('Удалено');
|
||||||
|
await onChanged();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
function requestBulkDelete() {
|
||||||
|
if (selectedCount === 0) return;
|
||||||
|
void confirm({
|
||||||
|
title: 'Удалить выбранные CDN-источники?',
|
||||||
|
description: `Будет удалено: ${selectedCount}`,
|
||||||
|
confirmLabel: 'Удалить',
|
||||||
|
destructive: true,
|
||||||
|
onConfirm: bulkDelete
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
async function bulkDelete() {
|
||||||
|
if (selectedCount === 0) return;
|
||||||
|
deletingBulk = true;
|
||||||
|
let deleted = 0;
|
||||||
|
try {
|
||||||
|
for (const id of activeSelected) {
|
||||||
|
try {
|
||||||
|
await apiMutate(`/v1/modules/${moduleId}/cdn-sources/${id}`, 'DELETE', undefined, {
|
||||||
|
idempotent: false
|
||||||
|
});
|
||||||
|
deleted += 1;
|
||||||
|
} catch (e) {
|
||||||
|
notifyApiError(e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (deleted > 0) notify.success(`Удалено CDN-источников: ${deleted}`);
|
||||||
|
await onChanged();
|
||||||
|
} finally {
|
||||||
|
deletingBulk = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<Card>
|
||||||
|
<CardHeader class="flex flex-col gap-3 pb-2 sm:flex-row sm:items-center sm:justify-between">
|
||||||
|
<div class="min-w-0 flex-1">
|
||||||
|
<CardTitle class="text-base">CDN-источники</CardTitle>
|
||||||
|
<CardDescription>URL источников для скачивания списков CIDR.</CardDescription>
|
||||||
|
</div>
|
||||||
|
<div class="flex shrink-0 flex-wrap items-center justify-end gap-2 self-start sm:self-auto">
|
||||||
|
<Button size="sm" onclick={openCreate}><Plus />Добавить</Button>
|
||||||
|
{#if selectedCount > 0}
|
||||||
|
<Button variant="destructive" size="sm" onclick={requestBulkDelete} disabled={deletingBulk}>
|
||||||
|
<Trash2 />
|
||||||
|
Удалить ({selectedCount})
|
||||||
|
</Button>
|
||||||
|
{/if}
|
||||||
|
</div>
|
||||||
|
</CardHeader>
|
||||||
|
<CardContent class="p-4 pt-0">
|
||||||
|
<AppDataTable
|
||||||
|
columns={[...columns]}
|
||||||
|
rows={sources}
|
||||||
|
rowKey={(s) => s.id}
|
||||||
|
{loading}
|
||||||
|
emptyTitle="Нет CDN-источников"
|
||||||
|
emptyDescription="Добавьте URL для загрузки списков CIDR."
|
||||||
|
>
|
||||||
|
{#snippet toolbar()}
|
||||||
|
{#if sources.length > 0}
|
||||||
|
<div class="flex items-center gap-2">
|
||||||
|
<Checkbox
|
||||||
|
checked={allSelected}
|
||||||
|
onCheckedChange={(v) => toggleAll(v === true)}
|
||||||
|
aria-label="Выбрать все CDN-источники"
|
||||||
|
/>
|
||||||
|
<span class="text-sm text-muted-foreground">Выбрать все</span>
|
||||||
|
</div>
|
||||||
|
{/if}
|
||||||
|
{/snippet}
|
||||||
|
{#snippet cell({ row: src, column })}
|
||||||
|
{#if column.id === 'select'}
|
||||||
|
<Checkbox
|
||||||
|
checked={selectedIds.has(src.id)}
|
||||||
|
aria-label="Выбрать CDN-источник"
|
||||||
|
onCheckedChange={() => toggleSelection(src.id)}
|
||||||
|
/>
|
||||||
|
{:else if column.id === 'url'}
|
||||||
|
<span class="max-w-xs truncate font-mono text-xs" title={src.url}>{src.url}</span>
|
||||||
|
{:else if column.id === 'kind'}
|
||||||
|
<div class="flex flex-col gap-0.5">
|
||||||
|
<Badge variant="outline">{normalizeCdnSourceKind(src.source_kind)}</Badge>
|
||||||
|
{#if src.prefix_path?.trim()}
|
||||||
|
<span
|
||||||
|
class="font-mono text-xs break-all text-muted-foreground"
|
||||||
|
title={src.prefix_path}>{src.prefix_path}</span
|
||||||
|
>
|
||||||
|
{/if}
|
||||||
|
</div>
|
||||||
|
{:else if column.id === 'community'}
|
||||||
|
<span class="text-sm text-muted-foreground">
|
||||||
|
{communityLabel(src.community_id, communities)}
|
||||||
|
</span>
|
||||||
|
{:else if column.id === 'interval'}
|
||||||
|
<span class="text-sm text-muted-foreground">
|
||||||
|
{src.refresh_interval_sec != null ? `${src.refresh_interval_sec}с` : '—'}
|
||||||
|
</span>
|
||||||
|
{:else if column.id === 'refreshed'}
|
||||||
|
<span class="text-sm whitespace-nowrap text-muted-foreground">
|
||||||
|
{formatDateTime(src.last_refreshed_at)}
|
||||||
|
</span>
|
||||||
|
{:else if column.id === 'actions'}
|
||||||
|
<div class="flex gap-1">
|
||||||
|
<Button variant="ghost" size="icon-sm" onclick={() => openEdit(src)}>
|
||||||
|
<Pencil class="size-3.5" />
|
||||||
|
</Button>
|
||||||
|
<Button
|
||||||
|
variant="ghost"
|
||||||
|
size="icon-sm"
|
||||||
|
class="text-destructive"
|
||||||
|
onclick={() => requestDelete(src)}
|
||||||
|
>
|
||||||
|
<Trash2 class="size-3.5" />
|
||||||
|
</Button>
|
||||||
|
</div>
|
||||||
|
{/if}
|
||||||
|
{/snippet}
|
||||||
|
</AppDataTable>
|
||||||
|
</CardContent>
|
||||||
|
</Card>
|
||||||
|
|
||||||
|
<ModuleCdnSourceDialog
|
||||||
|
bind:open={dialogOpen}
|
||||||
|
{moduleId}
|
||||||
|
edit={editTarget}
|
||||||
|
{communities}
|
||||||
|
onSaved={onChanged}
|
||||||
|
onClose={() => {
|
||||||
|
editTarget = null;
|
||||||
|
}}
|
||||||
|
/>
|
||||||
@@ -0,0 +1,144 @@
|
|||||||
|
<script lang="ts">
|
||||||
|
import { apiMutate } from '$lib/api/client.js';
|
||||||
|
import type { ModuleCreate } from '$lib/api/types.js';
|
||||||
|
import { moduleTypeRu } from '$lib/ui-labels.js';
|
||||||
|
import { Button } from '$lib/ui/core/button/index.js';
|
||||||
|
import { Input } from '$lib/ui/core/input/index.js';
|
||||||
|
import { Label } from '$lib/ui/core/label/index.js';
|
||||||
|
import {
|
||||||
|
Dialog,
|
||||||
|
DialogContent,
|
||||||
|
DialogHeader,
|
||||||
|
DialogTitle,
|
||||||
|
DialogFooter,
|
||||||
|
DialogDescription
|
||||||
|
} from '$lib/ui/core/dialog/index.js';
|
||||||
|
import { Select, SelectContent, SelectItem, SelectTrigger } from '$lib/ui/core/select/index.js';
|
||||||
|
import { Switch } from '$lib/ui/core/switch/index.js';
|
||||||
|
import { notify, notifyApiError } from '$lib/ui/app/toast.js';
|
||||||
|
|
||||||
|
type Props = {
|
||||||
|
open: boolean;
|
||||||
|
onClose: () => void;
|
||||||
|
onCreated: () => void | Promise<void>;
|
||||||
|
};
|
||||||
|
|
||||||
|
let { open = $bindable(), onClose, onCreated }: Props = $props();
|
||||||
|
|
||||||
|
let saving = $state(false);
|
||||||
|
let form = $state<ModuleCreate>({
|
||||||
|
type: 'AS_PREFIXES',
|
||||||
|
name: '',
|
||||||
|
enabled: true,
|
||||||
|
priority: 0
|
||||||
|
});
|
||||||
|
|
||||||
|
const moduleTypes = [
|
||||||
|
{ value: 'AS_PREFIXES', label: moduleTypeRu('AS_PREFIXES') },
|
||||||
|
{ value: 'CDN_CIDRS', label: moduleTypeRu('CDN_CIDRS') },
|
||||||
|
{ value: 'DOMAINS', label: moduleTypeRu('DOMAINS') },
|
||||||
|
{ value: 'IP_RANGES', label: moduleTypeRu('IP_RANGES') }
|
||||||
|
] as const;
|
||||||
|
|
||||||
|
function resetForm() {
|
||||||
|
form = { type: 'AS_PREFIXES', name: '', enabled: true, priority: 0 };
|
||||||
|
}
|
||||||
|
|
||||||
|
async function create() {
|
||||||
|
if (!form.name.trim()) {
|
||||||
|
notify.error('Укажите название модуля');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
saving = true;
|
||||||
|
try {
|
||||||
|
await apiMutate('/v1/modules', 'POST', form);
|
||||||
|
notify.success('Модуль создан');
|
||||||
|
open = false;
|
||||||
|
resetForm();
|
||||||
|
await onCreated();
|
||||||
|
} catch (e) {
|
||||||
|
notifyApiError(e);
|
||||||
|
} finally {
|
||||||
|
saving = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function handleOpenChange(next: boolean) {
|
||||||
|
open = next;
|
||||||
|
if (!next) {
|
||||||
|
onClose();
|
||||||
|
resetForm();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<Dialog bind:open onOpenChange={handleOpenChange}>
|
||||||
|
<DialogContent class="sm:max-w-md">
|
||||||
|
<DialogHeader>
|
||||||
|
<DialogTitle>Новый модуль</DialogTitle>
|
||||||
|
<DialogDescription>Создание нового модуля префиксов.</DialogDescription>
|
||||||
|
</DialogHeader>
|
||||||
|
<div class="space-y-4 py-2">
|
||||||
|
<div class="space-y-1.5">
|
||||||
|
<Label for="m-name">Название</Label>
|
||||||
|
<Input id="m-name" bind:value={form.name} placeholder="my-asn-module" />
|
||||||
|
</div>
|
||||||
|
<div class="space-y-1.5">
|
||||||
|
<Label for="m-type">Тип</Label>
|
||||||
|
<Select
|
||||||
|
type="single"
|
||||||
|
value={form.type}
|
||||||
|
onValueChange={(v) => {
|
||||||
|
if (v) form.type = v as typeof form.type;
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
<SelectTrigger id="m-type" class="w-full">
|
||||||
|
{moduleTypes.find((t) => t.value === form.type)?.label ?? 'Выберите тип'}
|
||||||
|
</SelectTrigger>
|
||||||
|
<SelectContent>
|
||||||
|
{#each moduleTypes as t (t.value)}
|
||||||
|
<SelectItem value={t.value}>{t.label}</SelectItem>
|
||||||
|
{/each}
|
||||||
|
</SelectContent>
|
||||||
|
</Select>
|
||||||
|
</div>
|
||||||
|
<div class="grid grid-cols-2 gap-4">
|
||||||
|
<div class="space-y-1.5">
|
||||||
|
<Label for="m-priority">Приоритет</Label>
|
||||||
|
<Input id="m-priority" type="number" bind:value={form.priority} />
|
||||||
|
</div>
|
||||||
|
<div class="space-y-1.5">
|
||||||
|
<Label for="m-interval">Интервал (сек)</Label>
|
||||||
|
<Input
|
||||||
|
id="m-interval"
|
||||||
|
type="number"
|
||||||
|
placeholder="3600"
|
||||||
|
bind:value={form.refresh_interval_sec}
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div
|
||||||
|
class="flex flex-row items-center justify-between gap-4 rounded-lg border border-border bg-muted/30 p-3"
|
||||||
|
>
|
||||||
|
<div class="grid min-w-0 flex-1 gap-1 pr-2">
|
||||||
|
<Label for="m-enabled" class="leading-snug text-foreground">Включён</Label>
|
||||||
|
<p class="text-xs leading-snug text-muted-foreground">
|
||||||
|
Модуль участвует в сборке ревизий, если включён.
|
||||||
|
</p>
|
||||||
|
</div>
|
||||||
|
<Switch
|
||||||
|
id="m-enabled"
|
||||||
|
class="shrink-0"
|
||||||
|
checked={form.enabled !== false}
|
||||||
|
onCheckedChange={(v) => {
|
||||||
|
form = { ...form, enabled: v };
|
||||||
|
}}
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<DialogFooter>
|
||||||
|
<Button variant="outline" onclick={() => handleOpenChange(false)}>Отмена</Button>
|
||||||
|
<Button onclick={create} disabled={saving}>{saving ? 'Создание…' : 'Создать'}</Button>
|
||||||
|
</DialogFooter>
|
||||||
|
</DialogContent>
|
||||||
|
</Dialog>
|
||||||
@@ -0,0 +1,57 @@
|
|||||||
|
<script lang="ts">
|
||||||
|
import { resolve } from '$app/paths';
|
||||||
|
import type { ModuleRow } from '$lib/api/types.js';
|
||||||
|
import { moduleEnabledRu, moduleEnabledBadgeVariant, moduleTypeRu } from '$lib/ui-labels.js';
|
||||||
|
import { Badge } from '$lib/ui/core/badge/index.js';
|
||||||
|
import { Button } from '$lib/ui/core/button/index.js';
|
||||||
|
import PageHeader from '$lib/ui/app/page-header/page-header.svelte';
|
||||||
|
import ArrowLeft from '@lucide/svelte/icons/arrow-left';
|
||||||
|
import Pencil from '@lucide/svelte/icons/pencil';
|
||||||
|
import Trash2 from '@lucide/svelte/icons/trash-2';
|
||||||
|
import RefreshCw from '@lucide/svelte/icons/refresh-cw';
|
||||||
|
import Blocks from '@lucide/svelte/icons/blocks';
|
||||||
|
|
||||||
|
type Props = {
|
||||||
|
mod: ModuleRow;
|
||||||
|
refreshing: boolean;
|
||||||
|
onRefresh: () => void;
|
||||||
|
onEdit: () => void;
|
||||||
|
onDelete: () => void;
|
||||||
|
};
|
||||||
|
|
||||||
|
let { mod, refreshing, onRefresh, onEdit, onDelete }: Props = $props();
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<div class="flex min-w-0 items-start gap-2">
|
||||||
|
<Button variant="ghost" size="icon-sm" class="mt-1 shrink-0" href={resolve('/modules')}>
|
||||||
|
<ArrowLeft class="size-4" />
|
||||||
|
</Button>
|
||||||
|
<PageHeader
|
||||||
|
class="min-w-0 flex-1"
|
||||||
|
title={mod.name}
|
||||||
|
description={mod.id}
|
||||||
|
icon={Blocks}
|
||||||
|
iconClass="bg-chart-2/15 text-chart-2"
|
||||||
|
>
|
||||||
|
{#snippet actions()}
|
||||||
|
<div class="flex flex-wrap items-center gap-2">
|
||||||
|
<Badge variant="outline">{moduleTypeRu(mod.type)}</Badge>
|
||||||
|
<Badge variant={moduleEnabledBadgeVariant(!!mod.enabled)} class="text-xs">
|
||||||
|
{moduleEnabledRu(!!mod.enabled)}
|
||||||
|
</Badge>
|
||||||
|
<Button variant="outline" size="sm" onclick={() => onRefresh()} disabled={refreshing}>
|
||||||
|
<RefreshCw class={refreshing ? 'animate-spin' : ''} />
|
||||||
|
Обновить
|
||||||
|
</Button>
|
||||||
|
<Button variant="outline" size="sm" onclick={() => onEdit()}>
|
||||||
|
<Pencil />
|
||||||
|
Редактировать
|
||||||
|
</Button>
|
||||||
|
<Button variant="destructive" size="sm" onclick={() => onDelete()}>
|
||||||
|
<Trash2 />
|
||||||
|
Удалить
|
||||||
|
</Button>
|
||||||
|
</div>
|
||||||
|
{/snippet}
|
||||||
|
</PageHeader>
|
||||||
|
</div>
|
||||||
Loaded 100 of 302 files, more files were not shown because too many files have changed in this diff.
Show more
Reference in new issue
Block a user