more changes

This commit is contained in:
pratik
2025-10-22 12:06:03 -05:00
parent ab07cd6d92
commit c3554e84ab

View File

@@ -99,14 +99,14 @@ if ! command -v curl &> /dev/null; then
exit 1 exit 1
fi fi
# Build curl options based on configuration # Build curl options as an array to avoid quote issues
CURL_OPTS="" CURL_OPTS=()
if [ -n "$CERT_FILE" ]; then if [ -n "$CERT_FILE" ]; then
if [ ! -f "$CERT_FILE" ]; then if [ ! -f "$CERT_FILE" ]; then
log_error "Certificate file not found: $CERT_FILE" log_error "Certificate file not found: $CERT_FILE"
exit 1 exit 1
fi fi
CURL_OPTS="$CURL_OPTS --cert $CERT_FILE" CURL_OPTS+=("--cert" "$CERT_FILE")
fi fi
if [ -n "$KEY_FILE" ]; then if [ -n "$KEY_FILE" ]; then
@@ -114,15 +114,15 @@ if [ -n "$KEY_FILE" ]; then
log_error "Key file not found: $KEY_FILE" log_error "Key file not found: $KEY_FILE"
exit 1 exit 1
fi fi
CURL_OPTS="$CURL_OPTS --key $KEY_FILE" CURL_OPTS+=("--key" "$KEY_FILE")
fi fi
if [ -n "$X_FORWARDED_FOR" ]; then if [ -n "$X_FORWARDED_FOR" ]; then
CURL_OPTS="$CURL_OPTS -H \"X-Forwarded-For: $X_FORWARDED_FOR\"" CURL_OPTS+=("-H" "X-Forwarded-For: $X_FORWARDED_FOR")
fi fi
if [ -n "$MY_APIM_KEY" ]; then if [ -n "$MY_APIM_KEY" ]; then
CURL_OPTS="$CURL_OPTS -H \"My-APIM-KEY: $MY_APIM_KEY\"" CURL_OPTS+=("-H" "My-APIM-KEY: $MY_APIM_KEY")
fi fi
# Build CF configuration JSON # Build CF configuration JSON
@@ -153,7 +153,7 @@ log_info "Step 1/5: Initializing upload session..."
# Debug mode output # Debug mode output
if [ "$DEBUG_MODE" = "true" ]; then if [ "$DEBUG_MODE" = "true" ]; then
echo "DEBUG: API_BASE = $API_BASE" echo "DEBUG: API_BASE = $API_BASE"
echo "DEBUG: CURL_OPTS = $CURL_OPTS" echo "DEBUG: CURL_OPTS = ${CURL_OPTS[@]}"
echo "DEBUG: Request JSON:" echo "DEBUG: Request JSON:"
echo "$CF_CONFIG" echo "$CF_CONFIG"
fi fi
@@ -162,17 +162,17 @@ fi
TEMP_JSON=$(mktemp) TEMP_JSON=$(mktemp)
echo "$CF_CONFIG" > "$TEMP_JSON" echo "$CF_CONFIG" > "$TEMP_JSON"
# Build the curl command # Build the curl command using array expansion
if [ -n "$CURL_OPTS" ]; then if [ ${#CURL_OPTS[@]} -gt 0 ]; then
if [ "$DEBUG_MODE" = "true" ]; then if [ "$DEBUG_MODE" = "true" ]; then
INIT_RESPONSE=$(eval curl -v -X POST "$API_BASE/upload/init" \ INIT_RESPONSE=$(curl -v -X POST "$API_BASE/upload/init" \
-H "Content-Type: application/json" \ -H "Content-Type: application/json" \
$CURL_OPTS \ "${CURL_OPTS[@]}" \
-d @"$TEMP_JSON") -d @"$TEMP_JSON")
else else
INIT_RESPONSE=$(eval curl -s -X POST "$API_BASE/upload/init" \ INIT_RESPONSE=$(curl -s -X POST "$API_BASE/upload/init" \
-H "Content-Type: application/json" \ -H "Content-Type: application/json" \
$CURL_OPTS \ "${CURL_OPTS[@]}" \
-d @"$TEMP_JSON") -d @"$TEMP_JSON")
fi fi
else else
@@ -250,14 +250,24 @@ upload_file_in_chunks() {
for chunk_file in "$temp_dir"/chunk_*; do for chunk_file in "$temp_dir"/chunk_*; do
printf " Chunk %3d/%3d... " "$((chunk_index + 1))" "$total_chunks" printf " Chunk %3d/%3d... " "$((chunk_index + 1))" "$total_chunks"
RESPONSE=$(eval curl -s -X POST "$API_BASE/upload/chunk" \ if [ ${#CURL_OPTS[@]} -gt 0 ]; then
$CURL_OPTS \ RESPONSE=$(curl -s -X POST "$API_BASE/upload/chunk" \
"${CURL_OPTS[@]}" \
-F "uploadSessionId=$SESSION_ID" \ -F "uploadSessionId=$SESSION_ID" \
-F "fileType=$file_type" \ -F "fileType=$file_type" \
-F "chunkIndex=$chunk_index" \ -F "chunkIndex=$chunk_index" \
-F "totalChunks=$total_chunks" \ -F "totalChunks=$total_chunks" \
-F "fileName=$file_name" \ -F "fileName=$file_name" \
-F "chunk=@$chunk_file") -F "chunk=@$chunk_file")
else
RESPONSE=$(curl -s -X POST "$API_BASE/upload/chunk" \
-F "uploadSessionId=$SESSION_ID" \
-F "fileType=$file_type" \
-F "chunkIndex=$chunk_index" \
-F "totalChunks=$total_chunks" \
-F "fileName=$file_name" \
-F "chunk=@$chunk_file")
fi
SUCCESS=$(echo "$RESPONSE" | grep -o '"success":[^,}]*' | cut -d':' -f2) SUCCESS=$(echo "$RESPONSE" | grep -o '"success":[^,}]*' | cut -d':' -f2)
@@ -296,8 +306,12 @@ upload_file_in_chunks "$MANIFEST_FILE" "manifest"
############################################################################# #############################################################################
log_info "Step 4/5: Starting async deployment..." log_info "Step 4/5: Starting async deployment..."
FINALIZE_RESPONSE=$(eval curl -s -X POST "$API_BASE/upload/finalize?uploadSessionId=$SESSION_ID&async=true" \ if [ ${#CURL_OPTS[@]} -gt 0 ]; then
$CURL_OPTS) FINALIZE_RESPONSE=$(curl -s -X POST "$API_BASE/upload/finalize?uploadSessionId=$SESSION_ID&async=true" \
"${CURL_OPTS[@]}")
else
FINALIZE_RESPONSE=$(curl -s -X POST "$API_BASE/upload/finalize?uploadSessionId=$SESSION_ID&async=true")
fi
STATUS=$(echo "$FINALIZE_RESPONSE" | grep -o '"status":"[^"]*' | cut -d'"' -f4) STATUS=$(echo "$FINALIZE_RESPONSE" | grep -o '"status":"[^"]*' | cut -d'"' -f4)
if [ "$STATUS" != "IN_PROGRESS" ]; then if [ "$STATUS" != "IN_PROGRESS" ]; then
@@ -320,8 +334,12 @@ while [ $elapsed -lt $MAX_WAIT ]; do
sleep $POLL_INTERVAL sleep $POLL_INTERVAL
elapsed=$((elapsed + POLL_INTERVAL)) elapsed=$((elapsed + POLL_INTERVAL))
STATUS_RESPONSE=$(eval curl -s "$API_BASE/deployment/status/$SESSION_ID" \ if [ ${#CURL_OPTS[@]} -gt 0 ]; then
$CURL_OPTS 2>/dev/null) STATUS_RESPONSE=$(curl -s "$API_BASE/deployment/status/$SESSION_ID" \
"${CURL_OPTS[@]}" 2>/dev/null)
else
STATUS_RESPONSE=$(curl -s "$API_BASE/deployment/status/$SESSION_ID" 2>/dev/null)
fi
if [ $? -ne 0 ]; then if [ $? -ne 0 ]; then
log_warning "Failed to fetch status, retrying..." log_warning "Failed to fetch status, retrying..."