From 646cd34715d9b75ec6c36ae18c51cf2e042e0781 Mon Sep 17 00:00:00 2001 From: Koenkk Date: Mon, 28 Oct 2019 18:05:50 +0100 Subject: [PATCH] Support secret for network_key. https://github.com/Koenkk/zigbee2mqtt/issues/2209 --- lib/util/settings.js | 8 ++++++++ test/settings.test.js | 5 +++++ 2 files changed, 13 insertions(+) diff --git a/lib/util/settings.js b/lib/util/settings.js index c70431881..1f64507b3 100644 --- a/lib/util/settings.js +++ b/lib/util/settings.js @@ -247,6 +247,10 @@ function write() { toWrite.mqtt.password = actual.mqtt.password; } + if (actual.advanced && actual.advanced.network_key) { + toWrite.advanced.network_key = actual.advanced.network_key; + } + if (typeof actual.devices === 'string') { yaml.writeIfChanged(data.joinPath(actual.devices), settings.devices); toWrite.devices = actual.devices; @@ -300,6 +304,10 @@ function read() { s.mqtt.password = interpetValue(s.mqtt.password); } + if (s.advanced && s.advanced.network_key) { + s.advanced.network_key = interpetValue(s.advanced.network_key); + } + // Read devices/groups configuration from separate file. if (typeof s.devices === 'string') { const file = data.joinPath(s.devices); diff --git a/test/settings.test.js b/test/settings.test.js index 3e4474e75..427477174 100644 --- a/test/settings.test.js +++ b/test/settings.test.js @@ -99,11 +99,15 @@ describe('Settings', () => { user: '!secret username', password: '!secret password', }, + advanced: { + network_key: '!secret network_key' + } }; const contentSecret = { username: 'mysecretusername', password: 'mysecretpassword', + network_key: [1,2,3], }; write(secretFile, contentSecret, false); @@ -117,6 +121,7 @@ describe('Settings', () => { }; expect(settings.get().mqtt).toStrictEqual(expected); + expect(settings.get().advanced.network_key).toStrictEqual([1,2,3]); settings._write(); expect(read(configurationFile)).toStrictEqual(contentConfiguration);