feat: add file-based env variables for LibreTranslate and Stalwart

Impersonation
This commit is contained in:
Pascal Dietrich
2026-09-24 18:36:49 +02:00
parent e33ab899b0
commit fe813d3599
2 changed files with 23 additions and 5 deletions
+5 -2
View File
@@ -1,4 +1,5 @@
import { NextRequest, NextResponse } from 'next/server';
import { readFileEnv } from "@/lib/read-file-env";
import { getStalwartCredentials } from '@/lib/stalwart/credentials';
// Host-side proxy backing the "Translate" plugin (manifest apiPostPaths:
@@ -11,7 +12,7 @@ import { getStalwartCredentials } from '@/lib/stalwart/credentials';
// langpair needs an explicit source language, so when the
// plugin asks for "auto" we detect it locally first.
// - "libretranslate" — only available when the host sets LIBRETRANSLATE_URL
// (and optionally LIBRETRANSLATE_API_KEY). Supports native
// (and optionally LIBRETRANSLATE_API_KEY or LIBRETRANSLATE_API_KEY_FILE). Supports native
// source auto-detection.
export const runtime = 'nodejs';
@@ -225,7 +226,9 @@ async function translateLibre(
if (!endpoint) {
throw new Error('LibreTranslate is not configured on this server');
}
const apiKey = process.env.LIBRETRANSLATE_API_KEY;
const apiKey =
process.env.LIBRETRANSLATE_API_KEY ||
readFileEnv(process.env.LIBRETRANSLATE_API_KEY_FILE);
const url = endpoint.replace(/\/+$/, '') + '/translate';
const res = await fetch(url, {
method: 'POST',
+18 -3
View File
@@ -1,4 +1,5 @@
import { configManager } from '@/lib/admin/config-manager';
import { readFileEnv } from "@/lib/read-file-env";
export interface ImpersonationConfig {
jwtSecret: string;
@@ -16,13 +17,27 @@ export interface ImpersonationConfig {
* BULWARK_STALWART_MASTER_USER master account address (e.g. master@example.com)
* BULWARK_STALWART_MASTER_PASSWORD
*
* Alternatively the file-based env:
* BULWARK_JWT_AUTH_SECRET_FILE
* BULWARK_STALWART_MASTER_USER_FILE
* BULWARK_STALWART_MASTER_PASSWORD_FILE
*
* Optional env:
* BULWARK_JWT_AUTH_ISSUER (default: "platform-api/webmail")
*/
export function readImpersonationConfig(): ImpersonationConfig | null {
const jwtSecret = process.env.BULWARK_JWT_AUTH_SECRET ?? '';
const masterUser = process.env.BULWARK_STALWART_MASTER_USER ?? '';
const masterPassword = process.env.BULWARK_STALWART_MASTER_PASSWORD ?? '';
const jwtSecret =
process.env.BULWARK_JWT_AUTH_SECRET ??
readFileEnv(process.env.BULWARK_JWT_AUTH_SECRET_FILE) ??
"";
const masterUser =
process.env.BULWARK_STALWART_MASTER_USER ??
readFileEnv(process.env.BULWARK_STALWART_MASTER_USER_FILE) ??
"";
const masterPassword =
process.env.BULWARK_STALWART_MASTER_PASSWORD ??
readFileEnv(process.env.BULWARK_STALWART_MASTER_PASSWORD_FILE) ??
"";
if (!jwtSecret || !masterUser || !masterPassword) return null;
return {
jwtSecret,