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.

62 lines
1.6 KiB

8 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. payload=$(mktemp $TMPDIR/artifactory-resource-request.XXXXXX)
  7. cat > $payload <&0
  8. cat $payload
  9. endpoint=$(jq -r '.source.endpoint // ""' < $payload)
  10. regex=$(jq -r '.source.regex // ""' < $payload)
  11. username=$(jq -r '.source.username // ""' < $payload)
  12. password=$(jq -r '.source.password // ""' < $payload)
  13. skip_ssl_verification=$(jq -r '.source.skip_ssl_verification // ""' < $payload)
  14. repository=$(jq -r '.source.repository // ""' < $payload)
  15. file=$(jq -r '.params.file // ""' < $payload)
  16. folder=$(jq -r '.params.folder // ""' < $payload)
  17. paramRegex=$(jq -r '.params.regex // ""' < $payload)
  18. version=$(jq -r '.version.version // ""' < $payload)
  19. if [ -z "$endpoint" ]; then
  20. echo "invalid payload (missing endpoint)"
  21. exit 1
  22. fi
  23. if [ -z "$repository" ]; then
  24. echo "invalid payload (missing repository)"
  25. exit 1
  26. fi
  27. # Building CURL request
  28. args_url="$endpoint/api/storage$repository$folder"
  29. args_security=
  30. [ -n "$username" ] && args_security="-u $username";
  31. [ -n "$password" ] && args_security="$args_security:$password";
  32. trueValue="true"
  33. [ -n "$skip_ssl_verification" ] && [ "${skip_ssl_verification,,}" = "${trueValue,,}" ] && args_security="$args_security -k";
  34. if [ -n "$paramRegex" ]; then
  35. echo "overwriting source regex"
  36. regex=$paramRegex
  37. fi
  38. final_url=$(echo "$args_security" " $args_url")
  39. echo $final_url
  40. if [ -z "$version" ]; then
  41. echo "empty version - return current version"
  42. artifactory_current_version "$final_url" "$regex" >&3
  43. else
  44. check_version "$final_url" "$regex" "$version" >&3
  45. fi