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

#!/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
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)
file=$(jq -r '.params.file // ""' < $payload)
folder=$(jq -r '.params.folder // ""' < $payload)
paramRegex=$(jq -r '.params.regex // ""' < $payload)
version=$(jq -r '.version.version // ""' < $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
# Building CURL request
args_url="$endpoint/api/storage$repository$folder"
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";
if [ -n "$paramRegex" ]; then
echo "overwriting source regex"
regex=$paramRegex
fi
final_url=$(echo "$args_security" " $args_url")
echo $final_url
if [ -z "$version" ]; then
echo "empty version - return current version"
artifactory_current_version "$final_url" "$regex" >&3
else
check_version "$final_url" "$regex" "$version" >&3
fi