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.

83 lines
1.8 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. folder=$(jq -r '.params.folder // ""' < $payload)
  22. file=$(jq -r '.params.file // ""' < $payload)
  23. paramRegex=$(jq -r '.params.regex // ""' < $payload)
  24. if [ -z "$endpoint" ]; then
  25. echo "invalid payload (missing endpoint)"
  26. exit 1
  27. fi
  28. if [ -z "$repository" ]; then
  29. echo "invalid payload (missing repository)"
  30. exit 1
  31. fi
  32. if [ -z "$file" ]; then
  33. echo "invalid payload (missing file)"
  34. exit 1
  35. fi
  36. abs_file=$(ls $file)
  37. filename=$(basename "$abs_file")
  38. args_url="$endpoint"
  39. args_url="$args_url$repository"
  40. if [ -n "$folder" ]; then
  41. echo "adding parameter folder"
  42. args_url="$args_url/$folder"
  43. fi
  44. args_url="$args_url/$filename"
  45. args_security=
  46. [ -n "$username" ] && args_security="-u $username";
  47. [ -n "$password" ] && args_security="$args_security:$password";
  48. trueValue="true"
  49. [ -n "$skip_ssl_verification" ] && [ "${skip_ssl_verification,,}" = "${trueValue,,}" ] && args_security="$args_security -k";
  50. echo "########## $filename, $file"
  51. echo $args_security "-T $abs_file $args_url "
  52. curl $args_security "-T$abs_file" "$args_url"
  53. echo $file $regex
  54. version=$(applyRegex_version $regex $filename)
  55. jq -n "{
  56. version: {version: $(echo $version | jq -R .)}
  57. }" >&3