more changes
This commit is contained in:
@@ -99,14 +99,14 @@ if ! command -v curl &> /dev/null; then
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# Build curl options based on configuration
|
||||
CURL_OPTS=""
|
||||
# Build curl options as an array to avoid quote issues
|
||||
CURL_OPTS=()
|
||||
if [ -n "$CERT_FILE" ]; then
|
||||
if [ ! -f "$CERT_FILE" ]; then
|
||||
log_error "Certificate file not found: $CERT_FILE"
|
||||
exit 1
|
||||
fi
|
||||
CURL_OPTS="$CURL_OPTS --cert $CERT_FILE"
|
||||
CURL_OPTS+=("--cert" "$CERT_FILE")
|
||||
fi
|
||||
|
||||
if [ -n "$KEY_FILE" ]; then
|
||||
@@ -114,15 +114,15 @@ if [ -n "$KEY_FILE" ]; then
|
||||
log_error "Key file not found: $KEY_FILE"
|
||||
exit 1
|
||||
fi
|
||||
CURL_OPTS="$CURL_OPTS --key $KEY_FILE"
|
||||
CURL_OPTS+=("--key" "$KEY_FILE")
|
||||
fi
|
||||
|
||||
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
|
||||
|
||||
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
|
||||
|
||||
# Build CF configuration JSON
|
||||
@@ -153,7 +153,7 @@ log_info "Step 1/5: Initializing upload session..."
|
||||
# Debug mode output
|
||||
if [ "$DEBUG_MODE" = "true" ]; then
|
||||
echo "DEBUG: API_BASE = $API_BASE"
|
||||
echo "DEBUG: CURL_OPTS = $CURL_OPTS"
|
||||
echo "DEBUG: CURL_OPTS = ${CURL_OPTS[@]}"
|
||||
echo "DEBUG: Request JSON:"
|
||||
echo "$CF_CONFIG"
|
||||
fi
|
||||
@@ -162,17 +162,17 @@ fi
|
||||
TEMP_JSON=$(mktemp)
|
||||
echo "$CF_CONFIG" > "$TEMP_JSON"
|
||||
|
||||
# Build the curl command
|
||||
if [ -n "$CURL_OPTS" ]; then
|
||||
# Build the curl command using array expansion
|
||||
if [ ${#CURL_OPTS[@]} -gt 0 ]; 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" \
|
||||
$CURL_OPTS \
|
||||
"${CURL_OPTS[@]}" \
|
||||
-d @"$TEMP_JSON")
|
||||
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" \
|
||||
$CURL_OPTS \
|
||||
"${CURL_OPTS[@]}" \
|
||||
-d @"$TEMP_JSON")
|
||||
fi
|
||||
else
|
||||
@@ -250,14 +250,24 @@ upload_file_in_chunks() {
|
||||
for chunk_file in "$temp_dir"/chunk_*; do
|
||||
printf " Chunk %3d/%3d... " "$((chunk_index + 1))" "$total_chunks"
|
||||
|
||||
RESPONSE=$(eval curl -s -X POST "$API_BASE/upload/chunk" \
|
||||
$CURL_OPTS \
|
||||
-F "uploadSessionId=$SESSION_ID" \
|
||||
-F "fileType=$file_type" \
|
||||
-F "chunkIndex=$chunk_index" \
|
||||
-F "totalChunks=$total_chunks" \
|
||||
-F "fileName=$file_name" \
|
||||
-F "chunk=@$chunk_file")
|
||||
if [ ${#CURL_OPTS[@]} -gt 0 ]; then
|
||||
RESPONSE=$(curl -s -X POST "$API_BASE/upload/chunk" \
|
||||
"${CURL_OPTS[@]}" \
|
||||
-F "uploadSessionId=$SESSION_ID" \
|
||||
-F "fileType=$file_type" \
|
||||
-F "chunkIndex=$chunk_index" \
|
||||
-F "totalChunks=$total_chunks" \
|
||||
-F "fileName=$file_name" \
|
||||
-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)
|
||||
|
||||
@@ -296,8 +306,12 @@ upload_file_in_chunks "$MANIFEST_FILE" "manifest"
|
||||
#############################################################################
|
||||
log_info "Step 4/5: Starting async deployment..."
|
||||
|
||||
FINALIZE_RESPONSE=$(eval curl -s -X POST "$API_BASE/upload/finalize?uploadSessionId=$SESSION_ID&async=true" \
|
||||
$CURL_OPTS)
|
||||
if [ ${#CURL_OPTS[@]} -gt 0 ]; then
|
||||
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)
|
||||
|
||||
if [ "$STATUS" != "IN_PROGRESS" ]; then
|
||||
@@ -320,8 +334,12 @@ while [ $elapsed -lt $MAX_WAIT ]; do
|
||||
sleep $POLL_INTERVAL
|
||||
elapsed=$((elapsed + POLL_INTERVAL))
|
||||
|
||||
STATUS_RESPONSE=$(eval curl -s "$API_BASE/deployment/status/$SESSION_ID" \
|
||||
$CURL_OPTS 2>/dev/null)
|
||||
if [ ${#CURL_OPTS[@]} -gt 0 ]; then
|
||||
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
|
||||
log_warning "Failed to fetch status, retrying..."
|
||||
|
||||
Reference in New Issue
Block a user