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

#!/bin/bash
set -e
exec 3>&1 # make stdout available as fd 3 for the result
exec 1>&2 # redirect all output to stderr for logging
source $(dirname $0)/common.sh
source=$1
if [ -z "$source" ]; then
echo "usage: $0 <path/to/source>"
exit 1
fi
cd $source
payload=$(mktemp $TMPDIR/artifactory-resource-request.XXXXXX)
cat > $payload <&0
cat $payload
endpoint=$(jq -r '.source.endpoint // ""' < $payload)
regex=$(jq -r '.source.regex // ""' < $payload)
username=$(jq -r '.source.username // ""' < $payload)
password=$(jq -r '.source.password // ""' < $payload)
skip_ssl_verification=$(jq -r '.source.skip_ssl_verification // ""' < $payload)
repository=$(jq -r '.source.repository // ""' < $payload)
folder=$(jq -r '.params.folder // ""' < $payload)
file=$(jq -r '.params.file // ""' < $payload)
paramRegex=$(jq -r '.params.regex // ""' < $payload)
if [ -z "$endpoint" ]; then
echo "invalid payload (missing endpoint)"
exit 1
fi
if [ -z "$repository" ]; then
echo "invalid payload (missing repository)"
exit 1
fi
if [ -z "$file" ]; then
echo "invalid payload (missing file)"
exit 1
fi
abs_file=$(ls $file)
filename=$(basename "$abs_file")
args_url="$endpoint"
args_url="$args_url$repository"
if [ -n "$folder" ]; then
echo "adding parameter folder"
args_url="$args_url/$folder"
fi
args_url="$args_url/$filename"
args_security=
[ -n "$username" ] && args_security="-u $username";
[ -n "$password" ] && args_security="$args_security:$password";
trueValue="true"
[ -n "$skip_ssl_verification" ] && [ "${skip_ssl_verification,,}" = "${trueValue,,}" ] && args_security="$args_security -k";
echo "########## $filename, $file"
echo $args_security "-T $abs_file $args_url "
curl $args_security "-T$abs_file" "$args_url"
echo $file $regex
version=$(applyRegex_version $regex $filename)
jq -n "{
version: {version: $(echo $version | jq -R .)}
}" >&3