feat(gui): add create modals for issuers, policies, profiles, owners, teams, agent groups

Six pages were read-only viewers despite the API client having all
create functions wired up. Users deploying certctl had no way to create
CAs or other objects from the GUI — reported in GitHub issue.

- IssuersPage: 2-step create modal (type selection → config) for
  Local CA, ACME, step-ca, OpenSSL/Custom issuer types
- PoliciesPage: create modal with type, severity, JSON config, enabled
- ProfilesPage: create modal with name, description, max TTL, short-lived
- OwnersPage: create modal with name, email, team dropdown
- TeamsPage: create modal with name, description
- AgentGroupsPage: create modal with match criteria fields
- Layout.tsx: version v2.0.5 → v2.0.7
- cmd/server/main.go: version 0.1.0 → 2.0.7

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
shankar0123
2026-03-28 07:36:58 -04:00
parent 9b5b9ad3a2
commit baafab50c5
8 changed files with 975 additions and 14 deletions
+133 -2
View File
@@ -1,5 +1,6 @@
import { useState } from 'react';
import { useQuery, useMutation, useQueryClient } from '@tanstack/react-query';
import { getProfiles, deleteProfile } from '../api/client';
import { getProfiles, deleteProfile, createProfile } from '../api/client';
import PageHeader from '../components/PageHeader';
import DataTable from '../components/DataTable';
import type { Column } from '../components/DataTable';
@@ -16,8 +17,115 @@ function formatTTL(seconds: number): string {
return `${Math.floor(seconds / 86400)}d`;
}
interface CreateProfileModalProps {
isOpen: boolean;
onClose: () => void;
onSuccess: () => void;
isLoading: boolean;
error: string | null;
}
function CreateProfileModal({ isOpen, onClose, onSuccess, isLoading, error }: CreateProfileModalProps) {
const [name, setName] = useState('');
const [description, setDescription] = useState('');
const [ttl, setTtl] = useState('86400');
const [shortLived, setShortLived] = useState(false);
const handleSubmit = async (e: React.FormEvent) => {
e.preventDefault();
if (!name.trim()) return;
try {
await createProfile({
name: name.trim(),
description: description.trim(),
max_ttl_seconds: parseInt(ttl) || 86400,
allow_short_lived: shortLived,
enabled: true,
});
setName('');
setDescription('');
setTtl('86400');
setShortLived(false);
onSuccess();
} catch (err) {
console.error('Create profile error:', err);
}
};
if (!isOpen) return null;
return (
<div className="fixed inset-0 bg-black/40 flex items-center justify-center z-50" onClick={onClose}>
<div className="bg-surface border border-surface-border rounded p-5 w-full max-w-md shadow-xl" onClick={e => e.stopPropagation()}>
<h2 className="text-lg font-semibold text-ink mb-4">Create Profile</h2>
{error && <div className="mb-4 p-3 bg-red-50 border border-red-200 rounded text-sm text-red-700">{error}</div>}
<form onSubmit={handleSubmit} className="space-y-4">
<div>
<label className="block text-sm font-medium text-ink mb-1">Name *</label>
<input
value={name}
onChange={e => setName(e.target.value)}
className="w-full bg-white border border-surface-border rounded px-3 py-2 text-sm text-ink focus:outline-none focus:border-brand-400"
placeholder="e.g., Web Server Certs"
required
/>
</div>
<div>
<label className="block text-sm font-medium text-ink mb-1">Description</label>
<textarea
value={description}
onChange={e => setDescription(e.target.value)}
className="w-full bg-white border border-surface-border rounded px-3 py-2 text-sm text-ink focus:outline-none focus:border-brand-400"
placeholder="Optional description"
rows={2}
/>
</div>
<div>
<label className="block text-sm font-medium text-ink mb-1">Max TTL (seconds)</label>
<input
type="number"
value={ttl}
onChange={e => setTtl(e.target.value)}
className="w-full bg-white border border-surface-border rounded px-3 py-2 text-sm text-ink focus:outline-none focus:border-brand-400"
placeholder="86400"
/>
<p className="text-xs text-ink-muted mt-1">e.g. 86400 = 1 day, 2592000 = 30 days</p>
</div>
<div className="flex items-center gap-2">
<input
type="checkbox"
id="shortLived"
checked={shortLived}
onChange={e => setShortLived(e.target.checked)}
className="w-4 h-4"
/>
<label htmlFor="shortLived" className="text-sm text-ink">Allow short-lived certs</label>
</div>
<div className="flex gap-2 pt-4">
<button
type="submit"
disabled={isLoading}
className="flex-1 btn btn-primary disabled:opacity-50 disabled:cursor-not-allowed"
>
{isLoading ? 'Creating...' : 'Create Profile'}
</button>
<button
type="button"
onClick={onClose}
className="flex-1 btn btn-ghost"
>
Cancel
</button>
</div>
</form>
</div>
</div>
);
}
export default function ProfilesPage() {
const queryClient = useQueryClient();
const [showCreate, setShowCreate] = useState(false);
const { data, isLoading, error, refetch } = useQuery({
queryKey: ['profiles'],
@@ -29,6 +137,14 @@ export default function ProfilesPage() {
onSuccess: () => queryClient.invalidateQueries({ queryKey: ['profiles'] }),
});
const createMutation = useMutation({
mutationFn: createProfile,
onSuccess: () => {
queryClient.invalidateQueries({ queryKey: ['profiles'] });
setShowCreate(false);
},
});
const columns: Column<CertificateProfile>[] = [
{
key: 'name',
@@ -116,7 +232,15 @@ export default function ProfilesPage() {
return (
<>
<PageHeader title="Certificate Profiles" subtitle={data ? `${data.total} profiles` : undefined} />
<PageHeader
title="Certificate Profiles"
subtitle={data ? `${data.total} profiles` : undefined}
action={
<button onClick={() => setShowCreate(true)} className="btn btn-primary">
+ New Profile
</button>
}
/>
<div className="flex-1 overflow-y-auto">
{error ? (
<ErrorState error={error as Error} onRetry={() => refetch()} />
@@ -124,6 +248,13 @@ export default function ProfilesPage() {
<DataTable columns={columns} data={data?.data || []} isLoading={isLoading} emptyMessage="No profiles configured" />
)}
</div>
<CreateProfileModal
isOpen={showCreate}
onClose={() => setShowCreate(false)}
onSuccess={() => {}}
isLoading={createMutation.isPending}
error={createMutation.error ? (createMutation.error as Error).message : null}
/>
</>
);
}