-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathin
executable file
·58 lines (42 loc) · 1.24 KB
/
in
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
#!/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
# for jq
PATH=/usr/local/bin:$PATH
#
# Get parameters from the pipeline
#
payload=$(mktemp /tmp/resource-in.XXXXXX)
# read the payload from the input file
cat > "$payload" <&0
PAYLOAD_CONTENT=$(<$payload)
# use our functions
source /opt/resource/functions.sh
#
# parse payload JSON and extract properties,
# please refer to unit tests for comments
#
FYZON_URL=`extractUrl "$PAYLOAD_CONTENT"`
PROJECT_ID=`extractProjectId "$PAYLOAD_CONTENT"`
FORMAT=`extractFormat "$PAYLOAD_CONTENT"`
DELIMETER=`extractDelimeter "$PAYLOAD_CONTENT"`
COUNTRIES=`extractCountries "$PAYLOAD_CONTENT"`
# navigate to output folder
cd "$1"
# And now, download all the requested files
arrCountries=($COUNTRIES)
for country in "${arrCountries[@]}"
do
fileName="${country##*|}"
urlDownloadFile=`buildUrlToFile "$country" "$FORMAT" "$PROJECT_ID" "$FYZON_URL" "$DELIMETER"`
# and download
echo "Download $fileName file from Fyzon by URL: $urlDownloadFile"
curl -s "$urlDownloadFile" > "$fileName"
done
# ...and make a JSON to be passed as a resource output
jq -n "{
\"version\": {
\"url\": \"$FYZON_URL\"
}
}" >&3