-
Notifications
You must be signed in to change notification settings - Fork 10
/
mock-gs1-data.sh
executable file
·63 lines (50 loc) · 1.99 KB
/
mock-gs1-data.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
#!/bin/sh
# chmod +x this file to make it executable
SERVICE_NAME="Mock Global GS1 Resolver"
# Max number of retries
MAX_RETRIES=3
RETRY_COUNT=0
# Path to the Mock GS1 identifier JSON file
IDENTIFIER_FILE="./seeding/mock-gs1-identifier.json"
# Path to the Mock GS1 link resolver JSON file
IDENTIFICATIONS_FILE="./seeding/mock-gs1-link-resolver.json"
# Wait for the service to be available
echo "Waiting for ${SERVICE_NAME} service to be ready..."
# Loop until the health API returns "status": "OK"
while true; do
# If max retries reached, exit with error
if [ $RETRY_COUNT -eq $MAX_RETRIES ]; then
echo "${SERVICE_NAME} service did not become healthy after $MAX_RETRIES attempts. Exiting..."
exit 1
fi
# Make the health check request
HEALTH_STATUS=$(curl -s http://${MOCK_GS1_SERVICE_HOST}:${MOCK_GS1_SERVICE_PORT}/health-check | grep -o '"status":"OK"')
if [ "$HEALTH_STATUS" = '"status":"OK"' ]; then
echo "${SERVICE_NAME} service is healthy!"
break
fi
RETRY_COUNT=$((RETRY_COUNT+1))
echo "${SERVICE_NAME} service is not healthy yet. Retrying in 5 seconds..."
sleep 5 # Wait for 5 seconds before checking again
done
echo "${SERVICE_NAME} service is seeding data…"
# Execute create identifier request
curl -X POST \
http://${MOCK_GS1_SERVICE_HOST}:${MOCK_GS1_SERVICE_PORT}/api/identifiers \
-H 'accept: application/json' \
-H "Authorization: Bearer ${MOCK_GS1_SERVICE_API_KEY}" \
-H 'Content-Type: application/json' \
-d @"$IDENTIFIER_FILE"
printf "\n"
# Execute create link resolver requests
# Loop through JSON file and make curl requests for each identification
jq -c '.[]' "$IDENTIFICATIONS_FILE" | while read -r IDENTIFICATION; do
curl -X POST \
"http://${MOCK_GS1_SERVICE_HOST}:${MOCK_GS1_SERVICE_PORT}/api/resolver" \
-H 'accept: application/json' \
-H "Authorization: Bearer ${MOCK_GS1_SERVICE_API_KEY}" \
-H 'Content-Type: application/json' \
-d "$IDENTIFICATION"
printf "\n"
done
printf "\nSeeding ${SERVICE_NAME} service data complete!\n\n"