-
Notifications
You must be signed in to change notification settings - Fork 0
/
utils.sh
executable file
·71 lines (59 loc) · 1.48 KB
/
utils.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
#!/bin/bash
BASE="http://localhost:7071"
if [ $# -lt 1 ]; then
echo "Usage: $0 (produce|consume|start)"
exit 1
fi
# Handle start
if [ $1 == "start" ]; then
pushd terraform
if [ -z "$EVENTGRID_ENDPOINT" ]; then
export EVENTGRID_ENDPOINT=$(terraform output event_grid_endpoint | tr -d \")
fi
echo "EVENTGRID_ENDPOINT: $EVENTGRID_ENDPOINT"
if [ -z "$EVENTGRID_KEY" ]; then
export EVENTGRID_KEY=$(terraform output event_grid_key | tr -d \")
fi
echo "EVENTGRID_KEY: $EVENTGRID_KEY"
popd
pushd functions
source env/bin/activate
pip3 install -r requirements.txt >/dev/null
source .env
func host start
popd
exit 0
fi
# Handle produce and consume
if [ $# -ne 2 ]; then
echo "Usage: $0 (produce|consume) json-file"
exit 1
fi
if [[ "$1" != "produce" && "$1" != "consume" ]]; then
echo "Second parameter should be one of: produce, consume"
exit 1
fi
if [ ! -f "$2" ]; then
echo "File not found: $2"
exit 1
fi
# Checking if jq is installed
if ! command -v jq >/dev/null 2>&1; then
echo "jq is not installed. Please install jq to proceed."
exit 1
fi
jq empty "$2" >/dev/null 2>&1
if [ $? -ne 0 ]; then
echo "Invalid JSON file: $2"
exit 1
fi
file="$2"
function produce {
URL="$BASE/publish"
curl -X POST -H "Content-Type: application/json" -d "@$file" $URL
}
function consume {
URL="$BASE/runtime/webhooks/EventGrid?functionName=ShodanConsumer"
curl -X POST -H "Content-Type: application/json" -H "aeg-event-type: Notification" -d "@$file" $URL
}
$1