mirror of
https://github.com/snapotter-hq/SnapOtter.git
synced 2026-08-03 07:46:42 +02:00
style: apply Biome formatting to enterprise files
This commit is contained in:
@@ -16,11 +16,7 @@ export function computeHmac(data: Record<string, unknown>, key: Buffer): string
|
||||
return createHmac("sha256", key).update(canonicalize(data)).digest("hex");
|
||||
}
|
||||
|
||||
export function verifyHmac(
|
||||
data: Record<string, unknown>,
|
||||
hmac: string,
|
||||
key: Buffer,
|
||||
): boolean {
|
||||
export function verifyHmac(data: Record<string, unknown>, hmac: string, key: Buffer): boolean {
|
||||
const computed = computeHmac(data, key);
|
||||
return computed === hmac;
|
||||
}
|
||||
|
||||
@@ -100,10 +100,7 @@ export async function auditLog(
|
||||
requestId,
|
||||
};
|
||||
const integrity = computeHmac(rowData, hmacKey);
|
||||
await db
|
||||
.update(schema.auditLog)
|
||||
.set({ integrity })
|
||||
.where(eq(schema.auditLog.id, id));
|
||||
await db.update(schema.auditLog).set({ integrity }).where(eq(schema.auditLog.id, id));
|
||||
}
|
||||
} catch {
|
||||
logger.warn({ event }, "Failed to compute audit HMAC");
|
||||
|
||||
@@ -1,9 +1,4 @@
|
||||
import {
|
||||
createCipheriv,
|
||||
createDecipheriv,
|
||||
randomBytes,
|
||||
hkdf as hkdfCb,
|
||||
} from "node:crypto";
|
||||
import { createCipheriv, createDecipheriv, hkdf as hkdfCb, randomBytes } from "node:crypto";
|
||||
import { promisify } from "node:util";
|
||||
|
||||
const hkdf = promisify(hkdfCb);
|
||||
|
||||
@@ -50,7 +50,12 @@ export async function deliverWebhook(
|
||||
lastError = `HTTP ${response.status}`;
|
||||
// Don't retry 4xx errors (client errors = won't succeed on retry)
|
||||
if (response.status >= 400 && response.status < 500) {
|
||||
return { success: false, statusCode: response.status, error: lastError, attempts: attempt + 1 };
|
||||
return {
|
||||
success: false,
|
||||
statusCode: response.status,
|
||||
error: lastError,
|
||||
attempts: attempt + 1,
|
||||
};
|
||||
}
|
||||
} catch (err) {
|
||||
lastError = err instanceof Error ? err.message : String(err);
|
||||
|
||||
@@ -86,7 +86,11 @@ export async function apiKeyRoutes(app: FastifyInstance): Promise<void> {
|
||||
return reply.status(409).send({ error: "Failed to create API key" });
|
||||
}
|
||||
|
||||
await auditFromRequest(request)("API_KEY_CREATED", { userId: user.id, keyId: id, keyName: name });
|
||||
await auditFromRequest(request)("API_KEY_CREATED", {
|
||||
userId: user.id,
|
||||
keyId: id,
|
||||
keyName: name,
|
||||
});
|
||||
|
||||
// Return the raw key ONCE — it cannot be retrieved again
|
||||
return reply.status(201).send({
|
||||
|
||||
@@ -35,9 +35,9 @@ export async function registerSiemRoutes(app: FastifyInstance): Promise<void> {
|
||||
// Enterprise package not available
|
||||
}
|
||||
if (!featureEnabled) {
|
||||
return reply
|
||||
.status(403)
|
||||
.send({ error: "SIEM forwarding requires an enterprise license with the siem_forwarding feature" });
|
||||
return reply.status(403).send({
|
||||
error: "SIEM forwarding requires an enterprise license with the siem_forwarding feature",
|
||||
});
|
||||
}
|
||||
|
||||
const [row] = await db
|
||||
@@ -65,10 +65,7 @@ export async function registerSiemRoutes(app: FastifyInstance): Promise<void> {
|
||||
// PUT /api/v1/enterprise/siem/config
|
||||
app.put(
|
||||
"/api/v1/enterprise/siem/config",
|
||||
async (
|
||||
request: FastifyRequest<{ Body: unknown }>,
|
||||
reply: FastifyReply,
|
||||
) => {
|
||||
async (request: FastifyRequest<{ Body: unknown }>, reply: FastifyReply) => {
|
||||
const user = await requirePermission("webhooks:manage")(request, reply);
|
||||
if (!user) return;
|
||||
|
||||
@@ -81,14 +78,16 @@ export async function registerSiemRoutes(app: FastifyInstance): Promise<void> {
|
||||
// Enterprise package not available
|
||||
}
|
||||
if (!featureEnabled) {
|
||||
return reply
|
||||
.status(403)
|
||||
.send({ error: "SIEM forwarding requires an enterprise license with the siem_forwarding feature" });
|
||||
return reply.status(403).send({
|
||||
error: "SIEM forwarding requires an enterprise license with the siem_forwarding feature",
|
||||
});
|
||||
}
|
||||
|
||||
const parsed = configSchema.safeParse(request.body);
|
||||
if (!parsed.success) {
|
||||
return reply.status(400).send({ error: "Invalid SIEM config", details: parsed.error.issues });
|
||||
return reply
|
||||
.status(400)
|
||||
.send({ error: "Invalid SIEM config", details: parsed.error.issues });
|
||||
}
|
||||
|
||||
const config = { ...parsed.data };
|
||||
|
||||
@@ -9,10 +9,10 @@
|
||||
import { eq } from "drizzle-orm";
|
||||
import type { FastifyInstance, FastifyReply, FastifyRequest } from "fastify";
|
||||
import { z } from "zod";
|
||||
import { env } from "../config.js";
|
||||
import { db, schema } from "../db/index.js";
|
||||
import { auditFromRequest } from "../lib/audit.js";
|
||||
import { env } from "../config.js";
|
||||
import { encrypt, decrypt, isEncrypted } from "../lib/encryption.js";
|
||||
import { decrypt, encrypt, isEncrypted } from "../lib/encryption.js";
|
||||
import { requirePermission } from "../permissions.js";
|
||||
import { requireAuth } from "../plugins/auth.js";
|
||||
|
||||
@@ -37,8 +37,11 @@ async function decryptIfNeeded(value: string): Promise<string> {
|
||||
if (!isEncrypted(value)) return value;
|
||||
if (!env.DATA_ENCRYPTION_KEY) return value;
|
||||
return (
|
||||
(await decrypt(value, env.DATA_ENCRYPTION_KEY, env.DATA_ENCRYPTION_KEY_PREVIOUS || undefined)) ??
|
||||
value
|
||||
(await decrypt(
|
||||
value,
|
||||
env.DATA_ENCRYPTION_KEY,
|
||||
env.DATA_ENCRYPTION_KEY_PREVIOUS || undefined,
|
||||
)) ?? value
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user