From 6c3850b22ba9df06f7f9f4cf7c738fd190abf808 Mon Sep 17 00:00:00 2001 From: soyouzpanda Date: Tue, 29 Apr 2025 17:09:51 +0200 Subject: [PATCH] =?UTF-8?q?=E2=9C=A8(frontend)=20support=20`=5FFILE`=20env?= =?UTF-8?q?ironment=20variables=20for=20secrets?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Allow configuration variables that handles secrets to be read from a file given in an environment variable. --- CHANGELOG.md | 1 + src/frontend/servers/y-provider/src/env.ts | 13 +++++++++---- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index e8bf858c..ea821ad1 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -34,6 +34,7 @@ and this project adheres to - 🔧(git) set LF line endings for all text files #1032 - 📝(docs) minor fixes to docs/env.md - ✨(backend) support `_FILE` environment variables for secrets #912 +- ✨(frontend) support `_FILE` environment variables for secrets #912 ### Removed diff --git a/src/frontend/servers/y-provider/src/env.ts b/src/frontend/servers/y-provider/src/env.ts index fe281930..e0e02cf5 100644 --- a/src/frontend/servers/y-provider/src/env.ts +++ b/src/frontend/servers/y-provider/src/env.ts @@ -1,11 +1,16 @@ +import { readFileSync } from 'fs'; + export const COLLABORATION_LOGGING = process.env.COLLABORATION_LOGGING || 'false'; export const COLLABORATION_SERVER_ORIGIN = process.env.COLLABORATION_SERVER_ORIGIN || 'http://localhost:3000'; -export const COLLABORATION_SERVER_SECRET = - process.env.COLLABORATION_SERVER_SECRET || 'secret-api-key'; -export const Y_PROVIDER_API_KEY = - process.env.Y_PROVIDER_API_KEY || 'yprovider-api-key'; +export const COLLABORATION_SERVER_SECRET = process.env + .COLLABORATION_SERVER_SECRET_FILE + ? readFileSync(process.env.COLLABORATION_SERVER_SECRET_FILE, 'utf-8') + : process.env.COLLABORATION_SERVER_SECRET || 'secret-api-key'; +export const Y_PROVIDER_API_KEY = process.env.Y_PROVIDER_API_KEY_FILE + ? readFileSync(process.env.Y_PROVIDER_API_KEY_FILE, 'utf-8') + : process.env.Y_PROVIDER_API_KEY || 'yprovider-api-key'; export const PORT = Number(process.env.PORT || 4444); export const SENTRY_DSN = process.env.SENTRY_DSN || ''; export const COLLABORATION_BACKEND_BASE_URL =