fix(events): a source save keeps its stored verification (#2021)

A PUT that names no verification keeps the stored scheme, token hash and
sealed secret, and an hmac save with a blank secret keeps the sealed one.
The sources page gains an Edit action that reuses the add dialog.
This commit is contained in:
sam committed 2026-11-21 13:47:37 +11:00
1 parent 01eb4aaf7c
commit 30b4c28e06
2 files changed
+70 -22

No files matched your search

+31 -8
View File
@@ -55,17 +55,39 @@ async function put(name: string, connector: string, verification?: SourceVerific
}
const adding = ref(false);
const editing = ref<EventSource_ | null>(null);
const blank = { name: "", connector: "", verification: "token" as SourceVerification["verification"], hmac_header: "", hmac_prefix: "", hmac_secret: "" };
const draft = ref({ ...blank });
async function add(): Promise<void> {
const { name, connector, ...verification } = draft.value;
if (await put(name.trim(), connector, verification)) {
// Saving an unchanged token source must not rotate its token.
const keepsToken = editing.value?.verification === "token" && verification.verification === "token";
if (await put(name.trim(), connector, keepsToken ? undefined : verification)) {
adding.value = false;
editing.value = null;
draft.value = { ...blank };
}
}
// A blank secret keeps the stored one, so it is required only when a source
// has none yet.
const secretOptional = computed(() => editing.value?.verification === "hmac" && editing.value.hmac_secret_set);
const addDisabled = computed(() => busy.value || !draft.value.name || !draft.value.connector
|| (draft.value.verification === "hmac" && (!draft.value.hmac_header || !draft.value.hmac_secret)));
|| (draft.value.verification === "hmac" && (!draft.value.hmac_header || (!draft.value.hmac_secret && !secretOptional.value))));
function openAdd(): void {
editing.value = null;
draft.value = { ...blank };
adding.value = true;
actionError.value = "";
}
function openEdit(source: EventSource_): void {
editing.value = source;
draft.value = {
name: source.name, connector: source.connector, verification: source.verification,
hmac_header: source.hmac_header ?? "", hmac_prefix: source.hmac_prefix ?? "", hmac_secret: "",
};
adding.value = true;
actionError.value = "";
}
const keyFieldsOf = ref<EventSource_ | null>(null);
const keyFields = ref("");
@@ -104,7 +126,7 @@ const connectorNames = computed(() => (connectors.data.value ?? []).map((c) => c
<div v-else-if="!data" role="status" aria-label="Loading sources" class="space-y-2"><Skeleton class="h-8 w-full" /></div>
<template v-else>
<div class="mb-2 flex justify-end">
<Button size="sm" aria-label="Add source" title="Add source" @click="adding = true; actionError = ''"><Plus /></Button>
<Button size="sm" aria-label="Add source" title="Add source" @click="openAdd"><Plus /></Button>
</div>
<DataTable :columns="columns" :rows="data" :row-key="(s) => s.name" storage-key="sources">
<template #cell-name="{ row }"><span class="font-medium">{{ row.name }}</span></template>
@@ -113,8 +135,9 @@ const connectorNames = computed(() => (connectors.data.value ?? []).map((c) => c
<template #cell-key="{ row }"><span class="font-mono text-caption">{{ (row.key_fields ?? []).join(", ") || "Connector default" }}</span></template>
<template #actions="{ row }">
<MoreMenu :label="`${row.name} actions`">
<DropdownMenuItem @select="openEdit(row)">Edit…</DropdownMenuItem>
<DropdownMenuItem @select="editKeyFields(row)">Group by…</DropdownMenuItem>
<DropdownMenuItem v-if="row.verification === 'token'" :disabled="busy" @select="put(row.name, row.connector)">Rotate token</DropdownMenuItem>
<DropdownMenuItem v-if="row.verification === 'token'" :disabled="busy" @select="put(row.name, row.connector, { verification: 'token' })">Rotate token</DropdownMenuItem>
</MoreMenu>
</template>
<template #empty><Empty><EmptyHeader><EmptyTitle>No sources</EmptyTitle></EmptyHeader></Empty></template>
@@ -123,9 +146,9 @@ const connectorNames = computed(() => (connectors.data.value ?? []).map((c) => c
<Dialog v-model:open="adding">
<DialogContent>
<DialogHeader><DialogTitle>Add source</DialogTitle></DialogHeader>
<DialogHeader><DialogTitle>{{ editing ? `Edit ${editing.name}` : "Add source" }}</DialogTitle></DialogHeader>
<form id="add-source" class="space-y-3" @submit.prevent="add">
<Input v-model="draft.name" aria-label="Name" placeholder="alertmanager" pattern="[a-z0-9][a-z0-9-]*" required />
<Input v-model="draft.name" aria-label="Name" :disabled="!!editing" placeholder="alertmanager" pattern="[a-z0-9][a-z0-9-]*" required />
<Select v-model="draft.connector" required>
<SelectTrigger class="w-full" aria-label="Connector"><SelectValue placeholder="Connector that parses its events" /></SelectTrigger>
<SelectContent>
@@ -143,12 +166,12 @@ const connectorNames = computed(() => (connectors.data.value ?? []).map((c) => c
<template v-if="draft.verification === 'hmac'">
<Input v-model="draft.hmac_header" aria-label="Signature header" placeholder="X-Hub-Signature-256" required />
<Input v-model="draft.hmac_prefix" aria-label="Signature prefix" placeholder="sha256=" />
<Input v-model="draft.hmac_secret" type="password" aria-label="Signing secret" autocomplete="off" required />
<Input v-model="draft.hmac_secret" type="password" aria-label="Signing secret" autocomplete="off" :required="!secretOptional" :placeholder="secretOptional ? 'Leave blank to keep the current secret' : ''" />
</template>
<p v-if="connectors.error.value" class="text-caption text-danger">{{ connectors.error.value }}</p>
<p v-if="actionError" role="alert" class="text-caption text-danger">{{ actionError }}</p>
</form>
<DialogFooter><Button type="submit" form="add-source" :disabled="addDisabled">Add</Button></DialogFooter>
<DialogFooter><Button type="submit" form="add-source" :disabled="addDisabled">{{ editing ? "Save" : "Add" }}</Button></DialogFooter>
</DialogContent>
</Dialog>