A web check can read a value out of a JSON answer (power.now, state, data.result[0].value[1]) and judge it: below, above, equal to, contains, is there. The value read is shown on the Endpoints page, charted under History, exported as homelab_endpoint_value and in the read API. A check can also send one header (a token), stored encrypted, never returned, and not forwarded to another host on a redirect. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
25 lines
901 B
TypeScript
25 lines
901 B
TypeScript
/**
|
|
* A secret kept in the database: encrypted when an encryption key is set (as the notification channels' secrets are), plain otherwise. The webhooks' signing
|
|
* secrets and the header an endpoint check sends use it.
|
|
*/
|
|
import { decryptSecret, encryptSecret } from "../crypto.js";
|
|
import { env } from "../env.js";
|
|
|
|
const ENCRYPTED_PREFIX = "enc:v1:";
|
|
|
|
/** The stored form of a secret. */
|
|
export function sealSecret(plain: string): string {
|
|
return env.credentialsEncryptionEnabled ? ENCRYPTED_PREFIX + encryptSecret(plain) : plain;
|
|
}
|
|
|
|
/** What was stored, as it was given; null when there is none or it can no longer be decrypted. */
|
|
export function openSecret(stored: string | null): string | null {
|
|
if (!stored) return null;
|
|
if (!stored.startsWith(ENCRYPTED_PREFIX)) return stored;
|
|
try {
|
|
return decryptSecret(stored.slice(ENCRYPTED_PREFIX.length));
|
|
} catch {
|
|
return null;
|
|
}
|
|
}
|