Skip to content

Commit

Permalink
Relax constraints on timeout options
Browse files Browse the repository at this point in the history
  • Loading branch information
Tom Scavo committed Nov 12, 2016
1 parent ce77bff commit e8b5440
Showing 1 changed file with 29 additions and 17 deletions.
46 changes: 29 additions & 17 deletions bin/check_idp_error_urls.sh
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ display_help () {
Given a list of entityIDs and a metadata source, for each IdP
probe its errorURL in metadata (if any).
Usage: ${0##*/} [-hvq] [-d OUT_DIR] [-t CONNECT_TIME -m MAX_TIME] (-u MDQ_BASE_URL | -f MD_PATH) [ID ...]
Usage: ${0##*/} [-hvq] [-d OUT_DIR] [-t CONNECT_TIME [-m MAX_TIME]] (-u MDQ_BASE_URL | -f MD_PATH) [ID ...]
The script optionally takes a sequence of identifiers on the command
line. If none are given, the script takes its input from stdin.
Expand Down Expand Up @@ -61,12 +61,16 @@ display_help () {
consume all available TCP connect time. Thus the TCP connect
time should be kept small (say, less than 10 seconds) since
larger values will slow this script considerably. The default
value of this option argument is $connect_timeout_default secs.
value of this option is $connect_timeout_default secs.
The argument of the -m option is the maximum total time (in secs)
allotted to each probe. A reasonable value is a few seconds
beyond the TCP connect time. Any value less than the TCP connect
time causes the script to immediately fail.
time causes the script to immediately fail. If the -m option is
present on the command line, then the -t option must also be
present. If the -m option is omitted, its value is set to the
TCP connect time plus 2 secs, whether or not the -t option is
present.
Entity metadata is required to process each identifier. Metadata is
obtained in one of two ways, by consulting a Metadata Query Server
Expand Down Expand Up @@ -251,9 +255,8 @@ for lib_filename in $LIB_FILENAMES; do
fi
done

# default parameters
# default timeout option
connect_timeout_default=2
max_time_default=4

# output filenames
NO_IDP_ROLE_FILENAME="entities-no-idp-role.txt"
Expand Down Expand Up @@ -320,7 +323,7 @@ if $help_mode; then
exit 0
fi

# report bootstrap operation
# report bootstrap operations
if $verbose_mode; then
printf "$script_name using source lib directory: %s\n" "$LIB_DIR"
for lib_filename in $LIB_FILENAMES; do
Expand Down Expand Up @@ -376,23 +379,32 @@ else
fi
fi

# check consistency of timeout options (both or neither are required)
if [ -z "$connect_timeout" -a -z "$max_time" ]; then
# check consistency of timeout options
if [ -n "$max_time" -a -z "$connect_timeout" ]; then
echo "ERROR: $script_name: the -m option requires the presence of the -t option" >&2
exit 2
fi

# set default connect timeout if necessary
if [ -z "$connect_timeout" ]; then
connect_timeout=$connect_timeout_default
max_time=$max_time_default
elif [ -n "$connect_timeout" -a -n "$max_time" ]; then
if [ ! "${connect_timeout}" -gt 0 ] ; then
echo "ERROR: $script_name: connect timeout must be a positive integer: ${connect_timeout}" >&2
else
if [ "$connect_timeout" -le 0 ] ; then
echo "ERROR: $script_name: connect timeout ($connect_timeout) must be a positive integer" >&2
exit 2
fi
if [ ! "${max_time}" -gt "${connect_timeout}" ]; then
echo "ERROR: $script_name: max time must be greater than the connect timeout: ${max_time}" >&2
fi

# compute max time if necessary
if [ -z "$max_time" ]; then
max_time=$(( connect_timeout + 2 ))
else
if [ "$max_time" -le "$connect_timeout" ]; then
echo "ERROR: $script_name: max time ($max_time) must be greater than the connect timeout ($connect_timeout)" >&2
exit 2
fi
else
echo "ERROR: $script_name: both (or neither) options -t and -m are required" >&2
exit 2
fi

if $verbose_mode; then
printf "$script_name using connect timeout: %d secs\n" $connect_timeout
printf "$script_name using max time: %d secs\n" $max_time
Expand Down

0 comments on commit e8b5440

Please sign in to comment.