fix(ui): reveal signing secret in canvas source creation
This commit is contained in:
1 parent
282f31fef2
commit
b6f0bfd765
4 files changed
+156
-105
No files matched your search
@@ -0,0 +1,55 @@
|
||||
<script setup lang="ts">
|
||||
import { computed, ref } from "vue";
|
||||
import { Check, Copy, KeyRound, X } from "@lucide/vue";
|
||||
import { Alert, AlertDescription, AlertTitle } from "@/components/ui/alert";
|
||||
import { Button } from "@/components/ui/button";
|
||||
import { sourceURL, type Source } from "./source-signing";
|
||||
|
||||
const props = defineProps<{ source: Source }>();
|
||||
const emit = defineEmits<{ dismiss: [] }>();
|
||||
const url = computed(() => sourceURL(window.location.origin, props.source.path));
|
||||
const copied = ref<string | null>(null);
|
||||
async function copy(value: string): Promise<void> {
|
||||
await navigator.clipboard.writeText(value);
|
||||
copied.value = value;
|
||||
setTimeout(() => (copied.value = null), 1500);
|
||||
}
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<Alert>
|
||||
<KeyRound />
|
||||
<AlertTitle class="flex items-center justify-between gap-2 text-xs">
|
||||
<span class="font-mono"
|
||||
>{{ source.path }} · signing secret, shown once</span
|
||||
>
|
||||
<Button
|
||||
type="button"
|
||||
variant="ghost"
|
||||
size="icon-sm"
|
||||
aria-label="Dismiss"
|
||||
@click="emit('dismiss')"
|
||||
><X
|
||||
/></Button>
|
||||
</AlertTitle>
|
||||
<AlertDescription class="col-start-2 flex items-center gap-2">
|
||||
<code class="min-w-0 flex-1 break-all font-mono text-xs">{{ url }}</code>
|
||||
<Button type="button" variant="ghost" size="icon-sm" aria-label="Copy URL" @click="copy(url)"><Check v-if="copied === url" /><Copy v-else /></Button>
|
||||
</AlertDescription>
|
||||
<AlertDescription class="col-start-2 flex items-center gap-2">
|
||||
<code class="min-w-0 flex-1 break-all font-mono text-xs">{{
|
||||
source.secret
|
||||
}}</code>
|
||||
<Button
|
||||
type="button"
|
||||
variant="ghost"
|
||||
size="icon-sm"
|
||||
aria-label="Copy secret"
|
||||
@click="copy(source.secret || '')"
|
||||
>
|
||||
<Check v-if="copied === source.secret" />
|
||||
<Copy v-else />
|
||||
</Button>
|
||||
</AlertDescription>
|
||||
</Alert>
|
||||
</template>
|
||||
@@ -1,5 +1,5 @@
|
||||
<script setup lang="ts">
|
||||
import { Check, Copy, KeyRound, Lock, LockOpen, Plus, X } from "@lucide/vue";
|
||||
import { Check, Copy, KeyRound, Lock, LockOpen, Plus } from "@lucide/vue";
|
||||
import { onMounted, ref } from "vue";
|
||||
|
||||
import { Alert, AlertDescription, AlertTitle } from "@/components/ui/alert";
|
||||
@@ -27,6 +27,7 @@ import {
|
||||
sourceURL,
|
||||
type Source,
|
||||
} from "./source-signing";
|
||||
import SourceSecret from "./SourceSecret.vue";
|
||||
import { useSources } from "./use-sources";
|
||||
|
||||
/**
|
||||
@@ -93,35 +94,7 @@ function url(source: Source): string {
|
||||
<AlertDescription>{{ failure }}</AlertDescription>
|
||||
</Alert>
|
||||
|
||||
<Alert v-if="revealed">
|
||||
<KeyRound />
|
||||
<AlertTitle class="flex items-center justify-between gap-2">
|
||||
<span class="font-mono"
|
||||
>{{ revealed.path }} · signing secret, shown once</span
|
||||
>
|
||||
<Button
|
||||
variant="ghost"
|
||||
size="icon-sm"
|
||||
aria-label="Dismiss"
|
||||
@click="revealed = null"
|
||||
><X
|
||||
/></Button>
|
||||
</AlertTitle>
|
||||
<AlertDescription class="flex items-center gap-2">
|
||||
<code class="min-w-0 break-all font-mono text-xs">{{
|
||||
revealed.secret
|
||||
}}</code>
|
||||
<Button
|
||||
variant="ghost"
|
||||
size="icon-sm"
|
||||
aria-label="Copy secret"
|
||||
@click="copy(revealed.secret || '')"
|
||||
>
|
||||
<Check v-if="copied === revealed.secret" />
|
||||
<Copy v-else />
|
||||
</Button>
|
||||
</AlertDescription>
|
||||
</Alert>
|
||||
<SourceSecret v-if="revealed" :source="revealed" @dismiss="revealed = null" />
|
||||
|
||||
<Card v-if="sources && sources.length">
|
||||
<CardContent>
|
||||
|
||||
@@ -9,7 +9,8 @@ import { api } from "@/lib/api";
|
||||
import { useLiveResource } from "@/stores/live-updates";
|
||||
import { statusKind, statusLabel, takesRepository, type Binding } from "@/bindings/binding-draft";
|
||||
import type { Capture } from "@/captures/state";
|
||||
import { sourceURL } from "@/sources/source-signing";
|
||||
import SourceSecret from "@/sources/SourceSecret.vue";
|
||||
import { sourceURL, type Source } from "@/sources/source-signing";
|
||||
import type { EventType } from "@/captures/event-types";
|
||||
import type { Mapping, Preview } from "@/mappings/state";
|
||||
import {
|
||||
@@ -51,6 +52,8 @@ const rows = ref<Record<string, InputRow>>({});
|
||||
const repositoryPath = ref("");
|
||||
const preview = ref<Preview | null>(null);
|
||||
const saving = ref(false);
|
||||
const creatingSource = ref(false);
|
||||
const revealed = ref<Source | null>(null);
|
||||
const error = ref("");
|
||||
const status = ref(props.binding?.status ?? "");
|
||||
|
||||
@@ -113,6 +116,7 @@ watch([fields, captureId], () => {
|
||||
|
||||
const blockers = computed(() => {
|
||||
if (!sourcePath.value) return ["pick a source"];
|
||||
if (source.value === NEW_SOURCE) return ["create the source first"];
|
||||
if (!capture.value) return [`no event from ${sourcePath.value} yet to preview against`];
|
||||
if (payload.value === null) return ["the picked event's body is not JSON"];
|
||||
return problems(inputs.value, rows.value, preview.value);
|
||||
@@ -148,12 +152,28 @@ async function eventTypeFor(c: Capture): Promise<string> {
|
||||
return created.id;
|
||||
}
|
||||
|
||||
async function createSource(): Promise<void> {
|
||||
if (!sourcePath.value || creatingSource.value) return;
|
||||
creatingSource.value = true;
|
||||
error.value = "";
|
||||
try {
|
||||
const created = await api.sourceCreate<Source>(sourcePath.value);
|
||||
revealed.value = created;
|
||||
sources.value.push(created.path);
|
||||
source.value = created.path;
|
||||
newSource.value = "";
|
||||
} catch (err) {
|
||||
error.value = err instanceof Error ? err.message : String(err);
|
||||
} finally {
|
||||
creatingSource.value = false;
|
||||
}
|
||||
}
|
||||
|
||||
async function save(): Promise<void> {
|
||||
if (blockers.value.length || !capture.value) return;
|
||||
saving.value = true;
|
||||
error.value = "";
|
||||
try {
|
||||
if (source.value === NEW_SOURCE && !sources.value.includes(sourcePath.value)) await api.sourceCreate(sourcePath.value);
|
||||
const mappingBody = {
|
||||
name: `${workflow.value} ← ${sourcePath.value}`,
|
||||
event_type_id: await eventTypeFor(capture.value),
|
||||
@@ -221,8 +241,11 @@ async function approve(): Promise<void> {
|
||||
placeholder="path, e.g. alertmanager"
|
||||
class="h-8 w-full rounded-md border border-input bg-background px-2 font-mono text-[13px]"
|
||||
/>
|
||||
<Button v-if="source === NEW_SOURCE" type="button" size="sm" :disabled="creatingSource || !sourcePath" @click="createSource"><Spinner v-if="creatingSource" />Create source</Button>
|
||||
</section>
|
||||
|
||||
<SourceSecret v-if="revealed" :source="revealed" @dismiss="revealed = null" />
|
||||
|
||||
<section v-if="sourcePath" class="space-y-1.5">
|
||||
<label for="bind-capture" class="text-xs font-medium text-muted-foreground">Example event</label>
|
||||
<select v-if="sourceCaptures.length" id="bind-capture" v-model="captureId" class="h-8 w-full rounded-md border border-input bg-background px-2 text-[13px]">
|
||||
|
||||
Reference in new issue
Block a user