Skip to content

Commit

Permalink
Do a better job with the for loop
Browse files Browse the repository at this point in the history
  • Loading branch information
perfectra1n committed Jan 23, 2025
1 parent f7df5d5 commit 8d3a285
Showing 1 changed file with 12 additions and 14 deletions.
26 changes: 12 additions & 14 deletions src/services/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,26 +20,24 @@ function getEnvironmentOverrides() {
const overrides: Record<string, Record<string, string>> = {};

for (const [key, value] of Object.entries(process.env)) {
// Check if key is not uppercase or doesn't start with TRILIUM_
if (!key.startsWith('TRILIUM_') || !value || key !== key.toUpperCase()) {
continue;
}
// Only process valid TRILIUM environment variables
const isValidEnvVar = key.startsWith('TRILIUM_') &&
value &&
key === key.toUpperCase();

// Remove TRILIUM_ prefix and split by underscore
const parts = key.slice(8).split('_');
// Skip if not a valid TRILIUM environment variable
if (!isValidEnvVar) continue;

if (parts.length < 2) {
continue;
}
// Parse the environment variable
const parts = key.slice(8).split('_');
if (parts.length < 2) continue;

// First part is the section, rest is the key
// Extract section and config key
const section = parts[0];
const configKey = parts.slice(1).join('_');

if (!overrides[section]) {
overrides[section] = {};
}

// Initialize section if needed and set value
overrides[section] = overrides[section] || {};
overrides[section][configKey] = value;
}

Expand Down

0 comments on commit 8d3a285

Please sign in to comment.