-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathout
executable file
·77 lines (59 loc) · 1.74 KB
/
out
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
75
76
77
#!/bin/sh
set -e
exec 3>&1
exec 1>&2
inputs=$(mktemp /tmp/resource-in.XXXXXX)
cat > "$inputs" <&0
app_id=$(jq -r '.source.app_id' < "$inputs")
api_key=$(jq -r '.source.api_key' < "$inputs")
json_file=$(jq -r '.params.json_file // ""' < "$inputs")
user=$(jq -r '(.params.user // empty)' < "$inputs")
if [ -n "${json_file}" ] && [ -f "${json_file}" ]; then
if [ "$(jq 'has("revision")' "$json_file")" = "false" ]; then
echo "revision is missing from the json_file. cannot continue"
exit 1
fi
revision=$(jq -r '.revision' "$json_file")
changelog=$(jq -r '(.changelog // empty)' "$json_file")
description=$(jq -r '(.description // empty)' "$json_file")
fi
body=$(jq -c -n \
--arg revision "${revision}" \
--arg changelog "${changelog}" \
--arg description "${description}" \
--arg user "${user}" \
'{
deployment: {
revision: $revision,
changelog: $changelog,
description: $description,
user: $user
}
}'
)
RESPONSE=$(curl -X POST "https://api.newrelic.com/v2/applications/${app_id}/deployments.json" \
-H "X-Api-Key:${api_key}" -i \
-H "Content-Type: application/json" \
-d "${body}")
STATUS=$(echo "$RESPONSE" | awk '/HTTP/ { print $2 }')
if [ "$STATUS" -ne "200" ] && [ "$STATUS" -ne "201" ]; then
echo "$RESPONSE"
exit 1;
fi
jq -n \
--arg ts "$(date +%s)" \
--arg revision "${revision}" \
--arg changelog "${changelog}" \
--arg description "${description}" \
--arg user "${user}" \
'{
version: {
timestamp: $ts
},
metadata: [
{name: "revision", value: $revision},
{name: "changelog", value: $changelog},
{name: "description", value: $description},
{name: "user", value: $user}
]
}' >&3