forked from jdmevo123/akamai-mpulse-annotation-action
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathentrypoint.sh
43 lines (40 loc) · 1.19 KB
/
entrypoint.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
#!/bin/bash
set -e
set -o pipefail
# Set Variables
apiToken=$1
title=$2
text=$3
time=$(date +%s000)
if [ -n "$4" ]; then
domainIds=$4
fi
if [ -z "$4" ]; then
domainIds=""
fi
# Get API Token SSO
authToken=$(curl -X PUT -H "Content-type: application/json" --data-binary '{"apiToken":"'${apiToken}'"}' \
"https://mpulse.soasta.com/concerto/services/rest/RepositoryService/v1/Tokens" | jq '.["token"]' | tr -d '"')
# Execute Annotation
if [ "$domainIds" == "" ]; then
data='{ "title":"'${title}'", "start":'${time}', "text":"'${text}'" }'
fi
if [ "$domainIds" != "" ]; then
data='{ "title":"'${title}'", "start":'${time}', "text":"'${text}'", "domainIds":"['${domainIds}']" }'
fi
annotation=$(curl -X POST \
-H "X-Auth-Token: $authToken" \
-H "Content-type: application/json" \
--data-binary "$data"\
"https://mpulse.soasta.com/concerto/mpulse/api/annotations/v1")
annotation=$(echo $annotation | jq '.["id"]' | tr -d '"')
if [ "$annotation" == null ]; then
echo "Failed : Annotation ID was empty" && exit 1;
fi
if [ -n "$annotation" ]; then
echo "success : $annotation"
echo $annotation > annotationID.txt
fi
if [ -z "$annotation" ]; then
echo "Failed : $annotation" && exit 1;
fi