Fix delete_image: POST with images JSON array (DevTools-confirmed format)

DSM Container Manager rejects name+tag and sha256 id params (error 114).
Browser DevTools capture shows the correct call is:

  POST SYNO.Docker.Image / delete / version=1
  images=[{"repository":"nouchka/sqlite3","tags":["latest"]}]

Changes:
- Add DsmClient.post_request() for form-encoded POST requests
- delete_image now calls post_request with version=1 and the images
  JSON array built from the resolved repository name and tag
- Remove unused docker error-code dict from _error_message()
- Tests mock post_request and assert the images param content

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
2026-04-13 18:19:22 +02:00
parent 2b1e2ead7d
commit 5edd051830
3 changed files with 120 additions and 35 deletions
+13 -7
View File
@@ -2,6 +2,7 @@
from __future__ import annotations
import json
import logging
import sys
from datetime import UTC, datetime
@@ -243,17 +244,22 @@ def register_images(mcp: FastMCP, config: AppConfig, client: DsmClient) -> None:
f"Call delete_image(image_id={image_id!r}, confirmed=True) to confirm."
)
# DSM requires the sha256 image ID for deletion, not name+tag.
if not img_hash:
return f"Cannot delete '{display_name}': image ID (sha256) not found in list."
sys.stderr.write(f"[delete_image] api=SYNO.Docker.Image method=delete id={img_hash!r}\n")
# DSM Container Manager expects a POST with version=1 and an
# "images" JSON array — confirmed via browser DevTools capture.
# Format: images=[{"repository": "nginx", "tags": ["1.24"]}]
delete_repo = repo
delete_tag = img_tags[0] if img_tags else tag
images_param = json.dumps([{"repository": delete_repo, "tags": [delete_tag]}])
sys.stderr.write(
f"[delete_image] POST SYNO.Docker.Image/delete v1 images={images_param!r}\n"
)
sys.stderr.flush()
try:
await client.request(
await client.post_request(
"SYNO.Docker.Image",
"delete",
params={"id": img_hash},
version=1,
params={"images": images_param},
)
except Exception as e:
code = getattr(e, "code", "?")