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.

84 lines
2.0 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. 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/artifactory-resource-request.XXXXXX)
  13. cat > $payload <&0
  14. cat $payload
  15. endpoint=$(jq -r '.source.endpoint // ""' < $payload)
  16. regex=$(jq -r '.source.regex // ""' < $payload)
  17. username=$(jq -r '.source.username // ""' < $payload)
  18. password=$(jq -r '.source.password // ""' < $payload)
  19. skip_ssl_verification=$(jq -r '.source.skip_ssl_verification // ""' < $payload)
  20. repository=$(jq -r '.source.repository // ""' < $payload)
  21. file=$(jq -r '.params.file // ""' < $payload)
  22. folder=$(jq -r '.params.folder // ""' < $payload)
  23. paramRegex=$(jq -r '.params.regex // ""' < $payload)
  24. version=$(jq -r '.version.version // ""' < $payload)
  25. if [ -z "$endpoint" ]; then
  26. echo "invalid payload (missing endpoint)"
  27. exit 1
  28. fi
  29. if [ -z "$repository" ]; then
  30. echo "invalid payload (missing repository)"
  31. exit 1
  32. fi
  33. if [ -z "$version" ]; then
  34. echo "Missing version"
  35. exit 1
  36. fi
  37. # Building CURL request
  38. args_url="$endpoint/api/storage$repository$folder"
  39. args_security=
  40. [ -n "$username" ] && args_security="-u $username";
  41. [ -n "$password" ] && args_security="$args_security:$password";
  42. trueValue="true"
  43. [ -n "$skip_ssl_verification" ] && [ "${skip_ssl_verification,,}" = "${trueValue,,}" ] && args_security="$args_security -k";
  44. if [ -n "$paramRegex" ]; then
  45. echo "overwriting source regex"
  46. regex=$paramRegex
  47. fi
  48. final_url=$(echo "$args_security" " $args_url")
  49. echo $final_url
  50. file_json=$(in_file_with_version "$final_url" "$regex" "$version")
  51. file=$(echo $file_json | jq -r '.[].uri')
  52. if [ -z "$file" ]; then
  53. echo "file for version '$version' not found"
  54. exit 1
  55. fi
  56. args_url="$endpoint$repository/$file"
  57. echo $args_security "-O" "$args_url"
  58. curl $args_security "-O" "$args_url"
  59. echo $file_json | jq '.[].version | {version: {version: .}}' >&3