Commit 0e789a1b authored by Alain Takoudjou's avatar Alain Takoudjou

check_url_available recipe support certificate and key for client authentication

parent 68aa5e7d
......@@ -39,6 +39,9 @@ class Recipe(GenericBaseRecipe):
'curl_path': self.options['curl_path'],
'check_secure': self.options.get('check-secure', 0),
'http_code': self.options.get('http_code', '200'),
'ca-cert-file': self.options.get('ca-cert-file', ''),
'cert-file': self.options.get('cert-file', ''),
'key-file': self.options.get('key-file', ''),
}
# XXX-Cedric in this script, curl won't check certificate
......
......@@ -3,13 +3,31 @@
# BEWARE: It will be overwritten automatically
URL="%(url)s"
F_TIMEOUT="%(time_out)s"
TIMEOUT=20
CA_CERT="%(ca-cert-file)s"
CERT="%(cert-file)s"
KEY="%(key-file)s"
if [ -z "$URL" ]; then
echo "No URL specified." >&2
exit 3
fi
CODE=$(%(curl_path)s -g -k -sL $URL -w %%{http_code} --max-time 10 -o /dev/null)
if [ -s "$F_TIMEOUT" ]; then
TIMEOUT=$(cat $F_TIMEOUT)
result=$(echo $TIMEOUT | grep -E ^[0-9]+$)
if [ -z $result ]; then
# Not an integer
TIMEOUT=20
fi
fi
if [ -z "$CA_CERT" ] || [ -z "$CERT" ] || [ -z "$KEY" ]; then
CODE=$(%(curl_path)s -g -k -sL $URL -w %%{http_code} --max-time $TIMEOUT -o /dev/null)
else
CODE=$(%(curl_path)s -g -k -sL $URL -w %%{http_code} --max-time $TIMEOUT -o /dev/null --cacert $CA_CERT --cert $CERT --key $KEY)
fi
if [ $? -eq 3 ]; then
echo "URL malformed: $URL." >&2
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment