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.
|
|
#!/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) 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
if [ -z "$version" ]; then echo "Missing version" 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
file_json=$(in_file_with_version "$final_url" "$regex" "$version") file=$(echo $file_json | jq -r '.[].uri')
if [ -z "$file" ]; then echo "file for version '$version' not found" exit 1 fi
args_url="$endpoint$repository/$file"
echo $args_security "-O" "$args_url" curl $args_security "-O" "$args_url"
echo $file_json | jq '.[].version | {version: {version: .}}' >&3
|