Add support for selective config sync on v6 PiHoles#567
Add support for selective config sync on v6 PiHoles#567dreary-ennui wants to merge 7 commits intomattwebbio:masterfrom
Conversation
| const clientVersion = client.getVersion(); | ||
| if (clientVersion === 6 && success && enableSelectiveSync) { | ||
| const clientExistingConfig = JSON.parse( | ||
| await client.getExistingConfig() | ||
| ); | ||
|
|
||
| if ( | ||
| clientExistingConfig.config.webserver.api.app_pwhash === '' || | ||
| (clientExistingConfig.config.webserver.api.app_pwhash !== '' && | ||
| clientExistingConfig.config.webserver.api.app_sudo) | ||
| ) { | ||
| let patchedConfigDNSRecords = {}; | ||
| let patchedConfigCNAMERecords = {}; | ||
|
|
||
| if (config.sync.v6.selective_LocalDnsRecords) { | ||
| patchedConfigDNSRecords = { | ||
| config: { | ||
| dns: { | ||
| hosts: configDataBackup.config.dns.hosts | ||
| } | ||
| } | ||
| }; | ||
| } | ||
| if (config.sync.v6.selective_LocalCnameRecords) { | ||
| patchedConfigCNAMERecords = { | ||
| config: { | ||
| dns: { | ||
| cnameRecords: configDataBackup.config.dns.cnameRecords | ||
| } | ||
| } | ||
| }; | ||
| } | ||
|
|
||
| const patchedConfig = deepMerge( | ||
| {}, | ||
| patchedConfigDNSRecords, | ||
| patchedConfigCNAMERecords | ||
| ); | ||
| if (patchedConfig) { | ||
| success = await client.uploadPatchedConfig(patchedConfig); | ||
| } | ||
| } else { | ||
| log.info( | ||
| chalk.red( | ||
| `⚠ Error: Secondary host ${host.baseUrl} has an app password configured but webserver.api.app_sudo is set to false in pihole.toml. Skipping selective config sync for this host. Set webserver.api.app_sudo to true to resolve, in either the pihole.toml file or from the pihole web interface by going to Settings -> All settings -> Webserver and API. You may need to click the Blue "Modified settings" slider if you do not see webserver.api.app_sudo in the UI.` | ||
| ) | ||
| ); | ||
| } | ||
| } | ||
|
|
There was a problem hiding this comment.
I will probably try to figure out a way to move this into downloadBackup and uploadBackup - I'd like to keep as much logic out of sync.ts as possible
There was a problem hiding this comment.
Feel free! I was thinking of maybe doing the same; I figured since it was supplemental to the teleport functions and not exactly related to whether or not those succeed / fail that I'd make separate functions. I definitely agree that keeping sync.ts tidy is a good goal though
|
Thanks so much for the submission, @dreary-ennui! I'll try to get some version of this merged over the weekend. I hope you don't mind if I refactor it a little bit (left a comment explaining what I'll probably do) |
Codecov ReportAttention: Patch coverage is
❌ Your patch check has failed because the patch coverage (0.00%) is below the target coverage (90.00%). You can increase the patch coverage or adjust the target coverage. Additional details and impacted files@@ Coverage Diff @@
## master #567 +/- ##
==========================================
- Coverage 98.16% 97.57% -0.60%
==========================================
Files 12 13 +1
Lines 381 453 +72
Branches 113 134 +21
==========================================
+ Hits 374 442 +68
- Misses 5 9 +4
Partials 2 2
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
Not at all, go for it; makes sense to me. |
|
https://github.com/lovelaze/nebula-sync has a better method of selectively syncing the contents of the config backup JSON by having mutually exclusive include/exclude filters and recursive parsing, instead of hardcoding what the structure should be in the patched config. |
Adds a couple functions to GET and PATCH specific portions of /api/config for v6 PiHoles that can be used when syncing the entirety of the config file is not preferred.
Currently supports syncing of:
Resolves #565
Desired functionality mentioned in #190, #576