feat: add Config write/property functions, completing the Config API area - #123
Merged
Merged
Conversation
…area
Extends Get-PiHoleConfig with -Element (request one subset of the
config tree, e.g. "dns/upstreams") and -Detailed. Adds Set-PiHoleConfig
(PATCH /config), Add/Remove-PiHoleConfigArrayItem (PUT/DELETE
/config/{element}/{value}, for array-type settings like dns/hosts and
dns/cnameRecords), and Get-PiHoleConfigProperty (the list of settings
that can never be changed via the API).
All three write functions require the app password's "app_sudo" flag
to be enabled in Pi-hole (Settings > All Settings) - Pi-hole blocks
config changes from app passwords by default, and there's no way to
enable it via the API itself (avoiding that would defeat the point).
Verified against a real server with app_sudo both disabled and
enabled: a real config value can be changed and reverted, an
array item can be added and removed, and a genuinely read-only
property (misc.readOnly) is correctly rejected.
Adds ConvertTo-PiHoleFriendlyErrorMessage (Private/Misc.ps1), used by
the three write functions' error handling: Pi-hole's own error
responses carry a clearer message/hint than the generic HTTP exception
text, and for the app_sudo case specifically, a concrete pointer to
where to enable it - previously the module surfaced only "403
(Forbidden)" or "400 (Bad Request)" with no explanation.
Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
3 tasks done
…agement # Conflicts: # README.md # docs/EXAMPLES.md
Resolves the README.md/docs/EXAMPLES.md conflicts from merging develop (which now includes PR #122's Client Management and Network Information) by regenerating both from the merged source instead of hand-resolving generated-file diffs. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
1 task done
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Get-PiHoleConfigwith-Element(request one subset of the config tree, e.g."dns/upstreams") and-Detailed.Set-PiHoleConfig(PATCH /config),Add-PiHoleConfigArrayItem/Remove-PiHoleConfigArrayItem(PUT/DELETE /config/{element}/{value}, for array-type settings likedns/hostsanddns/cnameRecords- this is where local DNS records and CNAMEs live), andGet-PiHoleConfigProperty(the list of settings that can never be changed via the API).app_sudoflag to be enabled in Pi-hole (Settings > All Settings) - Pi-hole blocks config changes from app passwords by default, and there's no way to enable it via the API itself (that would defeat the point of the restriction). This is documented in each function's.DESCRIPTION.ConvertTo-PiHoleFriendlyErrorMessage(Private/Misc.ps1), used by the three write functions' error handling: Pi-hole's own error responses carry a clearer message/hint than the generic HTTP exception text, and for theapp_sudocase specifically, a concrete pointer to where to enable it - previously the module surfaced only"403 (Forbidden)"or"400 (Bad Request)"with no explanation of why or how to fix it.This completes the "Config" area from the API coverage audit (5 of 5 operations implemented).
Test plan
app_sudodisabled (confirming the 403 and its improved error message) and enabled (confirming a real config value can be changed and reverted, an array item can be added and removed, and a genuinely read-only property (misc.readOnly) is correctly rejected with a clear reason).debug.api) or a fake TEST-NET-1 host entry - never real DNS/DHCP/network behavior.docs/EXAMPLES.md.Invoke-ScriptAnalyzerclean against the full module.🤖 Generated with Claude Code