Skip to content

Commit

Permalink
add timeout
Browse files Browse the repository at this point in the history
  • Loading branch information
eytannnaim committed Nov 20, 2023
1 parent c57058e commit 122ba08
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 4 deletions.
11 changes: 7 additions & 4 deletions modules/aws/mx/configuration.tf
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
locals {
conf_timeout = 60 * 15
conf_timeout = 60 * 40

configuration_elements = concat(
local.service_group_configuration,
Expand All @@ -8,9 +8,12 @@ locals {
)
commands = <<-EOF
${templatefile("${path.module}/configure.tftpl",
{ mx_address = local.mx_address_for_api
https_auth_header = local.https_auth_header
configuration_elements = local.configuration_elements })}
{ mx_address = local.mx_address_for_api
https_auth_header = local.https_auth_header
configuration_elements = local.configuration_elements
timeout = local.conf_timeout
})
}
EOF
}

Expand Down
14 changes: 14 additions & 0 deletions modules/aws/mx/configure.tftpl
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,20 @@
set -x
set -e

start_time=$(date +%s)

cookie_file=$(mktemp)
response_file=$(mktemp)

function exit_on_timeout() {
now=$(date +%s)
elapsed=$((now-start_time))
if [ $elapsed -gt ${timeout} ]; then
echo "Timeout reached."
exit 1
fi
}

http_code=$(curl -k -s --cookie-jar $cookie_file -o $response_file -w "%%{http_code}" \
--request POST 'https://${mx_address}:8083/SecureSphere/api/v1/auth/session' \
--header "Authorization: Basic ${https_auth_header}")
Expand All @@ -27,6 +38,7 @@ while true; do
fi
fi

exit_on_timeout
echo "sleep 1m"
sleep 60
done
Expand All @@ -52,6 +64,8 @@ while true; do
break
fi
fi

exit_on_timeout
echo "sleep 1m"
sleep 60
done
Expand Down

0 comments on commit 122ba08

Please sign in to comment.