-
Notifications
You must be signed in to change notification settings - Fork 3
/
regenerate.sh
executable file
·74 lines (55 loc) · 1.83 KB
/
regenerate.sh
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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
#!/bin/bash -e
INPUT=$1
# aws --profile $AWS_PROFILE s3 ls --recursive s3://dev-media-unee-t/ | grep json$ | grep 2018-11-23 | while read -r _ _ _ fn; do echo s3://dev-media-unee-t/$fn; done
udomain() {
case $1 in
prod) echo $2.unee-t.com
;;
*) echo $2.$1.unee-t.com
;;
esac
}
if test "${INPUT##*.}" != "json"
then
echo Require JSON file, not $INPUT
exit 1
fi
BUCKET=$(echo $INPUT | awk -F[/:] '{print $4}')
case $BUCKET in
prod-media-unee-t)
STAGE=prod
;;
dev-media-unee-t)
STAGE=dev
;;
*)
echo Unknown bucket: $BUCKET
exit 1
;;
esac
AWS_PROFILE=uneet-$STAGE
# step 1 download JSON
aws --profile $AWS_PROFILE s3 cp $INPUT /tmp
# step 2 regenerate HTML file
fn=/tmp/$(basename $INPUT)
echo Working on $fn
cat <<< "$(jq ".force += true " < $fn)" > $fn
HTML=$(curl -X POST \
https://$(udomain $STAGE pdfgen) \
-H "Authorization: Bearer $(aws --profile $AWS_PROFILE ssm get-parameters --names API_ACCESS_TOKEN --with-decryption --query Parameters[0].Value --output text)" \
-H 'Content-Type: application/json' \
-H 'cache-control: no-cache' \
--data @$fn |
jq -r .HTML)
echo New output: $HTML
# step 3, regenerate PDF
date=$(jq -r .date < $fn)
echo Setting date: $date
# document_url must be from the host unee-t.com btw
curl -X POST \
https://$(udomain $STAGE prince) \
-H 'Content-Type: application/json' \
-H 'cache-control: no-cache' \
-d "{ \"document_url\": \"$HTML\", \"date\": \"$date\"}"
#aws --profile uneet-dev cloudfront create-invalidation --distribution-id E2L4KVYCVKXLA1 --invalidation-batch "{ \"Paths\": { \"Quantity\": 1, \"Items\": [ \"/*\" ] }, \"CallerReference\": \"$(shell date +%s)\" }"
#aws --profile uneet-prod cloudfront create-invalidation --distribution-id E3NBG008M01XS8 --invalidation-batch "{ \"Paths\": { \"Quantity\": 1, \"Items\": [ \"/*\" ] }, \"CallerReference\": \"$(shell date +%s)\" }"