diff --git a/backend/lib/Configuration.js b/backend/lib/Configuration.js index c69c8383..7b49e66f 100644 --- a/backend/lib/Configuration.js +++ b/backend/lib/Configuration.js @@ -6,6 +6,7 @@ const os = require("os"); const path = require("path"); const DEFAULT_SETTINGS = require("./res/default_config.json"); +const env = require("./res/env"); const Logger = require("./Logger"); const SCHEMAS = require("./doc/Configuration.openapi.json"); const Tools = require("./utils/Tools"); @@ -17,7 +18,7 @@ class Configuration { this.eventEmitter = new EventEmitter(); this.settings = structuredClone(DEFAULT_SETTINGS); - this.location = process.env.VALETUDO_CONFIG_PATH ?? path.join(os.tmpdir(), "valetudo_config.json"); + this.location = process.env[env.ConfigPath] ?? path.join(os.tmpdir(), "valetudo_config.json"); this.loadConfig(); } diff --git a/backend/lib/Valetudo.js b/backend/lib/Valetudo.js index 1668a03d..088f8587 100644 --- a/backend/lib/Valetudo.js +++ b/backend/lib/Valetudo.js @@ -1,4 +1,5 @@ const Configuration = require("./Configuration"); +const env = require("./res/env"); const fs = require("fs"); const Logger = require("./Logger"); const MqttController = require("./mqtt/MqttController"); @@ -24,7 +25,7 @@ class Valetudo { try { Logger.setLogLevel(this.config.get("logLevel")); - Logger.setLogFilePath(process.env.VALETUDO_LOG_PATH ?? path.join(os.tmpdir(), "valetudo.log")); + Logger.setLogFilePath(process.env[env.LogPath] ?? path.join(os.tmpdir(), "valetudo.log")); } catch (e) { Logger.error("Initialising Logger: " + e); } diff --git a/backend/lib/res/env.js b/backend/lib/res/env.js new file mode 100644 index 00000000..e0814310 --- /dev/null +++ b/backend/lib/res/env.js @@ -0,0 +1,5 @@ +module.exports = { + ConfigPath: "VALETUDO_LOG_PATH", + LogPath: "VALETUDO_LOG_PATH", + HumanReadableSystemId: "VALETUDO_HUMAN_READABLE_SYSTEM_ID", +}; diff --git a/backend/lib/utils/Tools.js b/backend/lib/utils/Tools.js index f2acf138..0de66ca0 100644 --- a/backend/lib/utils/Tools.js +++ b/backend/lib/utils/Tools.js @@ -4,6 +4,7 @@ const path = require("path"); const uuid = require("uuid"); const zooIDs = require("zoo-ids"); +const env = require("../res/env"); const LinuxTools = require("./LinuxTools"); let SYSTEM_ID; @@ -133,7 +134,21 @@ class Tools { } static GET_HUMAN_READABLE_SYSTEM_ID() { - return zooIDs.generateId(Tools.GET_SYSTEM_ID()); + /* + This is not part of the config file because: + A) You can break functionality if you configure this incorrectly (invalid string, duplicates, etc.) leading to support issues + and + B) Because this is a static method and passing the config here would require annoying refactoring + + Having it as an undocumented ENV variable should be accessible enough for those who don't require support + hand-holding if they configure it incorrectly but also inaccessible enough for those who do. + And, thirdly, it can still vanish at any time if necessary. You're welcome. + */ + if (process.env[env.HumanReadableSystemId]?.length > 0) { + return process.env[env.HumanReadableSystemId]; + } else { + return zooIDs.generateId(Tools.GET_SYSTEM_ID()); + } } static GET_ZEROCONF_HOSTNAME() {