feat(ix): добавить точки обмена трафиком
Docker images / prepare-release (push) Successful in 11s
Docker images / backend-test (push) Failing after 4m0s
Docker images / backend-image (push) Skipped
Docker images / frontend-image (push) Successful in 5m0s
Docker images / updater-image (push) Successful in 1m56s
Docker images / netflow-agent-image (push) Successful in 33s
Docker images / publish-release (push) Skipped
Docker images / notify-webhook (push) Skipped
Docker images / prepare-release (push) Successful in 11s
Docker images / backend-test (push) Failing after 4m0s
Docker images / backend-image (push) Skipped
Docker images / frontend-image (push) Successful in 5m0s
Docker images / updater-image (push) Successful in 1m56s
Docker images / netflow-agent-image (push) Successful in 33s
Docker images / publish-release (push) Skipped
Docker images / notify-webhook (push) Skipped
This commit is contained in:
1 parent
80cd3a18d7
commit
d422050a4b
65 files changed
+2563
-59
No files matched your search
@@ -76,6 +76,7 @@ import { prepareWireguardPeerDeletion, registerWireguardPeerDeleteActions } from
|
||||
import { registerFirewallActions } from "./firewall-actions.js"
|
||||
import { registerBfdMoveActions } from "./bfd-move-actions.js"
|
||||
import { registerGreMutationActions } from "./gre-mutation-actions.js"
|
||||
import { registerIxActions } from "./internet-exchange-actions.js"
|
||||
import { registerGreRevisionActions } from "./gre-revision-actions.js"
|
||||
import { prepareGreNativeChange, registerGreNativeServices } from "./gre-native-actions.js"
|
||||
import { registerVpnCatalogActions } from "./vpn-catalog-actions.js"
|
||||
@@ -701,6 +702,7 @@ registerWireguardInterfaceDeleteActions(add)
|
||||
registerFirewallActions(add)
|
||||
registerBfdMoveActions(add)
|
||||
registerGreMutationActions(add)
|
||||
registerIxActions(add)
|
||||
registerGreRevisionActions(add)
|
||||
registerGreNativeServices()
|
||||
registerVpnCatalogActions(add)
|
||||
|
||||
@@ -0,0 +1,114 @@
|
||||
import { z } from "zod"
|
||||
import { ixChangeSchema, type IxChange } from "@mmapp/contracts/internet-exchange"
|
||||
import { pool } from "../../db/index.js"
|
||||
import { applyIxChange, currentIxChange, ixTarget, observeIxSegment, prepareIxChange, reconcileIxChange } from "../../services/internet-exchange-execution.js"
|
||||
import { IxConflict, ixDeviceIds } from "../../services/internet-exchange-plan.js"
|
||||
import { listIxSegments, readIxRevision, readIxSegment } from "../../services/internet-exchange-store.js"
|
||||
import type { add } from "./actions.js"
|
||||
import type { ActionContext } from "./action-types.js"
|
||||
import { McpError } from "./security.js"
|
||||
import { registerMcpService } from "./service-registry.js"
|
||||
|
||||
export const ixOperation = "network.ix.configure"
|
||||
export const ixRestoreOperation = "network.ix.restore"
|
||||
const service = "network.ix.configure"
|
||||
const id = z.string().uuid()
|
||||
const revision = z.number().int().positive()
|
||||
const changeArgs = z.object({ change: ixChangeSchema }).strict()
|
||||
const restoreArgs = z.object({ id, revision, restoreRevision: revision }).strict()
|
||||
const sealedInput = z.object({
|
||||
id, change: ixChangeSchema, actorId: z.string().min(1),
|
||||
before: z.object({ revision: z.number().int().nonnegative(), devices: z.string().regex(/^[a-f0-9]{64}$/) }).strict(),
|
||||
}).strict()
|
||||
|
||||
async function present<T>(work: () => Promise<T>) {
|
||||
try { return await work() } catch (error) {
|
||||
if (error instanceof IxConflict) throw new McpError(error.statusCode === 400 ? "INVALID_INPUT" : error.statusCode === 404 ? "NOT_FOUND" : "STATE_CONFLICT", error.message, error.statusCode)
|
||||
throw error
|
||||
}
|
||||
}
|
||||
|
||||
async function prepare(change: IxChange, context: ActionContext) {
|
||||
const serverIds = await ixTarget(change)
|
||||
if (serverIds.some(id => !context.connection.policy.scope.serverIds.includes(id))) throw new McpError("SERVER_DENIED", "Нет доступа ко всем устройствам сегмента")
|
||||
const result = await prepareIxChange(change)
|
||||
const protections = await pool.query("SELECT object_ref FROM mcp_protections WHERE object_ref->>'serverId'=ANY($1::text[]) LIMIT 1001", [serverIds.map(String)])
|
||||
const objects = [...new Map(result.objects.concat(protections.rows.map(({ object_ref: object }) => ({
|
||||
kind: object.kind, id: object.id, serverId: object.serverId,
|
||||
}))).map(object => [JSON.stringify(object), object])).values()]
|
||||
if (objects.length > 1000) throw new McpError("STATE_UNAVAILABLE", "Превышен лимит защищённых ресурсов плана IX", 409)
|
||||
return {
|
||||
target: { scope: "servers" as const, serverIds },
|
||||
before: result.before, objects, snapshots: [],
|
||||
steps: [{ kind: "service" as const, service, input: { id: result.id, change, before: result.before, actorId: context.connection.owner_id } }],
|
||||
mutationCost: result.native.tasks.length + 1,
|
||||
warnings: [
|
||||
"Изменение затрагивает только выделенные интерфейсы и управляемые объекты IX. Проверка конфигурации не подтверждает прохождение трафика.",
|
||||
...result.native.tasks.slice(0, 12).map(task => `Узел ${task.serverId} · ${task.path} · ${task.fields ? task.rosId ? "изменить" : "создать" : "удалить"}`),
|
||||
],
|
||||
}
|
||||
}
|
||||
|
||||
async function restore(input: Record<string, unknown>, context: ActionContext) {
|
||||
const args = restoreArgs.parse(input)
|
||||
const current = await readIxSegment(args.id, context.transactionClient)
|
||||
if (!current || ixDeviceIds(current.configuration).some(id => !context.connection.policy.scope.serverIds.includes(id))) {
|
||||
throw new McpError("NOT_FOUND", "Сегмент IX не найден", 404)
|
||||
}
|
||||
return { id: args.id, revision: args.revision, configuration: await readIxRevision(args.id, args.restoreRevision) }
|
||||
}
|
||||
|
||||
export function registerIxActions(register: typeof add) {
|
||||
registerMcpService(service, {
|
||||
current: input => present(() => {
|
||||
const args = sealedInput.parse(input)
|
||||
return currentIxChange(args.id, args.change)
|
||||
}),
|
||||
execute: input => present(() => {
|
||||
const args = sealedInput.parse(input)
|
||||
return applyIxChange(args.id, args.change, args.before, args.actorId)
|
||||
}),
|
||||
verify: async (input, result) => {
|
||||
const args = sealedInput.parse(input)
|
||||
const row = await readIxSegment(args.id)
|
||||
return (result as { configurationVerified?: boolean })?.configurationVerified === true && row?.appliedRevision === args.change.revision + 1
|
||||
},
|
||||
reconcile: (input, authorize) => {
|
||||
const args = sealedInput.parse(input)
|
||||
return reconcileIxChange(args.id, args.change, args.before, authorize)
|
||||
},
|
||||
})
|
||||
register("network.ix.list", "mm_ix_segments_list", "Сегменты обмена трафиком", "network", "mm:network:read", "read", "servers",
|
||||
z.object({ limit: z.number().int().min(1).max(25).default(10), offset: z.number().int().nonnegative().max(1000000).default(0) }).strict(), {
|
||||
read: async (input, context) => {
|
||||
const items = await listIxSegments(Number(input.limit), Number(input.offset), context.connection.policy.scope.serverIds)
|
||||
return { items: items.map(segment => ({
|
||||
id: segment.id, name: segment.configuration.name, sites: segment.configuration.sites.map(site => site.serverId),
|
||||
revision: segment.revision, appliedRevision: segment.appliedRevision, updatedAt: segment.updatedAt,
|
||||
})) }
|
||||
},
|
||||
})
|
||||
register("network.ix.read", "mm_ix_segment_get", "Конфигурация сегмента IX", "network", "mm:network:read", "read", "servers",
|
||||
z.object({ id }).strict(), {
|
||||
target: async (input, context) => {
|
||||
const row = await readIxSegment(String(input.id), context.transactionClient)
|
||||
if (!row) throw new McpError("NOT_FOUND", "Сегмент IX не найден", 404)
|
||||
return { scope: "servers", serverIds: await ixTarget({ id: row.id, revision: row.revision, configuration: row.configuration }) }
|
||||
},
|
||||
read: async (input, context) => {
|
||||
const row = await readIxSegment(String(input.id))
|
||||
if (!row) throw new McpError("NOT_FOUND", "Сегмент IX не найден", 404)
|
||||
const ids = await ixTarget({ id: row.id, revision: row.revision, configuration: row.configuration })
|
||||
if (ids.some(id => !context.connection.policy.scope.serverIds.includes(id))) throw new McpError("SERVER_DENIED", "Нет доступа ко всем устройствам сегмента")
|
||||
return { segment: row, observations: await observeIxSegment(row) }
|
||||
},
|
||||
})
|
||||
register(ixOperation, "mm_ix_change_plan", "План изменения сегмента IX", "network", "mm:network:write", "write", "servers", changeArgs, {
|
||||
target: async input => ({ scope: "servers", serverIds: await ixTarget(changeArgs.parse(input).change) }),
|
||||
prepare: (input, context) => present(() => prepare(changeArgs.parse(input).change, context)),
|
||||
})
|
||||
register(ixRestoreOperation, "mm_ix_restore_plan", "План восстановления ревизии IX", "network", "mm:network:write", "write", "servers", restoreArgs, {
|
||||
target: async (input, context) => ({ scope: "servers", serverIds: await ixTarget(await restore(input, context)) }),
|
||||
prepare: (input, context) => present(async () => prepare(await restore(input, context), context)),
|
||||
})
|
||||
}
|
||||
@@ -34,6 +34,10 @@ export function publicRoutingCommunityChanges(evidence: ChangeEvidence) {
|
||||
|
||||
/** Service recovery has the same private native bodies as its forward plan. */
|
||||
export function publicMcpChangeEvidence(operationId: string, evidence: ChangeEvidence) {
|
||||
if (operationId === "network.ix.configure" || operationId === "network.ix.restore") {
|
||||
return { ...evidence, before: { revision: record(evidence.before).revision }, steps: evidence.steps.map(step => step.kind === "service"
|
||||
? { ...step, input: { id: step.input.id, change: step.input.change } } : step) }
|
||||
}
|
||||
if (operationId === "routing.bfd.configuration.move") {
|
||||
const before = evidence.before as { order?: string[] } | undefined
|
||||
return { ...evidence, before: { order: before?.order }, steps: evidence.steps.map(step => step.kind === "service"
|
||||
|
||||
Reference in new issue
Block a user