From f7c9f192a73a1570c442d03219574ea0eabd0502 Mon Sep 17 00:00:00 2001 From: Tim Otto Date: Sat, 30 Dec 2017 13:50:39 +0100 Subject: [PATCH] initial hack --- assets/out | 53 +++++++++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 51 insertions(+), 2 deletions(-) diff --git a/assets/out b/assets/out index 5d26eb3..be484e8 100755 --- a/assets/out +++ b/assets/out @@ -5,5 +5,54 @@ set -e exec 3>&1 # make stdout available as fd 3 for the result exec 1>&2 # redirect all output to stderr for logging -echo "OUT action not supported by this resource" -exit 1 +source $(dirname $0)/common.sh + +source=$1 + +if [ -z "$source" ]; then + echo "usage: $0 " + exit 1 +fi + +cd $source + +payload=$(mktemp $TMPDIR/concoure-curl-resource-request.XXXXXX) + +cat > $payload <&0 + +url=$(jq -r '.source.url // ""' < $payload) +filename=$(jq -r '.source.filename // ""' < $payload) +skip_ssl_verification=$(jq -r '.source.skip_ssl_verification // ""' < $payload) +username=$(jq -r '.source.username // ""' < $payload) +password=$(jq -r '.source.password // ""' < $payload) +method=$(jq -r '.source.method // "POST"' < $payload) + +if [ -z "$url" ]; then + echo "invalid payload (missing url)" + exit 1 +fi + +if [ -z "$filename" ]; then + echo "invalid payload (missing filename)" + exit 1 +fi + +# Building CURL request +args_url="$url" +args_security= +[ -n "$username" ] && args_security="-u $username"; +[ -n "$username" ] && [ -n "$password" ] && args_security="$args_security:$password"; + +trueValue="true" +[ -n "$skip_ssl_verification" ] && [ "${skip_ssl_verification,,}" = "${trueValue,,}" ] && args_security="$args_security -k"; + +curl "-X" "$method" "--upload-file" "$filename" $args_security "$args_url" + +final_url=$(echo "$args_security" " $args_url") +version=$(check_version "$final_url") +if [ -z "$version" ]; then + echo "Version could not be retrieved" + exit 1 +fi + +jq -n "{ version: {version: $(echo $version | jq .[].version )}}" >&3