From b39d0205df7dab815eaf518c74bf3adf7bf52f80 Mon Sep 17 00:00:00 2001 From: Ivaylo Novakov Date: Fri, 11 Feb 2022 13:55:29 +0100 Subject: [PATCH] Move the check to the start of the script. --- setup-scripts/blocklist-airtable.py | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/setup-scripts/blocklist-airtable.py b/setup-scripts/blocklist-airtable.py index d59c934e..0fc246bd 100755 --- a/setup-scripts/blocklist-airtable.py +++ b/setup-scripts/blocklist-airtable.py @@ -39,6 +39,16 @@ def exec(command): async def block_skylinks_from_airtable(): + # Get nginx's IP before doing anything else. If this step fails we don't + # need to continue with the execution of the script. + ipaddress = exec( + "docker inspect -f '{{range.NetworkSettings.Networks}}{{.IPAddress}}{{end}}' nginx" + ) + + if ipaddress == "": + print("Nginx's IP could not be detected. Exiting.") + return + print("Pulling blocked skylinks from Airtable via api integration") headers = {"Authorization": "Bearer " + AIRTABLE_API_KEY} skylinks = [] @@ -122,14 +132,6 @@ async def block_skylinks_from_airtable(): ) await send_msg(message, file=("\n".join(invalid_skylinks))) - ipaddress = exec( - "docker inspect -f '{{range.NetworkSettings.Networks}}{{.IPAddress}}{{end}}' nginx" - ) - - if ipaddress == "": - print("Nginx's IP could not be detected. Exiting.") - return - print("Sending blocklist request to siad through nginx") response = requests.post( "http://" + ipaddress + ":8000/skynet/blocklist",