feat: add managed database capture and operator restore
PostgreSQL and MySQL backups run through paired outposts, with operator sign-in, off-site copies, and legacy import. Retention stays on each orbit, so the unused retention console is removed. Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
82
web/src/components/operator/OperatorGate.tsx
Normal file
82
web/src/components/operator/OperatorGate.tsx
Normal file
@@ -0,0 +1,82 @@
|
||||
import { useState, type FormEvent, type ReactNode } from "react";
|
||||
import { useQuery, useQueryClient } from "@tanstack/react-query";
|
||||
import { fetchOperatorSession, loginOperator, logoutOperator } from "../../api";
|
||||
import { Button } from "../ui/Button";
|
||||
|
||||
export function OperatorGate({
|
||||
children,
|
||||
}: {
|
||||
children: (operator: { actor?: string; onLogout?: () => Promise<void> }) => ReactNode;
|
||||
}) {
|
||||
const queryClient = useQueryClient();
|
||||
const session = useQuery({
|
||||
queryKey: ["operator-session"],
|
||||
queryFn: ({ signal }) => fetchOperatorSession(signal),
|
||||
refetchInterval: 15_000,
|
||||
retry: false,
|
||||
});
|
||||
const [pending, setPending] = useState(false);
|
||||
const [error, setError] = useState<string>();
|
||||
|
||||
async function submit(event: FormEvent<HTMLFormElement>) {
|
||||
event.preventDefault();
|
||||
const form = event.currentTarget;
|
||||
const password = new FormData(form).get("password");
|
||||
if (pending || typeof password !== "string" || !password) return;
|
||||
setPending(true);
|
||||
setError(undefined);
|
||||
form.reset();
|
||||
await queryClient.cancelQueries({ queryKey: ["operator-session"] });
|
||||
try {
|
||||
const signedIn = await loginOperator(password);
|
||||
queryClient.setQueryData(["operator-session"], signedIn);
|
||||
} catch {
|
||||
setError("Could not sign in. Check the password or try again shortly.");
|
||||
} finally {
|
||||
setPending(false);
|
||||
}
|
||||
}
|
||||
|
||||
if (session.isSuccess && session.data.authorized) {
|
||||
const actor = session.data.actor ?? undefined;
|
||||
return children({
|
||||
actor,
|
||||
onLogout: actor ? async () => {
|
||||
await queryClient.cancelQueries({ queryKey: ["operator-session"] });
|
||||
await logoutOperator();
|
||||
queryClient.setQueryData(["operator-session"], {
|
||||
login_enabled: true, authorized: false, actor: null, csrf: null,
|
||||
});
|
||||
queryClient.removeQueries({ predicate: (query) => query.queryKey[0] !== "operator-session" });
|
||||
} : undefined,
|
||||
});
|
||||
}
|
||||
|
||||
return (
|
||||
<main className="vault-app flex min-h-screen items-center justify-center p-5">
|
||||
<section className="w-full max-w-sm rounded-2xl border border-space-700 bg-space-900 p-6 sm:p-8">
|
||||
<p className="instrument-label mb-3">Tessera / Backup control</p>
|
||||
<h1 className="text-2xl font-semibold text-star-100">Operator sign-in</h1>
|
||||
{session.isPending ? <p role="status" className="mt-4 text-star-300">Connecting to the hub…</p>
|
||||
: session.isError ? (
|
||||
<div className="mt-4 space-y-3">
|
||||
<p role="alert" className="text-star-300">Could not reach the hub.</p>
|
||||
<Button onClick={() => void session.refetch()}>Try again</Button>
|
||||
</div>
|
||||
) : session.data.login_enabled ? (
|
||||
<form onSubmit={submit} className="mt-5 space-y-4">
|
||||
<label className="block text-sm text-star-300">
|
||||
Operator password
|
||||
<input type="password" name="password" autoComplete="current-password" required
|
||||
maxLength={1024} className="mt-1 block w-full rounded-xl border border-space-700 bg-space-950 px-3 py-2 text-star-100" />
|
||||
</label>
|
||||
{error && <p role="alert" className="text-sm text-orbit-red">{error}</p>}
|
||||
<Button type="submit" variant="primary" className="w-full" disabled={pending}>
|
||||
{pending ? "Signing in…" : "Sign in"}
|
||||
</Button>
|
||||
</form>
|
||||
) : <p className="mt-4 text-star-300">Browser sign-in is disabled on this hub.</p>}
|
||||
</section>
|
||||
</main>
|
||||
);
|
||||
}
|
||||
Reference in New Issue
Block a user