feat(ui): add enterprise auth, audit log, four-eyes SoD, and promotion bundles UI (#2153)
This commit is contained in:
9 files changed
+1039
-43
No files matched your search
+11
-1
@@ -74,6 +74,11 @@
|
||||
"label": "Approvals",
|
||||
"description": "Default owner, escalation path, approval deadline and the approvals that earn an autonomy proposal."
|
||||
},
|
||||
{
|
||||
"path": "/org/audit",
|
||||
"label": "Audit log",
|
||||
"description": "Append-only record of identity, access, workflow and governance events."
|
||||
},
|
||||
{
|
||||
"path": "/org/connections",
|
||||
"label": "Connections",
|
||||
@@ -142,7 +147,12 @@
|
||||
{
|
||||
"path": "/settings/authentication",
|
||||
"label": "Authentication",
|
||||
"description": "Instance URL and single sign-on providers."
|
||||
"description": "Instance URL, single sign-on providers and session lifetimes."
|
||||
},
|
||||
{
|
||||
"path": "/settings/bundles",
|
||||
"label": "Promotion bundles",
|
||||
"description": "Export, diff and apply immutable environment bundles."
|
||||
},
|
||||
{
|
||||
"path": "/settings/credentials",
|
||||
|
||||
@@ -549,6 +549,19 @@ export const api = {
|
||||
headers: { Accept: "text/event-stream" },
|
||||
signal: opts.signal,
|
||||
}),
|
||||
auditEvents: (params: QueryParams = {}) =>
|
||||
request<AuditEventsResponse>("/api/audit/events" + qs(params)),
|
||||
auditExportUrl: (params: QueryParams = {}) =>
|
||||
"/api/audit/events/export" + qs(params),
|
||||
exportBundle: () => request<BundleExportReply>("/api/bundles/export"),
|
||||
diffBundle: (body: { bundle_yaml: string }) =>
|
||||
request<BundleDiffReply>("/api/bundles/diff", { method: "POST", body }),
|
||||
applyBundle: (body: {
|
||||
bundle_yaml: string;
|
||||
bindings_yaml?: string;
|
||||
dry_run?: boolean;
|
||||
expect_digest?: string;
|
||||
}) => request<BundleApplyReply>("/api/bundles/apply", { method: "POST", body }),
|
||||
};
|
||||
|
||||
/** One note, in one memory class. A note is readable only in its scope: a
|
||||
@@ -812,6 +825,8 @@ export interface Approval {
|
||||
level: string;
|
||||
summary: string;
|
||||
state: string;
|
||||
initiator_id?: string;
|
||||
require_sod?: boolean;
|
||||
/** The actions the request covers, in the order they run. An autonomy
|
||||
* proposal covers none. */
|
||||
steps?: ApprovalStep[];
|
||||
@@ -823,6 +838,63 @@ export interface Approval {
|
||||
answered_via?: string;
|
||||
}
|
||||
|
||||
export interface AuditEvent {
|
||||
id: string;
|
||||
org_id: string;
|
||||
at: string;
|
||||
category: string;
|
||||
action: string;
|
||||
actor_id: string;
|
||||
actor_kind?: string;
|
||||
resource_kind?: string;
|
||||
resource_id?: string;
|
||||
outcome: string;
|
||||
trace_id?: string;
|
||||
detail?: Record<string, unknown>;
|
||||
}
|
||||
|
||||
export interface AuditEventsResponse {
|
||||
events: AuditEvent[];
|
||||
more: boolean;
|
||||
}
|
||||
|
||||
export interface BundleDiff {
|
||||
workflows?: { op: string; name: string; details?: string[] }[];
|
||||
access_policies?: { op: string; id: string }[];
|
||||
judgement_rules?: { op: string; kind: string }[];
|
||||
action_types?: {
|
||||
op: string;
|
||||
connector: string;
|
||||
action: string;
|
||||
target_kind: string;
|
||||
environment: string;
|
||||
details?: string[];
|
||||
}[];
|
||||
}
|
||||
|
||||
export interface BundleExportReply {
|
||||
schema_version: string;
|
||||
exported_at: string;
|
||||
digest: string;
|
||||
bundle_yaml: string;
|
||||
}
|
||||
|
||||
export interface BundleDiffReply {
|
||||
digest: string;
|
||||
empty: boolean;
|
||||
formatted: string;
|
||||
diff: BundleDiff;
|
||||
}
|
||||
|
||||
export interface BundleApplyReply {
|
||||
digest: string;
|
||||
dry_run: boolean;
|
||||
applied: boolean;
|
||||
empty: boolean;
|
||||
formatted: string;
|
||||
diff: BundleDiff;
|
||||
}
|
||||
|
||||
interface Decision {
|
||||
id: string;
|
||||
level: string;
|
||||
|
||||
@@ -40,7 +40,7 @@ export const orgSpecs: NavSpec[] = [
|
||||
sections: [
|
||||
{
|
||||
label: "People & access",
|
||||
paths: ["/org/members", "/org/approvals", "/org/workspaces", "/org/policies", "/org/decisions"],
|
||||
paths: ["/org/members", "/org/approvals", "/org/workspaces", "/org/policies", "/org/decisions", "/org/audit"],
|
||||
},
|
||||
{
|
||||
label: "Agents",
|
||||
@@ -64,7 +64,7 @@ export const settings: NavSpec = {
|
||||
label: "Connections & channels",
|
||||
paths: ["/settings/extensions", "/settings/secret-engines", "/settings/credentials"],
|
||||
},
|
||||
{ paths: ["/settings/status", "/settings/organisations", "/settings/authentication"] },
|
||||
{ paths: ["/settings/status", "/settings/organisations", "/settings/authentication", "/settings/bundles"] },
|
||||
],
|
||||
};
|
||||
|
||||
|
||||
@@ -0,0 +1,210 @@
|
||||
<script setup lang="ts">
|
||||
definePage({
|
||||
name: "org-audit",
|
||||
meta: {
|
||||
navPath: "/org",
|
||||
label: "Audit log",
|
||||
description: "Append-only record of identity, access, workflow and governance events.",
|
||||
section: "org_decisions",
|
||||
},
|
||||
});
|
||||
|
||||
import { Download } from "@lucide/vue";
|
||||
import { computed, onMounted } from "vue";
|
||||
|
||||
import CodeView from "@/base/CodeView.vue";
|
||||
import PageHeader from "@/base/PageHeader.vue";
|
||||
import { Badge } from "@/components/ui/badge";
|
||||
import { Button } from "@/components/ui/button";
|
||||
import { DataTable, type DataTableColumn } from "@/components/ui/data-table";
|
||||
import { Empty, EmptyHeader, EmptyTitle } from "@/components/ui/empty";
|
||||
import { Input } from "@/components/ui/input";
|
||||
import { MetadataList } from "@/components/ui/metadata-list";
|
||||
import { ReadError } from "@/components/ui/read-error";
|
||||
import { Section } from "@/components/ui/section";
|
||||
import { Skeleton } from "@/components/ui/skeleton";
|
||||
import { StatusDot } from "@/components/ui/status-dot";
|
||||
import { Timestamp } from "@/components/ui/timestamp";
|
||||
import type { AuditEvent } from "@/lib/api";
|
||||
import UserReference from "@/org/UserReference.vue";
|
||||
import { useAuditStore } from "@/stores/audit";
|
||||
|
||||
const store = useAuditStore();
|
||||
|
||||
onMounted(() => {
|
||||
void store.load(true);
|
||||
});
|
||||
|
||||
const hasActiveFilters = computed(() =>
|
||||
Boolean(
|
||||
store.filters.category.trim() ||
|
||||
store.filters.action.trim() ||
|
||||
store.filters.actor.trim() ||
|
||||
store.filters.since.trim() ||
|
||||
store.filters.until.trim(),
|
||||
),
|
||||
);
|
||||
|
||||
const columns: DataTableColumn<AuditEvent>[] = [
|
||||
{ id: "at", label: "Time", fixed: true, width: "11rem", sort: (row) => row.at },
|
||||
{ id: "category", label: "Category", width: "8rem", sort: (row) => row.category },
|
||||
{ id: "action", label: "Action", width: "12rem", sort: (row) => row.action },
|
||||
{ id: "actor_id", label: "Actor", width: "auto" },
|
||||
{ id: "resource", label: "Resource", hide: "sm", width: "12rem" },
|
||||
{ id: "outcome", label: "Outcome", width: "7.5rem", sort: (row) => row.outcome },
|
||||
];
|
||||
|
||||
function outcomeTone(outcome: string): "ok" | "warn" | "danger" | "idle" {
|
||||
switch (outcome) {
|
||||
case "success":
|
||||
case "allowed":
|
||||
case "approved":
|
||||
return "ok";
|
||||
case "denied":
|
||||
case "refused":
|
||||
case "rejected":
|
||||
return "warn";
|
||||
case "error":
|
||||
case "failed":
|
||||
return "danger";
|
||||
default:
|
||||
return "idle";
|
||||
}
|
||||
}
|
||||
|
||||
function detailRows(row: AuditEvent): { label: string; value: string; mono?: boolean }[] {
|
||||
const rows: { label: string; value: string; mono?: boolean }[] = [
|
||||
{ label: "Event ID", value: row.id, mono: true },
|
||||
];
|
||||
if (row.actor_kind) rows.push({ label: "Actor kind", value: row.actor_kind });
|
||||
if (row.trace_id) rows.push({ label: "Trace ID", value: row.trace_id, mono: true });
|
||||
return rows;
|
||||
}
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<div>
|
||||
<PageHeader title="Audit log">
|
||||
<Button as-child variant="outline" size="sm">
|
||||
<a :href="store.exportUrl('jsonl')" download="audit-events.jsonl">
|
||||
<Download class="size-4" />
|
||||
Export JSONL
|
||||
</a>
|
||||
</Button>
|
||||
<Button as-child variant="outline" size="sm">
|
||||
<a :href="store.exportUrl('csv')" download="audit-events.csv">
|
||||
<Download class="size-4" />
|
||||
Export CSV
|
||||
</a>
|
||||
</Button>
|
||||
</PageHeader>
|
||||
|
||||
<Section title="Filter">
|
||||
<form class="grid gap-3 sm:grid-cols-2 lg:grid-cols-5" @submit.prevent="store.load(true)">
|
||||
<div>
|
||||
<label for="audit-category" class="mb-1 block text-caption text-fg-muted">Category</label>
|
||||
<Input id="audit-category" v-model="store.filters.category" placeholder="identity, access…" />
|
||||
</div>
|
||||
<div>
|
||||
<label for="audit-action" class="mb-1 block text-caption text-fg-muted">Action</label>
|
||||
<Input id="audit-action" v-model="store.filters.action" placeholder="login, bundle.apply…" />
|
||||
</div>
|
||||
<div>
|
||||
<label for="audit-actor" class="mb-1 block text-caption text-fg-muted">Actor</label>
|
||||
<Input id="audit-actor" v-model="store.filters.actor" placeholder="Identity ID" class="font-mono" />
|
||||
</div>
|
||||
<div>
|
||||
<label for="audit-since" class="mb-1 block text-caption text-fg-muted">Since</label>
|
||||
<Input id="audit-since" v-model="store.filters.since" type="datetime-local" />
|
||||
</div>
|
||||
<div>
|
||||
<label for="audit-until" class="mb-1 block text-caption text-fg-muted">Until</label>
|
||||
<Input id="audit-until" v-model="store.filters.until" type="datetime-local" />
|
||||
</div>
|
||||
<div class="flex flex-wrap items-center gap-2 sm:col-span-2 lg:col-span-5">
|
||||
<Button type="submit" size="sm" :disabled="store.loading">Apply</Button>
|
||||
<Button
|
||||
v-if="hasActiveFilters"
|
||||
type="button"
|
||||
variant="ghost"
|
||||
size="sm"
|
||||
:disabled="store.loading"
|
||||
@click="store.resetFilters"
|
||||
>
|
||||
Reset
|
||||
</Button>
|
||||
</div>
|
||||
</form>
|
||||
</Section>
|
||||
|
||||
<ReadError
|
||||
v-if="store.error"
|
||||
:message="store.error"
|
||||
retry-label="Retry"
|
||||
class="mb-4"
|
||||
@retry="store.load(true)"
|
||||
/>
|
||||
|
||||
<div v-else-if="store.loading && !store.events.length" role="status" aria-label="Loading audit log" class="space-y-2 py-2">
|
||||
<Skeleton class="h-9 w-full" />
|
||||
<Skeleton class="h-9 w-full" />
|
||||
<Skeleton class="h-9 w-full" />
|
||||
</div>
|
||||
|
||||
<Empty v-else-if="!store.events.length" class="border border-border">
|
||||
<EmptyHeader>
|
||||
<EmptyTitle>No audit events recorded</EmptyTitle>
|
||||
</EmptyHeader>
|
||||
</Empty>
|
||||
|
||||
<template v-else>
|
||||
<DataTable
|
||||
:columns="columns"
|
||||
:rows="store.events"
|
||||
:row-key="(row) => row.id"
|
||||
storage-key="org-audit"
|
||||
:initial-sort="{ id: 'at', desc: true }"
|
||||
>
|
||||
<template #cell-at="{ row }">
|
||||
<Timestamp :at="row.at" class="text-caption" />
|
||||
</template>
|
||||
<template #cell-category="{ row }">
|
||||
<Badge variant="outline">{{ row.category }}</Badge>
|
||||
</template>
|
||||
<template #cell-action="{ row }">
|
||||
<span class="font-mono text-caption">{{ row.action }}</span>
|
||||
</template>
|
||||
<template #cell-actor_id="{ row }">
|
||||
<UserReference :id="row.actor_id" :kind="row.actor_kind" fallback="system" class="text-caption" />
|
||||
</template>
|
||||
<template #cell-resource="{ row }">
|
||||
<span v-if="row.resource_kind || row.resource_id" class="font-mono text-caption text-fg-muted">
|
||||
{{ [row.resource_kind, row.resource_id].filter(Boolean).join(":") }}
|
||||
</span>
|
||||
<span v-else class="text-caption text-fg-muted">—</span>
|
||||
</template>
|
||||
<template #cell-outcome="{ row }">
|
||||
<span class="inline-flex items-center gap-1.5 text-caption">
|
||||
<StatusDot :tone="outcomeTone(row.outcome)" />
|
||||
{{ row.outcome }}
|
||||
</span>
|
||||
</template>
|
||||
<template #detail="{ row }">
|
||||
<MetadataList :rows="detailRows(row)" />
|
||||
<CodeView
|
||||
v-if="row.detail && Object.keys(row.detail).length"
|
||||
:code="JSON.stringify(row.detail, null, 2)"
|
||||
lang="json"
|
||||
class="mt-3"
|
||||
/>
|
||||
</template>
|
||||
</DataTable>
|
||||
|
||||
<div v-if="store.more" class="mt-4 flex justify-center">
|
||||
<Button variant="outline" size="sm" :disabled="store.loading" @click="store.load(false)">
|
||||
{{ store.loading ? "Loading…" : "Load older" }}
|
||||
</Button>
|
||||
</div>
|
||||
</template>
|
||||
</div>
|
||||
</template>
|
||||
@@ -5,52 +5,311 @@ definePage({
|
||||
navPath: "/settings",
|
||||
settings: true,
|
||||
label: "Authentication",
|
||||
description: "Instance URL and single sign-on providers.",
|
||||
description: "Instance URL, single sign-on providers and session lifetimes.",
|
||||
section: "settings",
|
||||
},
|
||||
});
|
||||
|
||||
import { ReadError } from "@/components/ui/read-error";
|
||||
import { Skeleton } from "@/components/ui/skeleton";
|
||||
import { Check } from "@lucide/vue";
|
||||
import { Check, Plus, Trash2 } from "@lucide/vue";
|
||||
import { computed, onMounted, ref } from "vue";
|
||||
import PageHeader from "@/base/PageHeader.vue";
|
||||
import { Button } from "@/components/ui/button";
|
||||
|
||||
import CodeView from "@/base/CodeView.vue";
|
||||
import PageHeader from "@/base/PageHeader.vue";
|
||||
import { Badge } from "@/components/ui/badge";
|
||||
import { Button } from "@/components/ui/button";
|
||||
import { Input } from "@/components/ui/input";
|
||||
import { Textarea } from "@/components/ui/textarea";
|
||||
import { api, classifyActionError, describeError } from "@/lib/api";
|
||||
import { errors } from "@/copy/errors";
|
||||
import { SettingRow } from "@/components/ui/setting-row";
|
||||
import { ReadError } from "@/components/ui/read-error";
|
||||
import { Section } from "@/components/ui/section";
|
||||
interface Settings {public_url:string;oidc_issuer:string;oidc_audience:string;oidc_client_id:string;trusted_proxies:string[]}
|
||||
const value=ref<Settings>({public_url:"",oidc_issuer:"",oidc_audience:"",oidc_client_id:"",trusted_proxies:[]});const loaded=ref(false);const error=ref("");const sessionExpired=ref(false);const busy=ref(false);const saved=ref(false);
|
||||
async function load(){try{value.value=await api.authentication<Settings>();loaded.value=true;error.value=""}catch(cause){error.value=describeError(cause, errors.common.unknown)}finally{loaded.value=true}}
|
||||
import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue } from "@/components/ui/select";
|
||||
import { SettingRow } from "@/components/ui/setting-row";
|
||||
import { Skeleton } from "@/components/ui/skeleton";
|
||||
import { Switch } from "@/components/ui/switch";
|
||||
import { Textarea } from "@/components/ui/textarea";
|
||||
import { errors } from "@/copy/errors";
|
||||
import { api, classifyActionError, describeError } from "@/lib/api";
|
||||
|
||||
interface Settings {
|
||||
public_url: string;
|
||||
oidc_issuer: string;
|
||||
oidc_audience: string;
|
||||
oidc_client_id: string;
|
||||
oidc_client_secret?: string;
|
||||
oidc_client_secret_set?: boolean;
|
||||
oidc_groups_claim?: string;
|
||||
oidc_role_map?: Record<string, string>;
|
||||
sso_only: boolean;
|
||||
session_idle_timeout_s: number;
|
||||
session_max_lifetime_s: number;
|
||||
trusted_proxies: string[];
|
||||
}
|
||||
|
||||
interface RoleMappingRow {
|
||||
group: string;
|
||||
role: string;
|
||||
}
|
||||
|
||||
const ROLES = ["owner", "admin", "developer", "viewer"] as const;
|
||||
|
||||
const value = ref<Settings>({
|
||||
public_url: "",
|
||||
oidc_issuer: "",
|
||||
oidc_audience: "",
|
||||
oidc_client_id: "",
|
||||
oidc_groups_claim: "",
|
||||
sso_only: false,
|
||||
session_idle_timeout_s: 0,
|
||||
session_max_lifetime_s: 0,
|
||||
trusted_proxies: [],
|
||||
});
|
||||
const clientSecret = ref("");
|
||||
const roleMapRows = ref<RoleMappingRow[]>([]);
|
||||
const loaded = ref(false);
|
||||
const error = ref("");
|
||||
const sessionExpired = ref(false);
|
||||
const busy = ref(false);
|
||||
const saved = ref(false);
|
||||
|
||||
let loadAttempt = 0;
|
||||
|
||||
async function load(): Promise<void> {
|
||||
const attempt = ++loadAttempt;
|
||||
try {
|
||||
const data = await api.authentication<Settings>();
|
||||
if (attempt !== loadAttempt) return;
|
||||
value.value = {
|
||||
public_url: data.public_url ?? "",
|
||||
oidc_issuer: data.oidc_issuer ?? "",
|
||||
oidc_audience: data.oidc_audience ?? "",
|
||||
oidc_client_id: data.oidc_client_id ?? "",
|
||||
oidc_client_secret_set: Boolean(data.oidc_client_secret_set),
|
||||
oidc_groups_claim: data.oidc_groups_claim ?? "",
|
||||
oidc_role_map: data.oidc_role_map ?? {},
|
||||
sso_only: Boolean(data.sso_only),
|
||||
session_idle_timeout_s: data.session_idle_timeout_s ?? 0,
|
||||
session_max_lifetime_s: data.session_max_lifetime_s ?? 0,
|
||||
trusted_proxies: data.trusted_proxies ?? [],
|
||||
};
|
||||
roleMapRows.value = Object.entries(data.oidc_role_map ?? {}).map(([group, role]) => ({
|
||||
group,
|
||||
role,
|
||||
}));
|
||||
error.value = "";
|
||||
sessionExpired.value = false;
|
||||
} catch (cause) {
|
||||
if (attempt !== loadAttempt) return;
|
||||
error.value = describeError(cause, errors.common.unknown);
|
||||
} finally {
|
||||
if (attempt === loadAttempt) loaded.value = true;
|
||||
}
|
||||
}
|
||||
onMounted(load);
|
||||
const proxyText=computed({get:()=>value.value.trusted_proxies.join("\n"),set:(text:string|number)=>{value.value.trusted_proxies=String(text).split("\n")}});
|
||||
const redirectURI=computed(()=>`${value.value.public_url.replace(/\/$/,"")}/oauth2/callback`);
|
||||
async function save(){busy.value=true;error.value="";saved.value=false;try{await api.saveAuthentication(value.value);saved.value=true}catch(cause){error.value=describeError(cause, errors.common.unknown);sessionExpired.value=classifyActionError(cause).kind==="session-expired"}finally{busy.value=false}}
|
||||
|
||||
const proxyText = computed({
|
||||
get: () => value.value.trusted_proxies.join("\n"),
|
||||
set: (text: string | number) => {
|
||||
value.value.trusted_proxies = String(text).split("\n");
|
||||
},
|
||||
});
|
||||
|
||||
const publicBase = computed(() => value.value.public_url.replace(/\/$/, ""));
|
||||
const redirectURI = computed(() => `${publicBase.value}/oauth2/callback`);
|
||||
const backchannelLogoutURI = computed(() => `${publicBase.value}/oauth2/backchannel-logout`);
|
||||
|
||||
function addRoleMapping(): void {
|
||||
roleMapRows.value.push({ group: "", role: "viewer" });
|
||||
}
|
||||
|
||||
function removeRoleMapping(index: number): void {
|
||||
roleMapRows.value.splice(index, 1);
|
||||
}
|
||||
|
||||
async function save(): Promise<void> {
|
||||
busy.value = true;
|
||||
error.value = "";
|
||||
sessionExpired.value = false;
|
||||
saved.value = false;
|
||||
try {
|
||||
const roleMap: Record<string, string> = {};
|
||||
for (const row of roleMapRows.value) {
|
||||
const group = row.group.trim();
|
||||
if (group && row.role) roleMap[group] = row.role;
|
||||
}
|
||||
const payload: Record<string, unknown> = {
|
||||
public_url: value.value.public_url,
|
||||
oidc_issuer: value.value.oidc_issuer,
|
||||
oidc_audience: value.value.oidc_audience,
|
||||
oidc_client_id: value.value.oidc_client_id,
|
||||
oidc_groups_claim: (value.value.oidc_groups_claim ?? "").trim(),
|
||||
oidc_role_map: roleMap,
|
||||
sso_only: value.value.sso_only,
|
||||
session_idle_timeout_s: Number(value.value.session_idle_timeout_s) || 0,
|
||||
session_max_lifetime_s: Number(value.value.session_max_lifetime_s) || 0,
|
||||
trusted_proxies: value.value.trusted_proxies,
|
||||
};
|
||||
if (clientSecret.value) {
|
||||
payload.oidc_client_secret = clientSecret.value;
|
||||
}
|
||||
await api.saveAuthentication(payload);
|
||||
clientSecret.value = "";
|
||||
await load();
|
||||
saved.value = true;
|
||||
} catch (cause) {
|
||||
error.value = describeError(cause, errors.common.unknown);
|
||||
sessionExpired.value = classifyActionError(cause).kind === "session-expired";
|
||||
} finally {
|
||||
busy.value = false;
|
||||
}
|
||||
}
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<div><PageHeader title="Authentication"/>
|
||||
<ReadError v-if="error" :message="error" retry-label="Retry" class="mb-4" @retry="load"><a v-if="sessionExpired" class="underline" href="/?reauth=1"> Sign in again</a></ReadError>
|
||||
<div v-else-if="!loaded" role="status" aria-label="Loading settings" class="space-y-2 py-2"><Skeleton class="h-8 w-full" /><Skeleton class="h-8 w-full" /><Skeleton class="h-24 w-full" /></div>
|
||||
<form v-if="loaded" @submit.prevent="save">
|
||||
<Section title="Instance URL">
|
||||
<SettingRow label="Public address" for="instance-url" hint="Passkeys require HTTPS and a domain name, or localhost. Once passkeys are enrolled, their domain is fixed."><Input id="instance-url" v-model="value.public_url" type="url" required /></SettingRow>
|
||||
</Section>
|
||||
<Section title="Reverse proxies">
|
||||
<SettingRow label="Trusted proxies" for="trusted-proxies" hint="One address or CIDR range per line. Webhook deliveries from these proxies are checked against the client address in X-Forwarded-For."><Textarea id="trusted-proxies" v-model="proxyText" rows="3" class="max-w-xl font-mono" placeholder="10.0.0.0/8" /></SettingRow>
|
||||
</Section>
|
||||
<Section title="OpenID Connect">
|
||||
<SettingRow label="Issuer URL" for="oidc-issuer"><Input id="oidc-issuer" v-model="value.oidc_issuer" type="url" placeholder="https://identity.example.com" /></SettingRow>
|
||||
<SettingRow label="Client ID" for="oidc-client"><Input id="oidc-client" v-model="value.oidc_client_id" /></SettingRow>
|
||||
<SettingRow label="Access token audience" for="oidc-audience"><Input id="oidc-audience" v-model="value.oidc_audience" /></SettingRow>
|
||||
<SettingRow label="Redirect URI" hint="Add permitted people in Organisation → Members.">
|
||||
<CodeView :code="redirectURI" />
|
||||
</SettingRow>
|
||||
<div class="flex items-center justify-end gap-2 border-t border-border pt-3"><Check v-if="saved" role="status" aria-label="Saved" class="size-4 text-fg-muted" /><Button type="submit" :disabled="busy">Save</Button></div>
|
||||
</Section>
|
||||
</form>
|
||||
</div>
|
||||
<div>
|
||||
<PageHeader title="Authentication" />
|
||||
<ReadError v-if="error" :message="error" retry-label="Retry" class="mb-4" @retry="load">
|
||||
<a v-if="sessionExpired" class="underline" href="/?reauth=1"> Sign in again</a>
|
||||
</ReadError>
|
||||
<div v-else-if="!loaded" role="status" aria-label="Loading settings" class="space-y-2 py-2">
|
||||
<Skeleton class="h-8 w-full" />
|
||||
<Skeleton class="h-8 w-full" />
|
||||
<Skeleton class="h-24 w-full" />
|
||||
</div>
|
||||
<form v-if="loaded" @submit.prevent="save">
|
||||
<Section title="Instance URL">
|
||||
<SettingRow
|
||||
label="Public address"
|
||||
for="instance-url"
|
||||
hint="Passkeys require HTTPS and a domain name, or localhost. Once passkeys are enrolled, their domain is fixed."
|
||||
>
|
||||
<Input id="instance-url" v-model="value.public_url" type="url" required />
|
||||
</SettingRow>
|
||||
</Section>
|
||||
|
||||
<Section title="Reverse proxies">
|
||||
<SettingRow
|
||||
label="Trusted proxies"
|
||||
for="trusted-proxies"
|
||||
hint="One address or CIDR range per line. Webhook deliveries from these proxies are checked against the client address in X-Forwarded-For."
|
||||
>
|
||||
<Textarea id="trusted-proxies" v-model="proxyText" rows="3" class="max-w-xl font-mono" placeholder="10.0.0.0/8" />
|
||||
</SettingRow>
|
||||
</Section>
|
||||
|
||||
<Section title="OpenID Connect">
|
||||
<SettingRow label="Issuer URL" for="oidc-issuer">
|
||||
<Input id="oidc-issuer" v-model="value.oidc_issuer" type="url" placeholder="https://identity.example.com" />
|
||||
</SettingRow>
|
||||
<SettingRow label="Client ID" for="oidc-client">
|
||||
<Input id="oidc-client" v-model="value.oidc_client_id" />
|
||||
</SettingRow>
|
||||
<SettingRow
|
||||
label="Client secret"
|
||||
for="oidc-client-secret"
|
||||
hint="Confidential clients only. Stored encrypted; leave blank to keep an existing secret."
|
||||
>
|
||||
<div class="flex flex-wrap items-center gap-2">
|
||||
<Input
|
||||
id="oidc-client-secret"
|
||||
v-model="clientSecret"
|
||||
type="password"
|
||||
autocomplete="new-password"
|
||||
class="min-w-0 flex-1"
|
||||
:placeholder="value.oidc_client_secret_set ? 'Leave blank to keep existing secret' : 'Enter client secret'"
|
||||
/>
|
||||
<Badge v-if="value.oidc_client_secret_set" variant="secondary">Configured</Badge>
|
||||
</div>
|
||||
</SettingRow>
|
||||
<SettingRow label="Access token audience" for="oidc-audience">
|
||||
<Input id="oidc-audience" v-model="value.oidc_audience" />
|
||||
</SettingRow>
|
||||
<SettingRow label="Groups claim" for="oidc-groups-claim" hint="ID token claim containing group names (defaults to groups).">
|
||||
<Input id="oidc-groups-claim" v-model="value.oidc_groups_claim" placeholder="groups" />
|
||||
</SettingRow>
|
||||
<SettingRow label="Group role mappings" hint="Map identity provider groups to an organisation role on sign-in.">
|
||||
<div class="space-y-2">
|
||||
<div v-for="(row, index) in roleMapRows" :key="index" class="flex flex-wrap items-center gap-2">
|
||||
<Input
|
||||
v-model="row.group"
|
||||
:aria-label="`Group ${index + 1}`"
|
||||
placeholder="idp-group-name"
|
||||
class="min-w-40 flex-1 font-mono"
|
||||
/>
|
||||
<Select v-model="row.role">
|
||||
<SelectTrigger class="w-36" :aria-label="`Role for group ${index + 1}`">
|
||||
<SelectValue />
|
||||
</SelectTrigger>
|
||||
<SelectContent>
|
||||
<SelectItem v-for="role in ROLES" :key="role" :value="role">{{ role }}</SelectItem>
|
||||
</SelectContent>
|
||||
</Select>
|
||||
<Button
|
||||
type="button"
|
||||
variant="ghost"
|
||||
size="icon"
|
||||
:aria-label="`Remove mapping ${index + 1}`"
|
||||
@click="removeRoleMapping(index)"
|
||||
>
|
||||
<Trash2 class="size-4" />
|
||||
</Button>
|
||||
</div>
|
||||
<Button type="button" variant="outline" size="sm" @click="addRoleMapping">
|
||||
<Plus class="size-4" />
|
||||
Add mapping
|
||||
</Button>
|
||||
</div>
|
||||
</SettingRow>
|
||||
<SettingRow label="Redirect URI" hint="Add permitted people in Organisation → Members.">
|
||||
<CodeView :code="redirectURI" />
|
||||
</SettingRow>
|
||||
<SettingRow label="Back-channel logout URI">
|
||||
<CodeView :code="backchannelLogoutURI" />
|
||||
</SettingRow>
|
||||
</Section>
|
||||
|
||||
<Section title="Sessions">
|
||||
<SettingRow
|
||||
label="Require single sign-on"
|
||||
for="sso-only"
|
||||
hint="Disable password and passkey sign-in when an identity provider is configured."
|
||||
>
|
||||
<Switch
|
||||
id="sso-only"
|
||||
:model-value="value.sso_only"
|
||||
@update:model-value="(on) => (value.sso_only = on)"
|
||||
/>
|
||||
</SettingRow>
|
||||
<SettingRow
|
||||
label="Idle timeout (seconds)"
|
||||
for="session-idle-timeout"
|
||||
hint="Seconds of inactivity before a session expires (0 uses the default)."
|
||||
>
|
||||
<Input
|
||||
id="session-idle-timeout"
|
||||
v-model.number="value.session_idle_timeout_s"
|
||||
type="number"
|
||||
min="0"
|
||||
step="1"
|
||||
class="max-w-xs"
|
||||
/>
|
||||
</SettingRow>
|
||||
<SettingRow
|
||||
label="Maximum lifetime (seconds)"
|
||||
for="session-max-lifetime"
|
||||
hint="Maximum session duration in seconds before re-authentication is required (0 uses the default)."
|
||||
>
|
||||
<Input
|
||||
id="session-max-lifetime"
|
||||
v-model.number="value.session_max_lifetime_s"
|
||||
type="number"
|
||||
min="0"
|
||||
step="1"
|
||||
class="max-w-xs"
|
||||
/>
|
||||
</SettingRow>
|
||||
<div class="flex items-center justify-end gap-2 border-t border-border pt-3">
|
||||
<Check v-if="saved" role="status" aria-label="Saved" class="size-4 text-fg-muted" />
|
||||
<Button type="submit" :disabled="busy">Save</Button>
|
||||
</div>
|
||||
</Section>
|
||||
</form>
|
||||
</div>
|
||||
</template>
|
||||
@@ -0,0 +1,313 @@
|
||||
<script setup lang="ts">
|
||||
definePage({
|
||||
name: "settings-bundles",
|
||||
meta: {
|
||||
navPath: "/settings",
|
||||
settings: true,
|
||||
label: "Promotion bundles",
|
||||
description: "Export, diff and apply immutable environment bundles.",
|
||||
section: "settings",
|
||||
},
|
||||
});
|
||||
|
||||
import { Download, Upload } from "@lucide/vue";
|
||||
import { computed, onMounted, ref } from "vue";
|
||||
|
||||
import CodeView from "@/base/CodeView.vue";
|
||||
import PageHeader from "@/base/PageHeader.vue";
|
||||
import { Badge } from "@/components/ui/badge";
|
||||
import { Button } from "@/components/ui/button";
|
||||
import {
|
||||
Dialog,
|
||||
DialogContent,
|
||||
DialogDescription,
|
||||
DialogFooter,
|
||||
DialogHeader,
|
||||
DialogTitle,
|
||||
} from "@/components/ui/dialog";
|
||||
import { Input } from "@/components/ui/input";
|
||||
import { MetadataList } from "@/components/ui/metadata-list";
|
||||
import { ReadError } from "@/components/ui/read-error";
|
||||
import { Section } from "@/components/ui/section";
|
||||
import { SettingRow } from "@/components/ui/setting-row";
|
||||
import { Skeleton } from "@/components/ui/skeleton";
|
||||
import { Textarea } from "@/components/ui/textarea";
|
||||
import { Timestamp } from "@/components/ui/timestamp";
|
||||
import { errors } from "@/copy/errors";
|
||||
import {
|
||||
api,
|
||||
describeError,
|
||||
type BundleApplyReply,
|
||||
type BundleDiffReply,
|
||||
type BundleExportReply,
|
||||
} from "@/lib/api";
|
||||
|
||||
const exported = ref<BundleExportReply | null>(null);
|
||||
const exportBusy = ref(false);
|
||||
const exportError = ref("");
|
||||
|
||||
const bundleYaml = ref("");
|
||||
const bindingsYaml = ref("");
|
||||
const expectDigest = ref("");
|
||||
const fileInput = ref<HTMLInputElement | null>(null);
|
||||
|
||||
const actionBusy = ref(false);
|
||||
const actionError = ref("");
|
||||
const diffResult = ref<BundleDiffReply | null>(null);
|
||||
const applyResult = ref<BundleApplyReply | null>(null);
|
||||
const confirmOpen = ref(false);
|
||||
|
||||
let exportAttempt = 0;
|
||||
let actionAttempt = 0;
|
||||
|
||||
async function loadExport(): Promise<void> {
|
||||
const seq = ++exportAttempt;
|
||||
exportBusy.value = true;
|
||||
exportError.value = "";
|
||||
try {
|
||||
const reply = await api.exportBundle();
|
||||
if (seq !== exportAttempt) return;
|
||||
exported.value = reply;
|
||||
} catch (cause) {
|
||||
if (seq !== exportAttempt) return;
|
||||
exportError.value = describeError(cause, errors.common.unknown);
|
||||
} finally {
|
||||
if (seq === exportAttempt) exportBusy.value = false;
|
||||
}
|
||||
}
|
||||
|
||||
onMounted(() => {
|
||||
void loadExport();
|
||||
});
|
||||
|
||||
const exportRows = computed(() => {
|
||||
if (!exported.value) return [];
|
||||
return [
|
||||
{ label: "Schema version", value: exported.value.schema_version, mono: true },
|
||||
{ label: "Digest", value: exported.value.digest, mono: true },
|
||||
{ label: "Exported", value: exported.value.exported_at },
|
||||
];
|
||||
});
|
||||
|
||||
function downloadExport(): void {
|
||||
if (!exported.value) return;
|
||||
const blob = new Blob([exported.value.bundle_yaml], { type: "application/yaml;charset=utf-8" });
|
||||
const url = URL.createObjectURL(blob);
|
||||
const link = document.createElement("a");
|
||||
link.href = url;
|
||||
link.download = `archie-bundle-${exported.value.digest.slice(0, 12)}.yaml`;
|
||||
link.click();
|
||||
URL.revokeObjectURL(url);
|
||||
}
|
||||
|
||||
async function onFileChange(event: Event): Promise<void> {
|
||||
const input = event.target as HTMLInputElement;
|
||||
const file = input.files?.[0];
|
||||
if (!file) return;
|
||||
bundleYaml.value = await file.text();
|
||||
diffResult.value = null;
|
||||
applyResult.value = null;
|
||||
actionError.value = "";
|
||||
input.value = "";
|
||||
}
|
||||
|
||||
async function runDiff(): Promise<void> {
|
||||
const seq = ++actionAttempt;
|
||||
actionBusy.value = true;
|
||||
actionError.value = "";
|
||||
diffResult.value = null;
|
||||
applyResult.value = null;
|
||||
try {
|
||||
const reply = await api.diffBundle({ bundle_yaml: bundleYaml.value });
|
||||
if (seq !== actionAttempt) return;
|
||||
diffResult.value = reply;
|
||||
} catch (cause) {
|
||||
if (seq !== actionAttempt) return;
|
||||
actionError.value = describeError(cause, errors.common.unknown);
|
||||
} finally {
|
||||
if (seq === actionAttempt) actionBusy.value = false;
|
||||
}
|
||||
}
|
||||
|
||||
async function runApply(dryRun: boolean): Promise<void> {
|
||||
const seq = ++actionAttempt;
|
||||
actionBusy.value = true;
|
||||
actionError.value = "";
|
||||
diffResult.value = null;
|
||||
applyResult.value = null;
|
||||
try {
|
||||
const reply = await api.applyBundle({
|
||||
bundle_yaml: bundleYaml.value,
|
||||
bindings_yaml: bindingsYaml.value.trim() ? bindingsYaml.value : undefined,
|
||||
dry_run: dryRun,
|
||||
expect_digest: expectDigest.value.trim() || undefined,
|
||||
});
|
||||
if (seq !== actionAttempt) return;
|
||||
applyResult.value = reply;
|
||||
confirmOpen.value = false;
|
||||
if (reply.applied && !dryRun) {
|
||||
void loadExport();
|
||||
}
|
||||
} catch (cause) {
|
||||
if (seq !== actionAttempt) return;
|
||||
actionError.value = describeError(cause, errors.common.unknown);
|
||||
confirmOpen.value = false;
|
||||
} finally {
|
||||
if (seq === actionAttempt) actionBusy.value = false;
|
||||
}
|
||||
}
|
||||
|
||||
const activeResult = computed(() => applyResult.value ?? diffResult.value);
|
||||
|
||||
const resultStatusLabel = computed(() => {
|
||||
if (applyResult.value) {
|
||||
if (applyResult.value.dry_run) return applyResult.value.empty ? "Dry run (no changes)" : "Dry run";
|
||||
return applyResult.value.applied ? "Applied" : "No changes";
|
||||
}
|
||||
if (diffResult.value) {
|
||||
return diffResult.value.empty ? "No changes" : "Diff ready";
|
||||
}
|
||||
return "";
|
||||
});
|
||||
|
||||
const resultRows = computed(() => {
|
||||
if (!activeResult.value) return [];
|
||||
return [
|
||||
{ label: "Status", value: resultStatusLabel.value },
|
||||
{ label: "Digest", value: activeResult.value.digest, mono: true },
|
||||
];
|
||||
});
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<div>
|
||||
<PageHeader title="Promotion bundles" />
|
||||
|
||||
<Section title="Current bundle">
|
||||
<template #action>
|
||||
<div class="flex flex-wrap items-center gap-2">
|
||||
<Button type="button" variant="outline" size="sm" :disabled="exportBusy" @click="loadExport">
|
||||
{{ exportBusy ? "Exporting…" : "Refresh" }}
|
||||
</Button>
|
||||
<Button v-if="exported" type="button" variant="outline" size="sm" @click="downloadExport">
|
||||
<Download class="size-4" />
|
||||
Download YAML
|
||||
</Button>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<ReadError v-if="exportError" :message="exportError" retry-label="Retry" @retry="loadExport" />
|
||||
<div v-else-if="exportBusy && !exported" role="status" aria-label="Exporting bundle" class="space-y-2 py-2">
|
||||
<Skeleton class="h-6 w-1/2" />
|
||||
<Skeleton class="h-40 w-full" />
|
||||
</div>
|
||||
<template v-else-if="exported">
|
||||
<MetadataList :rows="exportRows">
|
||||
<template #value="{ row }">
|
||||
<Timestamp v-if="row.label === 'Exported'" :at="exported.exported_at" />
|
||||
<span v-else>{{ row.value }}</span>
|
||||
</template>
|
||||
</MetadataList>
|
||||
<CodeView :code="exported.bundle_yaml" lang="yaml" class="mt-4" />
|
||||
</template>
|
||||
</Section>
|
||||
|
||||
<Section title="Promote bundle">
|
||||
<SettingRow
|
||||
label="Bundle YAML"
|
||||
for="bundle-yaml"
|
||||
hint="Paste an exported bundle YAML or load a bundle file."
|
||||
>
|
||||
<div class="space-y-2">
|
||||
<div class="flex items-center gap-2">
|
||||
<input
|
||||
ref="fileInput"
|
||||
type="file"
|
||||
accept=".yaml,.yml,text/yaml,application/yaml"
|
||||
class="sr-only"
|
||||
@change="onFileChange"
|
||||
/>
|
||||
<Button type="button" variant="outline" size="sm" @click="fileInput?.click()">
|
||||
<Upload class="size-4" />
|
||||
Load file
|
||||
</Button>
|
||||
</div>
|
||||
<Textarea
|
||||
id="bundle-yaml"
|
||||
v-model="bundleYaml"
|
||||
rows="10"
|
||||
class="font-mono"
|
||||
placeholder="schema_version: v1"
|
||||
/>
|
||||
</div>
|
||||
</SettingRow>
|
||||
|
||||
<SettingRow
|
||||
label="Bindings YAML (optional)"
|
||||
for="bindings-yaml"
|
||||
hint="Stage constraints checked before applying workflows and action types."
|
||||
>
|
||||
<Textarea
|
||||
id="bindings-yaml"
|
||||
v-model="bindingsYaml"
|
||||
rows="5"
|
||||
class="font-mono"
|
||||
placeholder="stage: staging"
|
||||
/>
|
||||
</SettingRow>
|
||||
|
||||
<SettingRow
|
||||
label="Expected digest (optional)"
|
||||
for="expect-digest"
|
||||
hint="Rejects apply if the parsed bundle digest does not match."
|
||||
>
|
||||
<Input id="expect-digest" v-model="expectDigest" class="max-w-xl font-mono" placeholder="sha256 digest" />
|
||||
</SettingRow>
|
||||
|
||||
<div class="flex flex-wrap items-center justify-end gap-2 border-t border-border pt-3">
|
||||
<Button type="button" variant="outline" :disabled="actionBusy || !bundleYaml.trim()" @click="runDiff">
|
||||
Diff
|
||||
</Button>
|
||||
<Button type="button" variant="outline" :disabled="actionBusy || !bundleYaml.trim()" @click="runApply(true)">
|
||||
Dry run
|
||||
</Button>
|
||||
<Button type="button" :disabled="actionBusy || !bundleYaml.trim()" @click="confirmOpen = true">
|
||||
Apply bundle
|
||||
</Button>
|
||||
</div>
|
||||
|
||||
<p v-if="actionError" role="alert" class="mt-3 text-caption text-danger">{{ actionError }}</p>
|
||||
|
||||
<div v-if="activeResult" class="mt-4 space-y-3 border-t border-border pt-4">
|
||||
<div class="flex items-center gap-2">
|
||||
<Badge :variant="applyResult?.applied ? 'default' : 'secondary'">{{ resultStatusLabel }}</Badge>
|
||||
</div>
|
||||
<MetadataList :rows="resultRows" />
|
||||
<CodeView :code="activeResult.formatted || 'no changes\n'" lang="diff" />
|
||||
</div>
|
||||
</Section>
|
||||
|
||||
<Dialog v-model:open="confirmOpen">
|
||||
<DialogContent class="max-h-[85vh] overflow-y-auto sm:max-w-2xl">
|
||||
<DialogHeader>
|
||||
<DialogTitle>Apply promotion bundle?</DialogTitle>
|
||||
<DialogDescription>
|
||||
This updates workflows, non-shipped access policies, judgement rules and action type metadata in this environment.
|
||||
</DialogDescription>
|
||||
</DialogHeader>
|
||||
<MetadataList v-if="activeResult" :rows="[{ label: 'Target digest', value: activeResult.digest, mono: true }]" />
|
||||
<CodeView
|
||||
v-if="activeResult"
|
||||
:code="activeResult.formatted || 'no changes\n'"
|
||||
lang="diff"
|
||||
/>
|
||||
<DialogFooter>
|
||||
<Button type="button" variant="outline" :disabled="actionBusy" @click="confirmOpen = false">Cancel</Button>
|
||||
<Button type="button" :disabled="actionBusy" @click="runApply(false)">
|
||||
{{ actionBusy ? "Applying…" : "Confirm apply" }}
|
||||
</Button>
|
||||
</DialogFooter>
|
||||
</DialogContent>
|
||||
</Dialog>
|
||||
</div>
|
||||
</template>
|
||||
@@ -7,8 +7,9 @@ import { Button } from "@/components/ui/button";
|
||||
import { ReadError } from "@/components/ui/read-error";
|
||||
import { Section } from "@/components/ui/section";
|
||||
import { Timestamp } from "@/components/ui/timestamp";
|
||||
import { useAccountsStore } from "@/accounts/accounts";
|
||||
import { errors } from "@/copy/errors";
|
||||
import { api, describeError } from "@/lib/api";
|
||||
import { api, describeError, type Approval } from "@/lib/api";
|
||||
import { useRead } from "@/lib/use-read";
|
||||
import { answerApproval } from "@/runs/answer";
|
||||
import { coversSequence } from "@/runs/sequence";
|
||||
@@ -20,10 +21,19 @@ import { useLiveResource } from "@/stores/session";
|
||||
const props = defineProps<{ run?: string }>();
|
||||
const emit = defineEmits<{ answered: [] }>();
|
||||
|
||||
const accounts = useAccountsStore();
|
||||
const { data, error, reload } = useRead(() => api.approvals());
|
||||
onMounted(reload);
|
||||
onMounted(() => {
|
||||
reload();
|
||||
if (!accounts.status) void accounts.load();
|
||||
});
|
||||
useLiveResource("work", () => void reload());
|
||||
|
||||
function isSelfApprovalBlocked(approval: Approval): boolean {
|
||||
const userId = accounts.status?.user?.id;
|
||||
return Boolean(approval.require_sod && userId && approval.initiator_id === userId);
|
||||
}
|
||||
|
||||
const waiting = computed(() =>
|
||||
(data.value ?? []).filter((a) => a.state === "pending" && (!props.run || a.run_id === props.run)),
|
||||
);
|
||||
@@ -68,9 +78,17 @@ async function answer(id: string, approved: boolean): Promise<void> {
|
||||
<template v-if="approval.deadline"><span v-if="!coversSequence(approval) || !run"> · </span>due <Timestamp :at="approval.deadline" /></template>
|
||||
</p>
|
||||
</div>
|
||||
<Badge v-if="approval.require_sod" variant="secondary">Four-eyes</Badge>
|
||||
<Badge variant="outline">{{ stateLabel(approval.level) }}</Badge>
|
||||
<Button size="sm" variant="outline" :disabled="busy === approval.id" @click="answer(approval.id, false)">Deny</Button>
|
||||
<Button size="sm" :disabled="busy === approval.id" @click="answer(approval.id, true)">Approve</Button>
|
||||
<Button
|
||||
size="sm"
|
||||
:disabled="busy === approval.id || isSelfApprovalBlocked(approval)"
|
||||
:title="isSelfApprovalBlocked(approval) ? 'Initiator cannot self-approve when four-eyes approval is required' : undefined"
|
||||
@click="answer(approval.id, true)"
|
||||
>
|
||||
Approve
|
||||
</Button>
|
||||
</li>
|
||||
</ul>
|
||||
</Section>
|
||||
|
||||
@@ -0,0 +1,82 @@
|
||||
import { defineStore } from "pinia";
|
||||
import { ref } from "vue";
|
||||
import { errors } from "@/copy/errors";
|
||||
import { ApiError, api, describeError, type AuditEvent, type QueryParams } from "@/lib/api";
|
||||
|
||||
export interface AuditFilters {
|
||||
category: string;
|
||||
action: string;
|
||||
actor: string;
|
||||
since: string;
|
||||
until: string;
|
||||
}
|
||||
|
||||
const EMPTY_FILTERS: AuditFilters = {
|
||||
category: "",
|
||||
action: "",
|
||||
actor: "",
|
||||
since: "",
|
||||
until: "",
|
||||
};
|
||||
|
||||
function toRFC3339(value: string): string {
|
||||
const trimmed = value.trim();
|
||||
if (!trimmed) return "";
|
||||
const parsed = new Date(trimmed);
|
||||
return Number.isNaN(parsed.getTime()) ? trimmed : parsed.toISOString();
|
||||
}
|
||||
|
||||
export const useAuditStore = defineStore("audit", () => {
|
||||
const events = ref<AuditEvent[]>([]);
|
||||
const more = ref(false);
|
||||
const loading = ref(false);
|
||||
const error = ref("");
|
||||
const filters = ref<AuditFilters>({ ...EMPTY_FILTERS });
|
||||
|
||||
let attempt = 0;
|
||||
|
||||
function queryParams(extra: QueryParams = {}): QueryParams {
|
||||
return {
|
||||
category: filters.value.category.trim(),
|
||||
action: filters.value.action.trim(),
|
||||
actor: filters.value.actor.trim(),
|
||||
since: toRFC3339(filters.value.since),
|
||||
until: toRFC3339(filters.value.until),
|
||||
...extra,
|
||||
};
|
||||
}
|
||||
|
||||
async function load(reset = true): Promise<void> {
|
||||
const seq = ++attempt;
|
||||
loading.value = true;
|
||||
error.value = "";
|
||||
try {
|
||||
const offset = reset ? 0 : events.value.length;
|
||||
const reply = await api.auditEvents(queryParams({ limit: 100, offset }));
|
||||
if (seq !== attempt) return;
|
||||
const rows = reply.events ?? [];
|
||||
events.value = reset ? rows : [...events.value, ...rows];
|
||||
more.value = Boolean(reply.more);
|
||||
} catch (cause) {
|
||||
if (seq !== attempt) return;
|
||||
if (cause instanceof ApiError && cause.status === 503) {
|
||||
error.value = "Audit store unavailable";
|
||||
return;
|
||||
}
|
||||
error.value = describeError(cause, errors.common.unknown);
|
||||
} finally {
|
||||
if (seq === attempt) loading.value = false;
|
||||
}
|
||||
}
|
||||
|
||||
function resetFilters(): void {
|
||||
filters.value = { ...EMPTY_FILTERS };
|
||||
void load(true);
|
||||
}
|
||||
|
||||
function exportUrl(format: "jsonl" | "csv"): string {
|
||||
return api.auditExportUrl(queryParams({ limit: 1000, format }));
|
||||
}
|
||||
|
||||
return { events, more, loading, error, filters, load, resetFilters, exportUrl };
|
||||
});
|
||||
Vendored
+32
@@ -164,6 +164,7 @@ declare module 'vue-router/auto-routes' {
|
||||
Record<never, never>,
|
||||
Record<never, never>,
|
||||
| 'org-approvals'
|
||||
| 'org-audit'
|
||||
| 'org-decisions'
|
||||
| 'org-instructions'
|
||||
| 'org-members'
|
||||
@@ -185,6 +186,13 @@ declare module 'vue-router/auto-routes' {
|
||||
Record<never, never>,
|
||||
| never
|
||||
>,
|
||||
'org-audit': RouteRecordInfo<
|
||||
'org-audit',
|
||||
'/org/audit',
|
||||
Record<never, never>,
|
||||
Record<never, never>,
|
||||
| never
|
||||
>,
|
||||
'org-decisions': RouteRecordInfo<
|
||||
'org-decisions',
|
||||
'/org/decisions',
|
||||
@@ -255,6 +263,13 @@ declare module 'vue-router/auto-routes' {
|
||||
Record<never, never>,
|
||||
| never
|
||||
>,
|
||||
'settings-bundles': RouteRecordInfo<
|
||||
'settings-bundles',
|
||||
'/settings/bundles',
|
||||
Record<never, never>,
|
||||
Record<never, never>,
|
||||
| never
|
||||
>,
|
||||
'settings-credentials': RouteRecordInfo<
|
||||
'settings-credentials',
|
||||
'/settings/credentials',
|
||||
@@ -504,6 +519,7 @@ declare module 'vue-router/auto-routes' {
|
||||
routes:
|
||||
| '/org'
|
||||
| 'org-approvals'
|
||||
| 'org-audit'
|
||||
| 'org-decisions'
|
||||
| 'org-instructions'
|
||||
| 'org-members'
|
||||
@@ -531,6 +547,14 @@ declare module 'vue-router/auto-routes' {
|
||||
pathParamNames:
|
||||
| never
|
||||
}
|
||||
'src/pages/org/audit.vue': {
|
||||
routes:
|
||||
| 'org-audit'
|
||||
views:
|
||||
| never
|
||||
pathParamNames:
|
||||
| never
|
||||
}
|
||||
'src/pages/org/decisions.vue': {
|
||||
routes:
|
||||
| 'org-decisions'
|
||||
@@ -611,6 +635,14 @@ declare module 'vue-router/auto-routes' {
|
||||
pathParamNames:
|
||||
| never
|
||||
}
|
||||
'src/pages/settings/bundles.vue': {
|
||||
routes:
|
||||
| 'settings-bundles'
|
||||
views:
|
||||
| never
|
||||
pathParamNames:
|
||||
| never
|
||||
}
|
||||
'src/pages/settings/credentials.vue': {
|
||||
routes:
|
||||
| 'settings-credentials'
|
||||
|
||||
Reference in new issue
Block a user