mirror of
https://github.com/imputnet/cobalt.git
synced 2025-06-27 17:08:28 +00:00
api/env: log information about dynamic env changes
This commit is contained in:
parent
5ac87bab09
commit
e2b6879ea2
@ -12,12 +12,19 @@ export const canonicalEnv = Object.freeze(structuredClone(process.env));
|
|||||||
export const setTunnelPort = (port) => env.tunnelPort = port;
|
export const setTunnelPort = (port) => env.tunnelPort = port;
|
||||||
export const isCluster = env.instanceCount > 1;
|
export const isCluster = env.instanceCount > 1;
|
||||||
export const updateEnv = (newEnv) => {
|
export const updateEnv = (newEnv) => {
|
||||||
|
const changes = [];
|
||||||
|
|
||||||
// tunnelPort is special and needs to get carried over here
|
// tunnelPort is special and needs to get carried over here
|
||||||
newEnv.tunnelPort = env.tunnelPort;
|
newEnv.tunnelPort = env.tunnelPort;
|
||||||
|
|
||||||
for (const key in env) {
|
for (const key in env) {
|
||||||
|
if (String(env[key]) !== String(newEnv[key])) {
|
||||||
|
changes.push(key);
|
||||||
|
}
|
||||||
env[key] = newEnv[key];
|
env[key] = newEnv[key];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return changes;
|
||||||
}
|
}
|
||||||
|
|
||||||
await validateEnvs(env);
|
await validateEnvs(env);
|
||||||
|
@ -5,7 +5,7 @@ import { updateEnv, canonicalEnv, env as currentEnv } from "../config.js";
|
|||||||
import { FileWatcher } from "../misc/file-watcher.js";
|
import { FileWatcher } from "../misc/file-watcher.js";
|
||||||
import { isURL } from "../misc/utils.js";
|
import { isURL } from "../misc/utils.js";
|
||||||
import * as cluster from "../misc/cluster.js";
|
import * as cluster from "../misc/cluster.js";
|
||||||
import { Yellow } from "../misc/console-text.js";
|
import { Green, Yellow } from "../misc/console-text.js";
|
||||||
|
|
||||||
const forceLocalProcessingOptions = ["never", "session", "always"];
|
const forceLocalProcessingOptions = ["never", "session", "always"];
|
||||||
|
|
||||||
@ -109,6 +109,8 @@ export const validateEnvs = async (env) => {
|
|||||||
if (env.externalProxy && env.freebindCIDR) {
|
if (env.externalProxy && env.freebindCIDR) {
|
||||||
throw new Error('freebind is not available when external proxy is enabled')
|
throw new Error('freebind is not available when external proxy is enabled')
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return env;
|
||||||
}
|
}
|
||||||
|
|
||||||
const reloadEnvs = async (contents) => {
|
const reloadEnvs = async (contents) => {
|
||||||
@ -136,14 +138,34 @@ const reloadEnvs = async (contents) => {
|
|||||||
...newEnvs,
|
...newEnvs,
|
||||||
};
|
};
|
||||||
|
|
||||||
const parsed = loadEnvs(candidate);
|
const parsed = await validateEnvs(
|
||||||
await validateEnvs(parsed);
|
loadEnvs(candidate)
|
||||||
updateEnv(parsed);
|
);
|
||||||
|
|
||||||
cluster.broadcast({ env_update: resolvedContents });
|
cluster.broadcast({ env_update: resolvedContents });
|
||||||
|
return updateEnv(parsed);
|
||||||
}
|
}
|
||||||
|
|
||||||
const wrapReload = (contents) => {
|
const wrapReload = (contents) => {
|
||||||
reloadEnvs(contents)
|
reloadEnvs(contents)
|
||||||
|
.then(changes => {
|
||||||
|
if (changes.length === 0) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
console.log(`${Green('[✓]')} envs reloaded successfully!`);
|
||||||
|
for (const key of changes) {
|
||||||
|
const value = currentEnv[key];
|
||||||
|
const isSecret = key.toLowerCase().includes('apikey')
|
||||||
|
|| key.toLowerCase().includes('secret');
|
||||||
|
|
||||||
|
if (!value) {
|
||||||
|
console.log(` removed: ${key}`);
|
||||||
|
} else {
|
||||||
|
console.log(` changed: ${key} -> ${isSecret ? '***' : value}`);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
})
|
||||||
.catch((e) => {
|
.catch((e) => {
|
||||||
console.error(`${Yellow('[!]')} Failed reloading environment variables at ${new Date().toISOString()}.`);
|
console.error(`${Yellow('[!]')} Failed reloading environment variables at ${new Date().toISOString()}.`);
|
||||||
console.error('Error:', e);
|
console.error('Error:', e);
|
||||||
|
Loading…
Reference in New Issue
Block a user