You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

58 lines
1.4 KiB

8 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
  1. #!/bin/bash
  2. set -e
  3. exec 3>&1 # make stdout available as fd 3 for the result
  4. exec 1>&2 # redirect all output to stderr for logging
  5. source $(dirname $0)/common.sh
  6. source=$1
  7. if [ -z "$source" ]; then
  8. echo "usage: $0 <path/to/source>"
  9. exit 1
  10. fi
  11. cd $source
  12. payload=$(mktemp $TMPDIR/concoure-curl-resource-request.XXXXXX)
  13. cat > $payload <&0
  14. url=$(jq -r '.source.url // ""' < $payload)
  15. path=$(jq -r '.params.path // ""' < $payload)
  16. skip_ssl_verification=$(jq -r '.source.skip_ssl_verification // ""' < $payload)
  17. username=$(jq -r '.source.username // ""' < $payload)
  18. password=$(jq -r '.source.password // ""' < $payload)
  19. method=$(jq -r '.source.method // "POST"' < $payload)
  20. if [ -z "$url" ]; then
  21. echo "invalid payload (missing url)"
  22. exit 1
  23. fi
  24. if [ -z "$path" ]; then
  25. echo "invalid payload (missing path)"
  26. exit 1
  27. fi
  28. # Building CURL request
  29. args_url="$url"
  30. args_security=
  31. [ -n "$username" ] && args_security="-u $username";
  32. [ -n "$username" ] && [ -n "$password" ] && args_security="$args_security:$password";
  33. trueValue="true"
  34. [ -n "$skip_ssl_verification" ] && [ "${skip_ssl_verification,,}" = "${trueValue,,}" ] && args_security="$args_security -k";
  35. curl "-X" "$method" "--upload-file" "$path" $args_security "$args_url"
  36. final_url=$(echo "$args_security" " $args_url")
  37. version=$(check_version "$final_url")
  38. if [ -z "$version" ]; then
  39. echo "Version could not be retrieved"
  40. exit 1
  41. fi
  42. jq -n "{ version: {version: $(echo $version | jq .[].version )}}" >&3