feat(ix): добавить удаление сегментов
Docker images / prepare-release (push) Successful in 11s
Docker images / backend-test (push) Successful in 10m30s
Docker images / frontend-image (push) Successful in 2m11s
Docker images / updater-image (push) Successful in 39s
Docker images / netflow-agent-image (push) Successful in 32s
Docker images / backend-image (push) Successful in 2m0s
Docker images / publish-release (push) Successful in 11s
Docker images / notify-webhook (push) Successful in 2s
Docker images / prepare-release (push) Successful in 11s
Docker images / backend-test (push) Successful in 10m30s
Docker images / frontend-image (push) Successful in 2m11s
Docker images / updater-image (push) Successful in 39s
Docker images / netflow-agent-image (push) Successful in 32s
Docker images / backend-image (push) Successful in 2m0s
Docker images / publish-release (push) Successful in 11s
Docker images / notify-webhook (push) Successful in 2s
This commit is contained in:
1 parent
be1cb6381a
commit
e11e67b3a1
10 files changed
+472
-87
No files matched your search
@@ -1,9 +1,9 @@
|
||||
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 { applyIxChange, currentIxChange, ixTarget, observeIxSegment, prepareIxChange, prepareIxRemoval, reconcileIxChange, removeIxSegment } 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 { assertIxRevision, isIxSegmentArchived, 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"
|
||||
@@ -12,10 +12,13 @@ import { registerMcpService } from "./service-registry.js"
|
||||
export const ixOperation = "network.ix.configure"
|
||||
export const ixRestoreOperation = "network.ix.restore"
|
||||
const service = "network.ix.configure"
|
||||
const removeService = "network.ix.delete"
|
||||
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 removeArgs = z.object({ id, revision }).strict()
|
||||
const sealedRemoval = removeArgs.extend({ actorId: z.string().min(1), digest: z.string().regex(/^[a-f0-9]{64}$/) })
|
||||
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(),
|
||||
@@ -32,14 +35,9 @@ 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: [],
|
||||
before: result.before, objects: await ixPlanObjects(serverIds, result.objects.map(object => object.serverId)), 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: [
|
||||
@@ -49,6 +47,28 @@ async function prepare(change: IxChange, context: ActionContext) {
|
||||
}
|
||||
}
|
||||
|
||||
async function ixPlanObjects(serverIds: number[], nativeIds = serverIds) {
|
||||
const protections = await pool.query("SELECT object_ref FROM mcp_protections WHERE object_ref->>'serverId'=ANY($1::text[]) LIMIT 1001", [serverIds.map(String)])
|
||||
const servers = nativeIds.map(serverId => ({ kind: "server", id: String(serverId), serverId }))
|
||||
const objects = [...new Map(servers.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 objects
|
||||
}
|
||||
|
||||
async function removalTarget(input: Record<string, unknown>, context: ActionContext) {
|
||||
const args = removeArgs.parse(input)
|
||||
const current = await readIxSegment(args.id, context.transactionClient)
|
||||
if (!current) throw new IxConflict("Сегмент IX не найден", 404)
|
||||
assertIxRevision(current, args.revision)
|
||||
const serverIds = await ixTarget({ id: current.id, revision: current.revision, configuration: current.configuration })
|
||||
if (serverIds.some(id => !context.connection.policy.scope.serverIds.includes(id))) {
|
||||
throw new McpError("SERVER_DENIED", "Нет доступа ко всем устройствам сегмента")
|
||||
}
|
||||
return { scope: "servers" as const, serverIds }
|
||||
}
|
||||
|
||||
async function restore(input: Record<string, unknown>, context: ActionContext) {
|
||||
const args = restoreArgs.parse(input)
|
||||
const current = await readIxSegment(args.id, context.transactionClient)
|
||||
@@ -78,6 +98,35 @@ export function registerIxActions(register: typeof add) {
|
||||
return reconcileIxChange(args.id, args.change, args.before, authorize)
|
||||
},
|
||||
})
|
||||
registerMcpService(removeService, {
|
||||
current: input => present(async () => {
|
||||
const { id, revision } = sealedRemoval.parse(input)
|
||||
return { revision, digest: (await prepareIxRemoval(id, revision)).digest }
|
||||
}),
|
||||
execute: input => present(() => {
|
||||
const { id, revision, digest, actorId } = sealedRemoval.parse(input)
|
||||
return removeIxSegment(id, revision, digest, actorId)
|
||||
}),
|
||||
verify: async (input, result) => {
|
||||
const { id, revision } = sealedRemoval.parse(input)
|
||||
return (result as { configurationVerified?: boolean } | undefined)?.configurationVerified === true && isIxSegmentArchived(id, revision)
|
||||
},
|
||||
})
|
||||
register(removeService, "mm_ix_delete_plan", "План удаления сегмента IX", "network", "mm:network:write", "write", "servers", removeArgs, {
|
||||
target: (input, context) => present(() => removalTarget(input, context)),
|
||||
prepare: (input, context) => present(async () => {
|
||||
const args = removeArgs.parse(input)
|
||||
const target = await removalTarget(input, context)
|
||||
const { segment, native, digest } = await prepareIxRemoval(args.id, args.revision)
|
||||
return {
|
||||
target, before: { revision: args.revision, digest }, objects: await ixPlanObjects(target.serverIds), snapshots: [],
|
||||
steps: [{ kind: "service" as const, service: removeService, input: { ...args, digest, actorId: context.connection.owner_id } }],
|
||||
mutationCost: native.tasks.length + 1, requiresHuman: true, verificationScope: "configuration" as const,
|
||||
warnings: [`Сегмент ${segment.configuration.name} будет удалён. Операций RouterOS: ${native.tasks.length}. История ревизий сохранится.`,
|
||||
...native.tasks.slice(0, 12).map(task => `Узел ${task.serverId} · удалить ${task.path}`)],
|
||||
}
|
||||
}),
|
||||
})
|
||||
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) => {
|
||||
|
||||
@@ -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.delete") {
|
||||
return { ...evidence, before: { revision: record(evidence.before).revision }, steps: evidence.steps.map(step => step.kind === "service"
|
||||
? { ...step, input: { id: step.input.id, revision: step.input.revision } } : step) }
|
||||
}
|
||||
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) }
|
||||
|
||||
Reference in new issue
Block a user