mirror of
https://github.com/versity/versitygw.git
synced 2026-09-23 08:24:17 +00:00
115 lines
3.7 KiB
Bash
115 lines
3.7 KiB
Bash
#!/usr/bin/env bats
|
|
|
|
# Copyright 2024 Versity Software
|
|
# This file is licensed under the Apache License, Version 2.0
|
|
# (the "License"); you may not use this file except in compliance
|
|
# with the License. You may obtain a copy of the License at
|
|
#
|
|
# http:#www.apache.org/licenses/LICENSE-2.0
|
|
#
|
|
# Unless required by applicable law or agreed to in writing,
|
|
# software distributed under the License is distributed on an
|
|
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
|
# KIND, either express or implied. See the License for the
|
|
# specific language governing permissions and limitations
|
|
# under the License.
|
|
|
|
multipart_upload_rest_before_completion() {
|
|
if ! check_param_count_v2 "bucket, key, file, part count" 4 $#; then
|
|
return 1
|
|
fi
|
|
|
|
local response
|
|
if ! response=$(create_multipart_upload_rest "$1" "$2" "" "parse_upload_id" 2>&1); then
|
|
log 2 "error creating multipart upload: $response"
|
|
return 1
|
|
fi
|
|
upload_id="$response"
|
|
|
|
if ! response=$(upload_parts_rest_before_completion "$1" "$2" "$3" "$upload_id" "$4" 2>&1); then
|
|
log 2 "error uploading parts before completion: $response"
|
|
return 1
|
|
fi
|
|
parts_payload="$response"
|
|
|
|
echo "$upload_id $parts_payload"
|
|
return 0
|
|
}
|
|
|
|
upload_parts_rest_before_completion() {
|
|
if ! check_param_count_v2 "bucket, key, file, upload ID, part count" 5 $#; then
|
|
return 1
|
|
fi
|
|
if ! segments=$(split_file "$3" "$5" 2>&1); then
|
|
log 2 "error splitting file: $segments"
|
|
return 1
|
|
fi
|
|
read -r -a segment_array <<< "$segments"
|
|
|
|
parts_payload=""
|
|
for ((part=0;part<"$5";part++)); do
|
|
part_number=$((part+1))
|
|
if ! etag=$(upload_part_rest "$1" "$2" "$4" "$part_number" "${segment_array[$part]}" 2>&1); then
|
|
log 2 "error uploading part $part: $etag"
|
|
return 1
|
|
fi
|
|
parts_payload+="<Part><ETag>$etag</ETag><PartNumber>$part_number</PartNumber></Part>"
|
|
done
|
|
echo "$parts_payload"
|
|
return 0
|
|
}
|
|
|
|
upload_parts_rest_with_checksum_before_completion() {
|
|
if ! check_param_count_v2 "bucket, key, file, upload ID, part count, algorithm" 6 $#; then
|
|
return 1
|
|
fi
|
|
log 5 "file: $3, part count: $5"
|
|
log 5 "file info: $(ls -l "$3")"
|
|
if ! segments=$(split_file "$3" "$5" 2>&1); then
|
|
log 2 "error splitting file"
|
|
return 1
|
|
fi
|
|
read -r -a segment_array <<< "$segments"
|
|
|
|
parts_payload=""
|
|
checksums=()
|
|
for ((part=0;part<"$5";part++)); do
|
|
part_number=$((part+1))
|
|
if ! upload_part_rest_with_checksum "$1" "$2" "$4" "$part_number" "${segment_array[$part]}" "$6"; then
|
|
log 2 "error uploading part $part"
|
|
return 1
|
|
fi
|
|
checksums+=("$checksum")
|
|
uppercase_checksum_algorithm=$(echo -n "$6" | tr '[:lower:]' '[:upper:]')
|
|
parts_payload+="<Part><ETag>$etag</ETag><Checksum${uppercase_checksum_algorithm}>${checksum}</Checksum${uppercase_checksum_algorithm}><PartNumber>$part_number</PartNumber></Part>"
|
|
log 5 "parts payload: $parts_payload"
|
|
done
|
|
log 5 "CHECKSUMS: ${checksums[*]}"
|
|
echo "${checksums[*]}"
|
|
echo "$parts_payload"
|
|
return 0
|
|
}
|
|
|
|
perform_full_multipart_upload_with_checksum_before_completion() {
|
|
if ! check_param_count_v2 "bucket, filename, checksum type, algorithm" 4 $#; then
|
|
return 1
|
|
fi
|
|
lowercase_checksum_algorithm=$(echo -n "$4" | tr '[:upper:]' '[:lower:]')
|
|
|
|
local response
|
|
if ! response=$(create_multipart_upload_rest "$1" "$2" "CHECKSUM_TYPE=$3 CHECKSUM_ALGORITHM=$4" "parse_upload_id" 2>&1); then
|
|
log 2 "error creating multipart upload: $response"
|
|
return 1
|
|
fi
|
|
upload_id="$response"
|
|
|
|
if ! response=$(upload_parts_rest_with_checksum_before_completion "$1" "$2" "$TEST_FILE_FOLDER/$2" "$upload_id" 2 "$lowercase_checksum_algorithm" 2>&1); then
|
|
log 2 "error uploading parts: $response"
|
|
return 1
|
|
fi
|
|
echo "$lowercase_checksum_algorithm"
|
|
echo "$upload_id"
|
|
echo "$response"
|
|
return 0
|
|
}
|