()
| 328 | } |
| 329 | |
| 330 | function read(): Partial<Settings> { |
| 331 | const s = yaml.read(CONFIG_FILE_PATH) as Partial<Settings>; |
| 332 | |
| 333 | // Read !secret MQTT username and password if set |
| 334 | const interpretValue = <T>(value: T): T => { |
| 335 | if (typeof value === "string") { |
| 336 | const ref = parseValueRef(value); |
| 337 | if (ref) { |
| 338 | return yaml.read(data.joinPath(ref.filename))[ref.key]; |
| 339 | } |
| 340 | } |
| 341 | return value; |
| 342 | }; |
| 343 | |
| 344 | if (s.mqtt?.user) { |
| 345 | s.mqtt.user = interpretValue(s.mqtt.user); |
| 346 | } |
| 347 | |
| 348 | if (s.mqtt?.password) { |
| 349 | s.mqtt.password = interpretValue(s.mqtt.password); |
| 350 | } |
| 351 | |
| 352 | if (s.mqtt?.server) { |
| 353 | s.mqtt.server = interpretValue(s.mqtt.server); |
| 354 | } |
| 355 | |
| 356 | if (s.advanced?.network_key) { |
| 357 | s.advanced.network_key = interpretValue(s.advanced.network_key); |
| 358 | } |
| 359 | |
| 360 | if (s.frontend?.auth_token) { |
| 361 | s.frontend.auth_token = interpretValue(s.frontend.auth_token); |
| 362 | } |
| 363 | |
| 364 | // Read devices/groups configuration from separate file if specified. |
| 365 | const readDevicesOrGroups = (type: "devices" | "groups"): void => { |
| 366 | if (typeof s[type] === "string" || (Array.isArray(s[type]) && Array(s[type]).length > 0)) { |
| 367 | const files: string[] = Array.isArray(s[type]) ? s[type] : [s[type]]; |
| 368 | s[type] = {}; |
| 369 | for (const file of files) { |
| 370 | const content = yaml.readIfExists(data.joinPath(file)); |
| 371 | // @ts-expect-error noMutate not typed properly |
| 372 | s[type] = objectAssignDeep.noMutate(s[type], content); |
| 373 | } |
| 374 | } |
| 375 | }; |
| 376 | |
| 377 | readDevicesOrGroups("devices"); |
| 378 | readDevicesOrGroups("groups"); |
| 379 | |
| 380 | return s; |
| 381 | } |
| 382 | |
| 383 | function applyEnvironmentVariables(settings: Partial<Settings>): void { |
| 384 | const iterate = (obj: KeyValue, path: string[]): void => { |
no test coverage detected