Skip to content

Commit 82d23cf

Browse files
refactor demo script
1 parent 1ad8d0e commit 82d23cf

File tree

1 file changed

+4
-3
lines changed

1 file changed

+4
-3
lines changed

resources/ingest_demo_data.sh

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ curl_with_retry() {
2222
local data_file="$6"
2323
local retry_count=0
2424

25+
local temp_file=""
2526
# Create temp file if data is provided (either as string or file)
2627
if [[ -n "$data_file" ]]; then
2728
temp_file="$data_file"
@@ -88,7 +89,7 @@ curl_with_retry() {
8889
rm -f "$temp_file"
8990
fi
9091

91-
if [[ "$status_code" == "200" || "$status_code" == "201" ]]; then
92+
if [[ "$status_code" =~ ^2[0-9][0-9]$ ]]; then
9293
echo "$response_body"
9394
return 0
9495
else
@@ -380,7 +381,7 @@ EOF
380381

381382
if [[ $curl_exit_code -eq 0 && -n "$response" ]]; then
382383
# Extract target ID from response
383-
target_id=$(echo "$response" | grep -o '"id":"[^"]*"' | cut -d'"' -f4)
384+
target_id=$(echo "$response" | jq -r '.id // empty')
384385
if [[ -n "$target_id" ]]; then
385386
echo "Target created successfully with ID: $target_id" >&2
386387
echo "$target_id"
@@ -486,7 +487,7 @@ EOF
486487

487488
if [[ $curl_exit_code -eq 0 && -n "$response" ]]; then
488489
# Extract dashboard ID from response
489-
dashboard_id=$(echo "$response" | grep -o '"dashboardId":"[^"]*"' | cut -d'"' -f4)
490+
dashboard_id=$(echo "$response" | jq -r '.dashboardId // empty')
490491
if [[ -n "$dashboard_id" ]]; then
491492
echo "Dashboard created successfully with ID: $dashboard_id" >&2
492493
echo "$dashboard_id"

0 commit comments

Comments
 (0)