mirror of
https://github.com/shankar0123/certctl.git
synced 2026-06-11 22:38:52 +00:00
3f5c2344ab
Closes five 2026-04-24 audit findings (all P2, all category cat-f /
diff-05x06-*) by reconciling the TypeScript interfaces in
web/src/api/types.ts with the on-wire JSON shape Go's
internal/domain/*.go structs actually emit. D-1 closed the same pattern
for one entity (Certificate / ManagedCertificate); D-2 covers the
remaining five.
Per-entity verdicts (audit's "stricter side is the contract"):
Agent — TRIM 5 phantoms (last_heartbeat, capabilities, tags,
created_at, updated_at). Go emits last_heartbeat_at only.
Target — ADD 2 (retired_at?, retired_reason?) — I-004 fields.
DiscCert — ADD pem_data? — real field, real Go emit, omitempty.
Issuer — TRIM phantom status. Go has Enabled bool only.
Notif — TRIM phantom subject. Go has Message string only.
Certificate — verify-only; D-1 closure confirmed clean at recon.
Consumer fixes (same commit as the trim):
- AgentDetailPage.tsx — remove dead Capabilities + Tags sections (always
rendered empty); replace agent.created_at/updated_at row with the
Go-emitted registered_at; widen heartbeatStatus() to accept undefined.
- AgentsPage.tsx — same heartbeatStatus widening.
- IssuersPage.tsx + IssuerDetailPage.tsx — issuerStatus() now derives
from `enabled` exclusively; the dead `issuer.status || 'Unknown'`
fallback is gone.
- NotificationsPage.tsx — drop dead `|| n.subject` fallback.
- NotificationsPage.test.tsx — drop dead `subject:` from mocks.
- api/utils.ts::timeAgo widened to accept string | undefined | null.
- api/types.test.ts — Agent (I-004) fixture trimmed of the 5 phantoms.
Tests (Vitest):
- 5 new describe blocks in web/src/api/types.test.ts:
- Agent interface (D-2 phantom-fields trim) — 2 it blocks
- Target interface (D-2 retirement fields) — 2 it blocks
- DiscoveredCertificate interface (D-2 pem_data ADD) — 2 it blocks
- Issuer interface (D-2 status phantom trim) — 1 it block
- Notification interface (D-2 subject phantom trim) — 1 it block
- Each block uses the literal-construction pattern from D-1; trimmed
fields are pinned via excess-property comments that compile-fail when
uncommented if a phantom is reintroduced.
CI regression guardrail:
- .github/workflows/ci.yml — existing D-1 step renamed to "Forbidden
StatusBadge dead-key + TS phantom-field regression guard (D-1 + D-2)".
Three new awk-windowed greps over Agent / Issuer / Notification
interfaces in types.ts. The Agent grep includes a `grep -v
'last_heartbeat_at'` filter to avoid false positives on the
legitimate Go-emitted heartbeat field.
Documentation:
- CHANGELOG.md — new D-2 section above B-1 under [unreleased] with full
Added/Removed/Audit findings closed/Known follow-ups breakdown.
- docs/architecture.md — Web Dashboard section gains a new "TS ↔ Go
type contract rule (D-1 + D-2 closure)" paragraph capturing the
stricter-side-wins rule and the CI guardrail it's anchored by.
- coverage-gap-audit-2026-04-24-v5/unified-audit.md — Live Tracker score
20/47 → 25/47 (P2: 6/27 → 11/27). Per-finding ✅ RESOLVED Status
blocks added to all 5 diff-05x06-* entries plus the verify-only
Certificate entry. Closed-bundle index gets D-2 row.
Verification (all gates green):
- cd web && tsc --noEmit → clean
- cd web && vitest run --reporter=dot → 9 files, 302 tests passing
(was 294 → +8 D-2 cases)
- cd web && vite build → clean
- go vet ./internal/... ./cmd/... → clean (no Go touched)
- golangci-lint v2.11.4 run ./... → 0 issues
- D-2 Agent guardrail dry-run → empty (good)
- D-2 Issuer guardrail dry-run → empty (good)
- D-2 Notification guardrail dry-run → empty (good)
- D-2 Target ADD-shape sanity → 2 retirement fields present
- D-2 DiscCert ADD-shape sanity → pem_data present
- D-1 Certificate guardrail still clean → empty (good)
- OpenAPI YAML parses → 89 paths
Audit findings closed:
- diff-05x06-7cdf4e78ae24 (P2, Agent TS↔Go drift)
- diff-05x06-2044a46f4dd0 (P2, Target TS↔DeploymentTarget Go drift)
- diff-05x06-85ab6b98a2f7 (P2, DiscoveredCertificate TS↔Go drift)
- diff-05x06-97fab8783a5c (P2, Issuer TS↔Go drift)
- diff-05x06-caba9eb3620e (P2, Notification TS↔NotificationEvent drift)
- diff-05x06-af18a8d7ef41 (P2) — verified clean since D-1; no edit
Deferred follow-ups:
- Issuer richer status view (enabled × test_status) — UX scope, not drift.
- Real Agent metadata (capabilities, tags) — backend feature, not drift.
- DiscoveredCertificate pem_data list-response perf — separate backend change.
187 lines
7.2 KiB
TypeScript
187 lines
7.2 KiB
TypeScript
import { useParams, useNavigate } from 'react-router-dom';
|
|
import { useQuery, useMutation } from '@tanstack/react-query';
|
|
import { getIssuer, testIssuerConnection, getCertificates } from '../api/client';
|
|
import PageHeader from '../components/PageHeader';
|
|
import StatusBadge from '../components/StatusBadge';
|
|
import DataTable from '../components/DataTable';
|
|
import type { Column } from '../components/DataTable';
|
|
import ErrorState from '../components/ErrorState';
|
|
import { formatDateTime } from '../api/utils';
|
|
import type { Certificate, Issuer } from '../api/types';
|
|
import { typeLabels, redactConfig } from '../config/issuerTypes';
|
|
|
|
function InfoRow({ label, value }: { label: string; value: React.ReactNode }) {
|
|
return (
|
|
<div className="flex justify-between py-2 border-b border-surface-border/50">
|
|
<span className="text-sm text-ink-muted">{label}</span>
|
|
<span className="text-sm text-ink">{value}</span>
|
|
</div>
|
|
);
|
|
}
|
|
|
|
// Derive display status from backend `enabled` boolean.
|
|
//
|
|
// D-2 (diff-05x06-97fab8783a5c, master): pre-D-2 the fall-through here
|
|
// was `issuer.status || 'Unknown'`, but `Issuer.status` was a TS phantom
|
|
// the Go-side struct never emitted (see types.ts::Issuer docblock for the
|
|
// full closure rationale). Post-D-2 the phantom is gone; this function
|
|
// derives the displayed status from `enabled` exclusively.
|
|
function issuerStatus(issuer: Issuer): string {
|
|
return issuer.enabled ? 'Enabled' : 'Disabled';
|
|
}
|
|
|
|
export default function IssuerDetailPage() {
|
|
const { id } = useParams<{ id: string }>();
|
|
const navigate = useNavigate();
|
|
|
|
const { data: issuer, isLoading, error, refetch } = useQuery({
|
|
queryKey: ['issuer', id],
|
|
queryFn: () => getIssuer(id!),
|
|
enabled: !!id,
|
|
});
|
|
|
|
const { data: certsData } = useQuery({
|
|
queryKey: ['certificates', { issuer_id: id }],
|
|
queryFn: () => getCertificates({ issuer_id: id! }),
|
|
enabled: !!id,
|
|
});
|
|
|
|
const testMutation = useMutation({
|
|
mutationFn: () => testIssuerConnection(id!),
|
|
onSuccess: () => refetch(),
|
|
});
|
|
|
|
if (error) {
|
|
return (
|
|
<>
|
|
<PageHeader title="Issuer Details" />
|
|
<ErrorState error={error as Error} onRetry={() => refetch()} />
|
|
</>
|
|
);
|
|
}
|
|
|
|
if (isLoading || !issuer) {
|
|
return (
|
|
<>
|
|
<PageHeader title="Issuer Details" />
|
|
<div className="flex items-center justify-center py-20">
|
|
<div className="text-sm text-ink-muted">Loading issuer...</div>
|
|
</div>
|
|
</>
|
|
);
|
|
}
|
|
|
|
const safeConfig = issuer.config ? redactConfig(issuer.config) : {};
|
|
|
|
const certColumns: Column<Certificate>[] = [
|
|
{
|
|
key: 'name',
|
|
label: 'Certificate',
|
|
render: (c) => (
|
|
<div>
|
|
<div className="font-medium text-ink text-sm">{c.common_name}</div>
|
|
<div className="text-xs text-ink-faint font-mono">{c.id}</div>
|
|
</div>
|
|
),
|
|
},
|
|
{ key: 'status', label: 'Status', render: (c) => <StatusBadge status={c.status} /> },
|
|
{ key: 'expires', label: 'Expires', render: (c) => <span className="text-xs text-ink-muted">{formatDateTime(c.expires_at)}</span> },
|
|
];
|
|
|
|
return (
|
|
<>
|
|
<PageHeader
|
|
title={issuer.name}
|
|
subtitle={typeLabels[issuer.type] || issuer.type}
|
|
action={
|
|
<div className="flex gap-2">
|
|
<button
|
|
onClick={() => navigate(`/issuers?edit=${issuer.id}`)}
|
|
className="px-3 py-1.5 border border-surface-border rounded text-ink text-xs hover:bg-surface-hover transition-colors font-medium"
|
|
>
|
|
Edit
|
|
</button>
|
|
<button
|
|
onClick={() => testMutation.mutate()}
|
|
disabled={testMutation.isPending}
|
|
className="btn btn-primary text-xs disabled:opacity-50"
|
|
>
|
|
{testMutation.isPending ? 'Testing...' : 'Test Connection'}
|
|
</button>
|
|
</div>
|
|
}
|
|
/>
|
|
|
|
<div className="flex-1 overflow-y-auto px-6 py-4 space-y-6">
|
|
{testMutation.isSuccess && (
|
|
<div className="px-4 py-2.5 bg-emerald-50 border border-emerald-200 rounded-lg text-sm text-emerald-700">
|
|
Connection test passed.
|
|
</div>
|
|
)}
|
|
{testMutation.isError && (
|
|
<div className="px-4 py-2.5 bg-red-50 border border-red-200 rounded-lg text-sm text-red-700">
|
|
Connection test failed: {(testMutation.error as Error).message}
|
|
</div>
|
|
)}
|
|
|
|
<div className="grid grid-cols-1 lg:grid-cols-2 gap-6">
|
|
{/* Issuer info */}
|
|
<div className="bg-surface border border-surface-border rounded p-5 shadow-sm">
|
|
<h3 className="text-sm font-semibold text-ink-muted mb-4">Issuer Information</h3>
|
|
<InfoRow label="ID" value={<span className="font-mono text-xs">{issuer.id}</span>} />
|
|
<InfoRow label="Name" value={issuer.name} />
|
|
<InfoRow label="Type" value={typeLabels[issuer.type] || issuer.type} />
|
|
<InfoRow label="Status" value={<StatusBadge status={issuerStatus(issuer)} />} />
|
|
<InfoRow label="Source" value={
|
|
<span className={`text-xs px-2 py-0.5 rounded-full ${
|
|
issuer.source === 'env' ? 'bg-amber-100 text-amber-700' : 'bg-blue-100 text-blue-700'
|
|
}`}>
|
|
{issuer.source === 'env' ? 'Environment Variable' : 'GUI Configured'}
|
|
</span>
|
|
} />
|
|
<InfoRow label="Connection Test" value={
|
|
issuer.test_status === 'success' ? (
|
|
<span className="text-xs text-emerald-600 font-medium">Passed {issuer.last_tested_at ? formatDateTime(issuer.last_tested_at) : ''}</span>
|
|
) : issuer.test_status === 'failed' ? (
|
|
<span className="text-xs text-red-600 font-medium">Failed {issuer.last_tested_at ? formatDateTime(issuer.last_tested_at) : ''}</span>
|
|
) : (
|
|
<span className="text-xs text-ink-faint">Not tested</span>
|
|
)
|
|
} />
|
|
<InfoRow label="Created" value={formatDateTime(issuer.created_at)} />
|
|
</div>
|
|
|
|
{/* Config (redacted) */}
|
|
<div className="bg-surface border border-surface-border rounded p-5 shadow-sm">
|
|
<h3 className="text-sm font-semibold text-ink-muted mb-4">Configuration</h3>
|
|
{Object.keys(safeConfig).length > 0 ? (
|
|
<div className="space-y-0">
|
|
{Object.entries(safeConfig).map(([key, val]) => (
|
|
<InfoRow key={key} label={key} value={
|
|
<span className="font-mono text-xs truncate max-w-xs inline-block">{String(val)}</span>
|
|
} />
|
|
))}
|
|
</div>
|
|
) : (
|
|
<div className="text-sm text-ink-faint py-4 text-center">No configuration data</div>
|
|
)}
|
|
</div>
|
|
</div>
|
|
|
|
{/* Issued certificates */}
|
|
<div className="bg-surface border border-surface-border rounded p-5 shadow-sm">
|
|
<h3 className="text-sm font-semibold text-ink-muted mb-4">
|
|
Issued Certificates {certsData ? `(${certsData.total})` : ''}
|
|
</h3>
|
|
<DataTable
|
|
columns={certColumns}
|
|
data={certsData?.data || []}
|
|
isLoading={!certsData}
|
|
emptyMessage="No certificates issued by this issuer"
|
|
/>
|
|
</div>
|
|
</div>
|
|
</>
|
|
);
|
|
}
|