Skip to content

Commit db9dd5b

Browse files
curl command as array of arguments
1 parent ce5f193 commit db9dd5b

File tree

1 file changed

+17
-14
lines changed

1 file changed

+17
-14
lines changed

resources/ingest_demo_data.sh

Lines changed: 17 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -37,40 +37,43 @@ curl_with_retry() {
3737
local max_time=$((10 + (retry_count * 10)))
3838
local connect_timeout=5
3939

40-
local curl_cmd="curl -s -w \"\n%{http_code}\" --max-time $max_time --connect-timeout $connect_timeout"
41-
42-
# Add headers
43-
curl_cmd+=" -H \"Content-Type: $content_type\""
44-
curl_cmd+=" -H \"$AUTH_HEADER\""
40+
local curl_args=(
41+
-s
42+
-w '\n%{http_code}'
43+
--max-time "$max_time"
44+
--connect-timeout "$connect_timeout"
45+
-H "Content-Type: $content_type"
46+
-H "$AUTH_HEADER"
47+
)
4548

4649
# Add stream header for ingestion requests
4750
if [[ "$url" == *"/ingest"* ]]; then
48-
curl_cmd+=" -H \"X-P-STREAM: $P_STREAM\""
51+
curl_args+=(-H "X-P-STREAM: $P_STREAM")
4952
fi
5053

5154
# Add method and data
5255
if [[ "$method" == "POST" ]]; then
53-
curl_cmd+=" -X POST"
56+
curl_args+=(-X POST)
5457
if [[ -n "$temp_file" ]]; then
55-
curl_cmd+=" --data-binary \"@$temp_file\""
58+
curl_args+=(--data-binary "@$temp_file")
5659
elif [[ -n "$data" ]]; then
57-
curl_cmd+=" -d \"$data\""
60+
curl_args+=(-d "$data")
5861
fi
5962
elif [[ "$method" == "PUT" ]]; then
60-
curl_cmd+=" -X PUT"
63+
curl_args+=(-X PUT)
6164
if [[ -n "$temp_file" ]]; then
62-
curl_cmd+=" --data-binary \"@$temp_file\""
65+
curl_args+=(--data-binary "@$temp_file")
6366
elif [[ -n "$data" ]]; then
64-
curl_cmd+=" -d \"$data\""
67+
curl_args+=(-d "$data")
6568
fi
6669
fi
6770

6871
# Add URL
69-
curl_cmd+=" \"$url\""
72+
curl_args+=("$url")
7073

7174
# Execute curl
7275
local response
73-
response=$(eval "$curl_cmd" 2>&1)
76+
response=$(curl "${curl_args[@]}" 2>&1)
7477
local curl_exit_code=$?
7578

7679
# Check curl exit code

0 commit comments

Comments
 (0)