-
Notifications
You must be signed in to change notification settings - Fork 10
105 lines (84 loc) · 3.21 KB
/
ksql.yml
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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
name: ksql
on:
workflow_dispatch:
jobs:
build:
if: github.repository_owner == 'Informatievlaanderen'
name: Deploy ksql statements
environment: stg
runs-on: ubuntu-latest
steps:
- name: Checkout Code
uses: actions/checkout@v4
- name: Execute ksql statements
shell: bash
run: |
shopt -s nocasematch
function process_file() {
echo Start execution of $1
contents=$(<$1)
contents=$(sed 's|"|\\\"|g' <<< $contents) # escape double quotes
contents=$(sed ':a; N; $!ba; s/\n/ /g' <<< $contents) # single line
#echo $contents
endpoint=''
endpoint=$2
if [[ ! $endpoint == https* ]]; then
endpoint="https$endpoint"
fi
#echo Endpoint: "$endpoint/ksql" | sed 's/./& /g'
curl --silent --user ${CONFLUENT_API_KEY}:${CONFLUENT_API_SECRET} -w "\n%{http_code}\n" --location "$endpoint/ksql" \
--header 'Accept: application/vnd.ksql.v1+json' \
--header 'Content-Type: application/json' \
--data "{ \"ksql\": \" $contents \", \"streamsProperties\": { \"ksql.streams.auto.offset.reset\": \"earliest\" } }"
echo End execution of $1
}
function lookup_secret() {
secret=''
secret_value=''
if [[ $1 =~ 'INTEGRATION_0' ]]
then
secret=$ENDPOINT_INTEGRATION_0
elif [[ $1 =~ 'GEOLOCATION_0' ]]
then
secret=$ENDPOINT_GEOLOCATION_0
elif [[ $1 =~ 'GRB_0' ]]
then
secret=ENDPOINT_GRB_0
fi
eval "secret_value=\$$secret"
}
function process_folder() {
echo Processing folder $1
# look up secret
lookup_secret $1
# execute remembered files with secret
for REMEMBERED_FILE in $remembered_files ; do
process_file $REMEMBERED_FILE $secret_value
done
pushd $1 > /dev/null
for FILE in *.ksql; do
process_file $FILE $secret_value
done
popd > /dev/null
}
pushd .ksql > /dev/null
#list files
remembered_files=()
for FILE in *.ksql; do
remembered_files+=$FILE
done
#list folders, skip CONNECTOR_ folder
for FOLDER in */ ; do
[[ $FOLDER =~ 'CONNECTORS' ]] && continue
if [[ $FOLDER =~ 'INTEGRATION_0' || $FOLDER =~ 'GEOLOCATION_0' || $FOLDER =~ 'GRB_0' ]]
then
process_folder $FOLDER
fi
done
popd > /dev/null
env:
CONFLUENT_API_KEY: ${{ secrets.VBR_CONFLUENT_API_KEY_STG }}
CONFLUENT_API_SECRET: ${{ secrets.VBR_CONFLUENT_API_SECRET_STG }}
ENDPOINT_INTEGRATION_0: ${{ secrets.VBR_KSQLDB_CLUSTER_ENDPOINT_INTEGRATION_0_STG }}
ENDPOINT_GEOLOCATION_0: ${{ secrets.VBR_KSQLDB_CLUSTER_ENDPOINT_GEOLOCATION_0_STG }}
ENDPOINT_GRB_0: ${{ secrets.VBR_KSQLDB_CLUSTER_ENDPOINT_GRB_0_STG }}