From 8de5262c12fb74cde2356d80aec2b85a8c5cb5a6 Mon Sep 17 00:00:00 2001 From: Cedric Date: Sat, 21 Nov 2026 12:49:28 +0100 Subject: [PATCH] Fix page bucket: GetBucketInfo de Garage 2.x n'a pas localAliases, reponse normalisee (getBucket) Co-Authored-By: Claude Sonnet 5.5 --- cmd/mockgarage/main.go | 2 +- frontend/src/Buckets.tsx | 8 ++++---- frontend/src/Keys.tsx | 6 +++--- frontend/src/Overview.tsx | 4 ++-- frontend/src/api.ts | 30 ++++++++++++++++++++++++++++-- 5 files changed, 38 insertions(+), 12 deletions(-) diff --git a/cmd/mockgarage/main.go b/cmd/mockgarage/main.go index ce400c5..c81970c 100644 --- a/cmd/mockgarage/main.go +++ b/cmd/mockgarage/main.go @@ -94,7 +94,7 @@ func (b *bucket) info() map[string]any { wc = map[string]any{"indexDocument": b.Index, "errorDocument": b.ErrDoc} } return map[string]any{ - "id": b.ID, "created": b.Created, "globalAliases": b.Aliases, "localAliases": []any{}, "websiteAccess": b.Site, "websiteConfig": wc, + "id": b.ID, "created": b.Created, "globalAliases": b.Aliases, "websiteAccess": b.Site, "websiteConfig": wc, "keys": ks, "objects": b.Objects, "bytes": b.Bytes, "unfinishedUploads": 0, "unfinishedMultipartUploads": 2, "unfinishedMultipartUploadParts": 5, "unfinishedMultipartUploadBytes": 30 << 20, "quotas": map[string]any{"maxSize": b.MaxSize, "maxObjects": b.MaxObjs}, diff --git a/frontend/src/Buckets.tsx b/frontend/src/Buckets.tsx index daa5b6e..151751d 100644 --- a/frontend/src/Buckets.tsx +++ b/frontend/src/Buckets.tsx @@ -1,5 +1,5 @@ import { useState } from "react"; -import { garage, bucketName, type BucketInfo, type BucketListItem, type KeyListItem, type Perm } from "./api"; +import { garage, getBucket, bucketName, type BucketInfo, type BucketListItem, type KeyListItem, type Perm } from "./api"; import { GIB, fmtDate, fmtNum, fmtSize } from "./format"; import { BucketIcon, GlobeIcon } from "./gicons"; import { CloseIcon, PlusIcon, RefreshIcon, TrashIcon } from "./icons"; @@ -13,7 +13,7 @@ export function Buckets() { const [creating, setCreating] = useState(false); const { data, error, loading, reload } = useLoad(async () => { const list = await garage.get("ListBuckets"); - const infos = await Promise.all(list.map((b) => garage.get("GetBucketInfo", { id: b.id }).catch(() => null))); + const infos = await Promise.all(list.map((b) => getBucket(b.id).catch(() => null))); return list.map((b, i) => ({ b, info: infos[i] })); }); const rows = (data ?? []).filter(({ b }) => bucketName(b).toLowerCase().includes(filter.toLowerCase())); @@ -55,7 +55,7 @@ export function Buckets() { web )} - {b.globalAliases.length > 1 && +{b.globalAliases.length - 1} alias} + {b.globalAliases?.length > 1 && +{b.globalAliases.length - 1} alias} {fmtNum(info?.objects)} {fmtSize(info?.bytes)} @@ -135,7 +135,7 @@ function CreateBucket({ onClose, onCreate }: { onClose: () => void; onCreate: (a export function BucketPage({ id }: { id: string }) { const act = useAct(); - const { data: b, error, loading, reload } = useLoad(() => garage.get("GetBucketInfo", { id }), [id]); + const { data: b, error, loading, reload } = useLoad(() => getBucket(id), [id]); const keys = useLoad(() => garage.get("ListKeys"), []); const [confirmDelete, setConfirmDelete] = useState(false); const [alias, setAlias] = useState(""); diff --git a/frontend/src/Keys.tsx b/frontend/src/Keys.tsx index 8066281..496ada4 100644 --- a/frontend/src/Keys.tsx +++ b/frontend/src/Keys.tsx @@ -298,10 +298,10 @@ export function KeyPage({ id, cfg }: { id: string; cfg: Config }) { - {k.buckets.map((b) => ( + {(k.buckets ?? []).map((b) => ( - {b.globalAliases[0] ?? b.localAliases[0] ?? b.id.slice(0, 12)} + {b.globalAliases?.[0] ?? b.localAliases?.[0] ?? b.id.slice(0, 12)} {(["read", "write", "owner"] as const).map((p) => ( @@ -317,7 +317,7 @@ export function KeyPage({ id, cfg }: { id: string; cfg: Config }) { ))} ))} - {k.buckets.length === 0 && ( + {(k.buckets ?? []).length === 0 && ( Cette clé n'a accès à aucun bucket. diff --git a/frontend/src/Overview.tsx b/frontend/src/Overview.tsx index a0bc695..43edf08 100644 --- a/frontend/src/Overview.tsx +++ b/frontend/src/Overview.tsx @@ -1,4 +1,4 @@ -import { garage, bucketName, type BucketInfo, type BucketListItem, type ClusterHealth, type ClusterStatus, type KeyListItem } from "./api"; +import { garage, getBucket, bucketName, type BucketInfo, type BucketListItem, type ClusterHealth, type ClusterStatus, type KeyListItem } from "./api"; import { fmtNum, fmtSize } from "./format"; import { Loading, PageHead, Status, UsageBar, useLoad } from "./ui"; import { RefreshIcon } from "./icons"; @@ -18,7 +18,7 @@ export function Overview() { garage.get("ListKeys"), garage.get<{ freeform?: string }>("GetClusterStatistics").catch(() => ({ freeform: "" })), ]); - const infos = await Promise.all(buckets.map((b) => garage.get("GetBucketInfo", { id: b.id }).catch(() => null))); + const infos = await Promise.all(buckets.map((b) => getBucket(b.id).catch(() => null))); return { health, status, buckets, keys, stats, infos: infos.filter((x): x is BucketInfo => !!x) }; }); diff --git a/frontend/src/api.ts b/frontend/src/api.ts index 9d76505..7652ff5 100644 --- a/frontend/src/api.ts +++ b/frontend/src/api.ts @@ -173,7 +173,33 @@ export const appApi = { cli: (args: string[]) => req<{ exitCode: number; output: string; ms: number }>("/api/cli", { method: "POST", body: JSON.stringify({ args }) }), }; -export const bucketName = (b: { id: string; globalAliases: string[]; localAliases: { alias: string }[] }) => - b.globalAliases[0] ?? b.localAliases[0]?.alias ?? b.id.slice(0, 12); +export const bucketName = (b: { id: string; globalAliases?: string[]; localAliases?: { alias: string }[] }) => + b.globalAliases?.[0] ?? b.localAliases?.[0]?.alias ?? b.id.slice(0, 12); + +/** + * GetBucketInfo, normalisé : Garage 2.x ne renvoie pas `localAliases` au niveau du bucket (ils sont + * dans `keys[].bucketLocalAliases`) et peut omettre d'autres champs ; l'interface n'a ainsi jamais + * à tester leur présence. + */ +export async function getBucket(id: string): Promise { + const b = await garage.get>("GetBucketInfo", { id }); + const keys = b.keys ?? []; + return { + id: b.id ?? id, + created: b.created ?? "", + globalAliases: b.globalAliases ?? [], + localAliases: b.localAliases ?? keys.flatMap((k) => (k.bucketLocalAliases ?? []).map((alias) => ({ accessKeyId: k.accessKeyId, alias }))), + websiteAccess: !!b.websiteAccess, + websiteConfig: b.websiteConfig ?? null, + keys, + objects: b.objects ?? 0, + bytes: b.bytes ?? 0, + unfinishedUploads: b.unfinishedUploads ?? 0, + unfinishedMultipartUploads: b.unfinishedMultipartUploads ?? 0, + unfinishedMultipartUploadParts: b.unfinishedMultipartUploadParts ?? 0, + unfinishedMultipartUploadBytes: b.unfinishedMultipartUploadBytes ?? 0, + quotas: b.quotas ?? {}, + }; +} export const errMsg = (e: unknown) => (e instanceof Error ? e.message : String(e));