-
-
Notifications
You must be signed in to change notification settings - Fork 2.9k
Fix API logic in api.sh #6193
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix API logic in api.sh #6193
Conversation
Signed-off-by: Christian König <github@yubiuser.dev>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If the API isn't available then immediately write to log exit
, no need to create a local variable to track.
We need the variable because it is set within the loop. The |
Okay, then the logic is off here. I don't like having What happens if the API is changed to return a 403? Do we currently keep iterating through the list of URLs even after we find an open endpoint? Do we track which URL was 200, or which URL was 401? |
|
No. pi-hole/advanced/Scripts/api.sh Lines 74 to 76 in 1bea6db
Yes. As we exit the loop once we found a responding URL, it's the one set at this moment in pi-hole/advanced/Scripts/api.sh Lines 66 to 68 in 1bea6db
This is (almost) exactly what we do.
I see your point but we adhere to the HTTP return codes used everywhere. I can reverse the logic to explicitly check for |
I like explicit, if we need 200 or 401 then check for 200 or 401. Read through
And tell me what we're looking for, compared to (pseudocode-ish): # Test if http status code is 200 (OK)
if [ "${authStatus}" = 200 ]; then
needAuth=false
# Test if http status is 401 (Auth required)
elif [ "${authStatus}" = 401]; then
# Check if 2FA is required
needTOTP=$(echo "${authData}"| jq --raw-output .session.totp 2>/dev/null)
else
# Remove the first URL from the list
local last_api_list
last_api_list="${chaos_api_list}"
chaos_api_list="${chaos_api_list#* }"
# If the list did not change, we are at the last element
if [ "${last_api_list}" = "${chaos_api_list}" ]; then
# Remove the last element
chaos_api_list=""
# List of URLs is empty and we have not found a valid URL
echo "API not available. Please check FTL.log"
echo "Exiting."
exit 1
fi
fi |
Signed-off-by: Christian König <github@yubiuser.dev>
Logic is now reverted. |
What does this PR aim to accomplish?:
Fix the logic in
api.sh
. I noticed we had the leftoverAPI_PORT
which was intended to signal if we found a responding api. The check for emptiness war wrong in the first place (using-n
instead of-z
).This PR fixes the logic by better naming the variable and explicitly setting it to true/false.
By submitting this pull request, I confirm the following:
git rebase
)