Address review comments

Signed-off-by: Adam Warner <me@adamwarner.co.uk>
This commit is contained in:
Adam Warner 2022-04-04 22:02:26 +01:00
parent 7fa8cdd03e
commit 4d31d5ee11
No known key found for this signature in database
GPG key ID: 872950F3ECF2B173
4 changed files with 10 additions and 10 deletions

View file

@ -56,11 +56,11 @@ addOrEditKeyValPair() {
# Deletes a key from target file
#
# Example usage:
# removeKey "PIHOLE_DNS_1" "/etc/pihole/setupVars.conf"
# removeKey "/etc/pihole/setupVars.conf" "PIHOLE_DNS_1"
#######################
removeKey() {
local key="${1}"
local file="${2}"
local file="${1}"
local key="${2}"
sed -i "/^${key}/d" "${file}"
}

View file

@ -60,7 +60,7 @@ add_setting() {
}
delete_setting() {
removeKey "${1}" "${setupVars}"
removeKey "${setupVars}" "${1}"
}
change_setting() {
@ -72,7 +72,7 @@ addFTLsetting() {
}
deleteFTLsetting() {
removeKey "${1}" "${FTLconf}"
removeKey "${FTLconf}" "${1}"
}
changeFTLsetting() {
@ -84,7 +84,7 @@ add_dnsmasq_setting() {
}
delete_dnsmasq_setting() {
removeKey "${1}" "${dnsmasqconfig}"
removeKey "${dnsmasqconfig}" "${1}"
}
SetTemperatureUnit() {

4
pihole
View file

@ -260,7 +260,7 @@ Options:
exit 0
elif [[ "${1}" == "off" ]]; then
# Disable logging
sed -i 's/^log-queries/#log-queries/' /etc/dnsmasq.d/01-pihole.conf
addOrEditKeyValPair /etc/dnsmasq.d/01-pihole.conf "log-queries"
addOrEditKeyValPair "${setupVars}" "QUERY_LOGGING" "false"
if [[ "${2}" != "noflush" ]]; then
# Flush logs
@ -270,7 +270,7 @@ Options:
local str="Logging has been disabled!"
elif [[ "${1}" == "on" ]]; then
# Enable logging
sed -i 's/^#log-queries/log-queries/' /etc/dnsmasq.d/01-pihole.conf
removeKey /etc/dnsmasq.d/01-pihole.conf "log-queries"
addOrEditKeyValPair "${setupVars}" "QUERY_LOGGING" "true"
echo -e " ${INFO} Enabling logging..."
local str="Logging has been enabled!"

View file

@ -17,13 +17,13 @@ def test_key_val_replacement_works(host):
def test_key_val_removal_works(host):
''' Confirms addOrEditKeyValPair provides the expected output '''
''' Confirms removeKey provides the expected output '''
host.run('''
source /opt/pihole/utils.sh
addOrEditKeyValPair "./testoutput" "KEY_ONE" "value1"
addOrEditKeyValPair "./testoutput" "KEY_TWO" "value2"
addOrEditKeyValPair "./testoutput" "KEY_THREE" "value3"
removeKey "KEY_TWO" "./testoutput"
removeKey "./testoutput" "KEY_TWO"
''')
output = host.run('''
cat ./testoutput