Garage UI : interface web d'administration pour Garage (API v2 + CLI)
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
commit
fdd5555100
36 files changed
+8486
No files matched your search
@@ -0,0 +1,351 @@
|
||||
import { useState } from "react";
|
||||
import { garage, type Config, type KeyInfo, type KeyListItem } from "./api";
|
||||
import { fmtDate } from "./format";
|
||||
import { EyeIcon, KeyIcon, PlusIcon, RefreshIcon, TrashIcon } from "./icons";
|
||||
import { Confirm, CopyButton, Loading, Modal, Mono, PageHead, Status, useAct, useLoad } from "./ui";
|
||||
|
||||
// --- Liste -------------------------------------------------------------------------
|
||||
|
||||
export function Keys({ cfg }: { cfg: Config }) {
|
||||
const [creating, setCreating] = useState<"new" | "import" | null>(null);
|
||||
const [created, setCreated] = useState<KeyInfo | null>(null);
|
||||
const { data, error, loading, reload } = useLoad(() => garage.get<KeyListItem[]>("ListKeys"));
|
||||
return (
|
||||
<div className="page">
|
||||
<PageHead title="Clés d'accès">
|
||||
<button onClick={reload} disabled={loading} aria-label="Actualiser" title="Actualiser">
|
||||
<RefreshIcon />
|
||||
</button>
|
||||
<button onClick={() => setCreating("import")}>Importer</button>
|
||||
<button className="primary" onClick={() => setCreating("new")}>
|
||||
<PlusIcon /> Nouvelle clé
|
||||
</button>
|
||||
</PageHead>
|
||||
<Loading loading={loading && !data} error={error} onRetry={reload} />
|
||||
{data && (
|
||||
<div className="table-wrap">
|
||||
<table className="table">
|
||||
<thead>
|
||||
<tr>
|
||||
<th>Nom</th>
|
||||
<th>Identifiant</th>
|
||||
<th>Créée</th>
|
||||
<th>Expiration</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
{data.map((k) => (
|
||||
<tr key={k.id} className="click" onClick={() => (location.hash = `#/keys/${k.id}`)}>
|
||||
<td>
|
||||
<a href={`#/keys/${k.id}`} className="name" onClick={(e) => e.stopPropagation()}>
|
||||
<KeyIcon /> {k.name || "(sans nom)"}
|
||||
</a>
|
||||
</td>
|
||||
<td>
|
||||
<Mono value={k.id} short={16} />
|
||||
</td>
|
||||
<td className="muted">{fmtDate(k.created)}</td>
|
||||
<td>{k.expired ? <Status kind="bad">expirée</Status> : k.expiration ? fmtDate(k.expiration) : <span className="muted">jamais</span>}</td>
|
||||
</tr>
|
||||
))}
|
||||
{data.length === 0 && (
|
||||
<tr>
|
||||
<td colSpan={4} className="muted center">
|
||||
Aucune clé.
|
||||
</td>
|
||||
</tr>
|
||||
)}
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
)}
|
||||
{creating && (
|
||||
<KeyForm
|
||||
mode={creating}
|
||||
onClose={() => setCreating(null)}
|
||||
onDone={(k) => {
|
||||
setCreating(null);
|
||||
setCreated(k);
|
||||
reload();
|
||||
}}
|
||||
/>
|
||||
)}
|
||||
{created && (
|
||||
<Modal title="Clé créée" onClose={() => setCreated(null)}>
|
||||
<p className="notice">Le secret reste consultable plus tard depuis la page de la clé.</p>
|
||||
<Secrets k={created} cfg={cfg} reveal />
|
||||
<div className="modal-actions">
|
||||
<span className="spacer" />
|
||||
<button className="primary" onClick={() => setCreated(null)}>
|
||||
Fermer
|
||||
</button>
|
||||
</div>
|
||||
</Modal>
|
||||
)}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
function KeyForm({ mode, onClose, onDone }: { mode: "new" | "import"; onClose: () => void; onDone: (k: KeyInfo) => void }) {
|
||||
const act = useAct();
|
||||
const [name, setName] = useState("");
|
||||
const [id, setId] = useState("");
|
||||
const [secret, setSecret] = useState("");
|
||||
const [exp, setExp] = useState("");
|
||||
const [createBucket, setCreateBucket] = useState(false);
|
||||
const [busy, setBusy] = useState(false);
|
||||
const valid = mode === "new" || (/^GK[0-9a-f]{24}$/.test(id) && /^[0-9a-f]{64}$/.test(secret));
|
||||
return (
|
||||
<Modal title={mode === "new" ? "Nouvelle clé" : "Importer une clé"} onClose={onClose}>
|
||||
<form
|
||||
className="form"
|
||||
onSubmit={async (e) => {
|
||||
e.preventDefault();
|
||||
setBusy(true);
|
||||
let k: KeyInfo | undefined;
|
||||
if (await act(async () => {
|
||||
if (mode === "new") {
|
||||
k = await garage.post<KeyInfo>("CreateKey", undefined, {
|
||||
name: name || null,
|
||||
allow: { createBucket },
|
||||
...(exp ? { expiration: new Date(exp).toISOString() } : { neverExpires: true }),
|
||||
});
|
||||
} else {
|
||||
k = await garage.post<KeyInfo>("ImportKey", undefined, { name: name || null, accessKeyId: id, secretAccessKey: secret });
|
||||
}
|
||||
})) onDone(k!);
|
||||
setBusy(false);
|
||||
}}
|
||||
>
|
||||
<label className="field">
|
||||
<span>Nom</span>
|
||||
<input type="text" value={name} onChange={(e) => setName(e.target.value)} autoFocus placeholder="ex. sauvegardes-proxmox" />
|
||||
</label>
|
||||
{mode === "import" && (
|
||||
<>
|
||||
<label className="field">
|
||||
<span>Identifiant (GK + 24 caractères hexadécimaux)</span>
|
||||
<input type="text" value={id} onChange={(e) => setId(e.target.value.trim())} />
|
||||
</label>
|
||||
<label className="field">
|
||||
<span>Secret (64 caractères hexadécimaux)</span>
|
||||
<input type="password" value={secret} onChange={(e) => setSecret(e.target.value.trim())} autoComplete="off" />
|
||||
</label>
|
||||
</>
|
||||
)}
|
||||
{mode === "new" && (
|
||||
<>
|
||||
<label className="field">
|
||||
<span>Expiration (facultative)</span>
|
||||
<input type="datetime-local" value={exp} onChange={(e) => setExp(e.target.value)} />
|
||||
</label>
|
||||
<label className="check-row">
|
||||
<input type="checkbox" checked={createBucket} onChange={(e) => setCreateBucket(e.target.checked)} />
|
||||
<span>Autoriser cette clé à créer des buckets</span>
|
||||
</label>
|
||||
</>
|
||||
)}
|
||||
<div className="modal-actions">
|
||||
<span className="spacer" />
|
||||
<button type="button" onClick={onClose}>
|
||||
Annuler
|
||||
</button>
|
||||
<button className="primary" disabled={!valid || busy}>
|
||||
{mode === "new" ? "Créer" : "Importer"}
|
||||
</button>
|
||||
</div>
|
||||
</form>
|
||||
</Modal>
|
||||
);
|
||||
}
|
||||
|
||||
/** Identifiant, secret et exemples de configuration client. */
|
||||
function Secrets({ k, cfg, reveal }: { k: KeyInfo; cfg: Config; reveal?: boolean }) {
|
||||
const [show, setShow] = useState(!!reveal);
|
||||
const secret = k.secretAccessKey || "";
|
||||
const shown = show ? secret : "•".repeat(32);
|
||||
const endpoint = cfg.s3Endpoint || "https://s3.example.org";
|
||||
const rclone = `[garage]\ntype = s3\nprovider = Other\naccess_key_id = ${k.accessKeyId}\nsecret_access_key = ${secret}\nendpoint = ${endpoint}\nregion = ${cfg.s3Region}`;
|
||||
const aws = `aws configure set aws_access_key_id ${k.accessKeyId}\naws configure set aws_secret_access_key ${secret}\naws configure set region ${cfg.s3Region}\naws --endpoint-url ${endpoint} s3 ls`;
|
||||
return (
|
||||
<div className="form">
|
||||
<label className="field">
|
||||
<span>Identifiant</span>
|
||||
<div className="row">
|
||||
<input readOnly value={k.accessKeyId} className="grow mono" />
|
||||
<CopyButton text={k.accessKeyId} />
|
||||
</div>
|
||||
</label>
|
||||
<label className="field">
|
||||
<span>Secret</span>
|
||||
<div className="row">
|
||||
<input readOnly value={shown} className="grow mono" />
|
||||
{secret && (
|
||||
<button className="icon-btn" onClick={() => setShow(!show)} aria-label={show ? "Masquer" : "Afficher"} title={show ? "Masquer" : "Afficher"}>
|
||||
<EyeIcon />
|
||||
</button>
|
||||
)}
|
||||
{secret && <CopyButton text={secret} />}
|
||||
</div>
|
||||
</label>
|
||||
{show && secret && (
|
||||
<>
|
||||
<div>
|
||||
<div className="row">
|
||||
<strong className="small-text grow">rclone</strong>
|
||||
<CopyButton text={rclone} />
|
||||
</div>
|
||||
<pre className="out">{rclone}</pre>
|
||||
</div>
|
||||
<div>
|
||||
<div className="row">
|
||||
<strong className="small-text grow">AWS CLI</strong>
|
||||
<CopyButton text={aws} />
|
||||
</div>
|
||||
<pre className="out">{aws}</pre>
|
||||
</div>
|
||||
</>
|
||||
)}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
// --- Détail ------------------------------------------------------------------------
|
||||
|
||||
export function KeyPage({ id, cfg }: { id: string; cfg: Config }) {
|
||||
const act = useAct();
|
||||
const [reveal, setReveal] = useState(false);
|
||||
const [confirmDelete, setConfirmDelete] = useState(false);
|
||||
const { data: k, error, loading, reload } = useLoad(() => garage.get<KeyInfo>("GetKeyInfo", { id, showSecretKey: reveal }), [id, reveal]);
|
||||
const [name, setName] = useState<string | null>(null);
|
||||
|
||||
if (!k)
|
||||
return (
|
||||
<div className="page">
|
||||
<PageHead title="Clé" back={{ href: "#/keys", label: "Clés d'accès" }} />
|
||||
<Loading loading={loading} error={error} onRetry={reload} />
|
||||
</div>
|
||||
);
|
||||
const run = (fn: () => Promise<unknown>, ok?: string) => act(fn, ok).then((r) => r && reload());
|
||||
|
||||
return (
|
||||
<div className="page">
|
||||
<PageHead title={k.name || k.accessKeyId} back={{ href: "#/keys", label: "Clés d'accès" }}>
|
||||
<button className="danger-outline" onClick={() => setConfirmDelete(true)}>
|
||||
<TrashIcon /> Supprimer
|
||||
</button>
|
||||
</PageHead>
|
||||
|
||||
<section className="panel">
|
||||
<h3>
|
||||
Identifiants {k.expired && <Status kind="bad">expirée</Status>}
|
||||
</h3>
|
||||
{reveal || k.secretAccessKey ? (
|
||||
<Secrets k={k} cfg={cfg} reveal />
|
||||
) : (
|
||||
<>
|
||||
<Secrets k={k} cfg={cfg} />
|
||||
<p className="muted small-text">Le secret n'est récupéré auprès de Garage que sur demande.</p>
|
||||
<button onClick={() => setReveal(true)}>
|
||||
<EyeIcon /> Afficher le secret
|
||||
</button>
|
||||
</>
|
||||
)}
|
||||
</section>
|
||||
|
||||
<section className="panel">
|
||||
<h3>Réglages</h3>
|
||||
<form
|
||||
className="form"
|
||||
onSubmit={(e) => {
|
||||
e.preventDefault();
|
||||
if (name !== null) run(() => garage.post("UpdateKey", { id: k.accessKeyId }, { name }), "Nom enregistré").then(() => setName(null));
|
||||
}}
|
||||
>
|
||||
<div className="inline-form">
|
||||
<label className="field grow">
|
||||
<span>Nom</span>
|
||||
<input type="text" value={name ?? k.name} onChange={(e) => setName(e.target.value)} />
|
||||
</label>
|
||||
<button disabled={name === null || name === k.name}>Renommer</button>
|
||||
</div>
|
||||
</form>
|
||||
<label className="check-row">
|
||||
<input
|
||||
type="checkbox"
|
||||
checked={k.permissions.createBucket}
|
||||
onChange={(e) =>
|
||||
run(() => garage.post("UpdateKey", { id: k.accessKeyId }, e.target.checked ? { allow: { createBucket: true } } : { deny: { createBucket: true } }))
|
||||
}
|
||||
/>
|
||||
<span>Peut créer des buckets</span>
|
||||
</label>
|
||||
<p className="muted small-text">
|
||||
Créée le {fmtDate(k.created)} · expiration : {k.expiration ? fmtDate(k.expiration) : "jamais"}
|
||||
</p>
|
||||
</section>
|
||||
|
||||
<section className="panel">
|
||||
<h3>Buckets accessibles</h3>
|
||||
<div className="table-wrap">
|
||||
<table className="table">
|
||||
<thead>
|
||||
<tr>
|
||||
<th>Bucket</th>
|
||||
<th className="c">Lecture</th>
|
||||
<th className="c">Écriture</th>
|
||||
<th className="c">Propriétaire</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
{k.buckets.map((b) => (
|
||||
<tr key={b.id}>
|
||||
<td>
|
||||
<a href={`#/buckets/${b.id}`}>{b.globalAliases[0] ?? b.localAliases[0] ?? b.id.slice(0, 12)}</a>
|
||||
</td>
|
||||
{(["read", "write", "owner"] as const).map((p) => (
|
||||
<td className="c" key={p}>
|
||||
<input
|
||||
type="checkbox"
|
||||
checked={!!b.permissions[p]}
|
||||
onChange={(e) =>
|
||||
run(() => garage.post(e.target.checked ? "AllowBucketKey" : "DenyBucketKey", undefined, { bucketId: b.id, accessKeyId: k.accessKeyId, permissions: { [p]: true } }))
|
||||
}
|
||||
aria-label={p}
|
||||
/>
|
||||
</td>
|
||||
))}
|
||||
</tr>
|
||||
))}
|
||||
{k.buckets.length === 0 && (
|
||||
<tr>
|
||||
<td colSpan={4} className="muted center">
|
||||
Cette clé n'a accès à aucun bucket.
|
||||
</td>
|
||||
</tr>
|
||||
)}
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
</section>
|
||||
|
||||
{confirmDelete && (
|
||||
<Confirm
|
||||
title="Supprimer la clé"
|
||||
message={
|
||||
<p>
|
||||
La clé <strong>{k.name || k.accessKeyId}</strong> sera supprimée et ses accès aux buckets révoqués. Les applications qui l'utilisent cesseront de fonctionner.
|
||||
</p>
|
||||
}
|
||||
confirmLabel="Supprimer"
|
||||
onClose={() => setConfirmDelete(false)}
|
||||
onConfirm={async () => {
|
||||
if (await act(() => garage.post("DeleteKey", { id: k.accessKeyId }), "Clé supprimée")) location.hash = "#/keys";
|
||||
else setConfirmDelete(false);
|
||||
}}
|
||||
/>
|
||||
)}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user