diff --git a/entrypoint.sh b/entrypoint.sh index 44b5184..c4b6698 100755 --- a/entrypoint.sh +++ b/entrypoint.sh @@ -1,21 +1,23 @@ #!/bin/bash if [ $# == 0 ]; then - echo "Usage: url [grade] [followRedirects]" + echo "Usage: url [api-key] [grade] [followRedirects]" echo "* url: URL to analyse." + echo "* api-key: Your Security Headers API key." echo "* grade: The desired security grade of your HTTP response headers. Possible grades: A+, A, B, C, D, E, F. Defaults to B." echo "* followRedirects: Follow redirects. Defaults to on, set to off or false to disable." exit 1 fi - -GRADE=${2:-'B'} -FOLLOW_REDIRECTS=${3-'1'} +APIKEY=$2 +GRADE=${3:-'B'} +FOLLOW_REDIRECTS=${4-'1'} FOLLOW_REDIRECTS=${FOLLOW_REDIRECTS/true/1} FOLLOW_REDIRECTS=${FOLLOW_REDIRECTS/on/1} FOLLOW_REDIRECTS=${FOLLOW_REDIRECTS/false/0} FOLLOW_REDIRECTS=${FOLLOW_REDIRECTS/off/0} + declare -A grades=( ['A+']=7 ['A']=6 @@ -26,7 +28,7 @@ declare -A grades=( ['F']=1 ) -RATING=$(curl -s -L "https://securityheaders.com/?hide=on&followRedirects=$FOLLOW_REDIRECTS&q=$1" -I | sed -En 's/x-grade: (.*)/\1/p' | tr -d '\r') +RATING=$(curl -H "x-api-key: $APIKEY" -s -L "https://api.securityheaders.com/?hide=on&followRedirects=$FOLLOW_REDIRECTS&q=$1" | jq -r '.summary.grade') echo "::set-output name=rating::$RATING"