-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathentrypoint.sh
executable file
·62 lines (56 loc) · 2.59 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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
#!/bin/bash -l
execution_id=$1;
client_id=$2;
client_secret=$3;
realm=$4;
name=$5;
status=$6;
conclusion=$7;
log=$8;
idm_url=$9;
workflow_url=${10};
started_at=$(date +"%Y-%m-%d %T%z");
completed_at=$(date +"%Y-%m-%d %T%z");
workflow_service="$workflow_url/executions/$execution_id/workflows/steps"
idm_service="$idm_url/realms/$realm/protocol/openid-connect/token"
echo $workflow_service
echo $idm_service
secret_stk_login=$(curl --location --request POST "$idm_service" \
--header "Content-Type: application/x-www-form-urlencoded" \
--data-urlencode "client_id=$client_id" \
--data-urlencode "grant_type=client_credentials" \
--data-urlencode "client_secret=$client_secret" | jq -r .access_token)
if [[ "$status" == "pending" ]]; then
http_code=$(curl -s -o response.txt -w '%{http_code}' \
--location --request PUT "$workflow_service" \
--header "Authorization: Bearer $secret_stk_login" \
--header 'Content-Type: application/json' \
--data "{\"name\": \"$name\", \"status\": \"$status\", \"log\": \"$log\"}";)
elif [[ "$status" == "completed" ]]; then
http_code=$(curl -s -o response.txt -w '%{http_code}' \
--location --request PUT "$workflow_service" \
--header "Authorization: Bearer $secret_stk_login" \
--header 'Content-Type: application/json' \
--data "{\"name\": \"$name\", \"status\": \"$status\", \"started_at\": \"$started_at\", \"completed_at\": \"$completed_at\", \"conclusion\": \"$conclusion\", \"log\": \"$log\"}";)
else
http_code=$(curl -s -o response.txt -w '%{http_code}' \
--location --request PUT "$workflow_service" \
--header "Authorization: Bearer $secret_stk_login" \
--header 'Content-Type: application/json' \
--data "{\"name\": \"$name\", \"status\": \"$status\", \"started_at\": \"$started_at\", \"log\": \"$log\"}";)
fi
if [[ "$http_code" -ne "200" ]]; then
echo "------------------------------------------------------------------------------------------"
echo "---------------------------------------- Error Reporting ---------------------------------"
echo "------------------------------------------------------------------------------------------"
echo "HTTP_CODE:" $http_code
echo "RESPONSE_CONTENT:"
cat response.txt
exit $http_code
else
echo "------------------------------------------------------------------------------------------"
echo "---------------------------------------- Success Reporting -------------------------------"
echo "------------------------------------------------------------------------------------------"
echo "HTTP_CODE:" $http_code
cat response.txt
fi