Files
versitygw/tests/rest_scripts/create_bucket.sh
2025-07-30 16:17:01 -03:00

73 lines
2.3 KiB
Bash
Executable File

#!/usr/bin/env bash
# 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.
source ./tests/rest_scripts/rest.sh
# Fields
# shellcheck disable=SC2153
bucket_name="$BUCKET_NAME"
acl="$ACL"
# shellcheck disable=SC2153
object_ownership="$OBJECT_OWNERSHIP"
# shellcheck disable=SC2153
grant_full_control="$GRANT_FULL_CONTROL"
# shellcheck disable=SC2153
grant_read="$GRANT_READ"
# shellcheck disable=SC2153
grant_read_acp="$GRANT_READ_ACP"
# shellcheck disable=SC2153
grant_write="$GRANT_WRITE"
# shellcheck disable=SC2153
grant_write_acp="$GRANT_WRITE_ACP"
current_date_time=$(date -u +"%Y%m%dT%H%M%SZ")
cr_data=("PUT" "/$bucket_name" "" "host:$host")
if [ "$acl" != "" ]; then
cr_data+=("x-amz-acl:$acl")
fi
cr_data+=("x-amz-content-sha256:UNSIGNED-PAYLOAD" "x-amz-date:$current_date_time")
if [ "$grant_full_control" != "" ]; then
cr_data+=("x-amz-grant-full-control:$grant_full_control")
fi
if [ "$grant_read" != "" ]; then
cr_data+=("x-amz-grant-read:$grant_read")
fi
if [ "$grant_read_acp" != "" ]; then
cr_data+=("x-amz-grant-read-acp:$grant_read_acp")
fi
if [ "$grant_write" != "" ]; then
cr_data+=("x-amz-grant-write:$grant_write")
fi
if [ "$grant_write_acp" != "" ]; then
cr_data+=("x-amz-grant-write-acp:$grant_write_acp")
fi
if [ "$object_ownership" != "" ]; then
cr_data+=("x-amz-object-ownership:$object_ownership")
fi
build_canonical_request "${cr_data[@]}"
# shellcheck disable=SC2119
create_canonical_hash_sts_and_signature
curl_command+=(curl -ks -w "%{http_code}" -X PUT "$AWS_ENDPOINT_URL/$bucket_name")
curl_command+=(-H "\"Authorization: AWS4-HMAC-SHA256 Credential=$aws_access_key_id/$year_month_day/$aws_region/s3/aws4_request,SignedHeaders=$param_list,Signature=$signature\"")
curl_command+=("${header_fields[@]}")
curl_command+=(-o "$OUTPUT_FILE")
# shellcheck disable=SC2154
eval "${curl_command[*]}" 2>&1