Skip to content

Commit 1018438

Browse files
authored
refs sparkfabrik-innovation-team/board#715: add S3 ACL management (#16)
1 parent c2b7fc2 commit 1018438

File tree

4 files changed

+20
-6
lines changed

4 files changed

+20
-6
lines changed

app/commands/bucket/main.sh

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ export FILE_SRC=${FILE_SRC:-""}
1414
export BUCKET_DST_ENDPOINT=${BUCKET_DST_ENDPOINT:-}
1515
export BUCKET_DST=${BUCKET_DST:-}
1616
export FILE_DST=${FILE_DST:-""}
17+
export ACL=${ACL:-}
1718
export RCLONE_ADD_PARAMS=${RCLONE_ADD_PARAMS:-}
1819

1920
export TIMEOUT_BUCKET_SRC=${TIMEOUT_BUCKET_SRC:-10}
@@ -35,6 +36,7 @@ OPTIONS
3536
--bucket-dst-endpoint Defines the destination bucket endpoint
3637
--bucket-dst Defines the destination bucket
3738
--file-dst Defines the destination file in the bucket
39+
--acl Difines the ACL used to create the copied objects in the destination
3840
--rclone-add-params Defines the additional parameters to be passed to rclone command
3941
--timeout-bucket-src Defines the maximum waiting time for source bucket set up (default ${TIMEOUT_BUCKET_SRC}s)
4042
--timeout-bucket-dst Defines the maximum waiting time for destination bucket set up (default ${TIMEOUT_BUCKET_DST}s)
@@ -56,6 +58,7 @@ EOM
5658
printf "%-${PAD}s %s\n" "BUCKET_DST_ENDPOINT" "${BUCKET_DST_ENDPOINT}"
5759
printf "%-${PAD}s %s\n" "BUCKET_DST" "${BUCKET_DST}"
5860
printf "%-${PAD}s %s\n" "FILE_DST" "${FILE_DST}"
61+
printf "%-${PAD}s %s\n" "ACL" "${ACL}"
5962
printf "%-${PAD}s %s\n" "RCLONE_ADD_PARAMS" "${RCLONE_ADD_PARAMS}"
6063
printf "%-${PAD}s %s\n" "TIMEOUT_BUCKET_SRC" "${TIMEOUT_BUCKET_SRC}"
6164
printf "%-${PAD}s %s\n" "TIMEOUT_BUCKET_DST" "${TIMEOUT_BUCKET_DST}"
@@ -82,6 +85,7 @@ while [ -n "${1:-}" ]; do
8285
--bucket-dst-endpoint) BUCKET_DST_ENDPOINT="${2}"; shift 2 ;;
8386
--bucket-dst) BUCKET_DST="${2}"; shift 2 ;;
8487
--file-dst) FILE_DST="${2}"; shift 2 ;;
88+
--acl) ACL="${2}"; shift 2 ;;
8589
--rclone-add-params) RCLONE_ADD_PARAMS="${2}"; shift 2 ;;
8690
--timeout-bucket-src) TIMEOUT_BUCKET_SRC="${2}"; shift 2 ;;
8791
--timeout-bucket-dst) TIMEOUT_BUCKET_DST="${2}"; shift 2 ;;

app/commands/bucket/subcommands/copy-bucket.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ elif [ -z "${FILE_SRC}" ]; then
4444
elif [ -z "${FILE_DST}" ]; then
4545
echo "$(format_string "Full bucket copy:" "bold") ${BUCKET_SRC}/${FILE_SRC} => ${BUCKET_DST}"
4646
fi
47+
echo "$(format_string "ACL:" "bold") ${ACL}"
4748

4849
if [ "${PROVIDER_LOWER}" = "aws" ]; then
4950
echo "rclone_aws sync :s3://${BUCKET_SRC}/${FILE_SRC} :s3://${BUCKET_DST}/${FILE_DST}"

app/functions

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,31 +32,40 @@ format_string() {
3232
fi
3333
}
3434

35+
S3_ACL=""
36+
if [ -n "${ACL}" ]; then
37+
S3_ACL="--s3-acl ${ACL}"
38+
fi
39+
3540
rclone_aws() {
41+
echo "rclone --s3-region="${AWS_DEFAULT_REGION}" --s3-location-constraint="${AWS_DEFAULT_REGION}" --s3-env-auth ${S3_ACL} ${RCLONE_ADD_PARAMS} $@"
3642
rclone \
3743
--s3-region="${AWS_DEFAULT_REGION}" \
3844
--s3-location-constraint="${AWS_DEFAULT_REGION}" \
3945
--s3-env-auth \
40-
${RCLONE_ADD_PARAMS} $@
46+
${S3_ACL} ${RCLONE_ADD_PARAMS} $@
4147
}
4248

4349
rclone_gcs() {
50+
echo "rclone ${RCLONE_ADD_PARAMS} $@"
4451
rclone \
4552
${RCLONE_ADD_PARAMS} $@
4653
}
4754

4855
rclone_minio() {
56+
echo "rclone --s3-provider=Minio --s3-endpoint=${BUCKET_ENDPOINT} --s3-env-auth ${S3_ACL} ${RCLONE_ADD_PARAMS} $@"
4957
rclone \
5058
--s3-provider=Minio \
5159
--s3-endpoint=${BUCKET_ENDPOINT} \
5260
--s3-env-auth \
53-
${RCLONE_ADD_PARAMS} $@
61+
${S3_ACL} ${RCLONE_ADD_PARAMS} $@
5462
}
5563

5664
rclone_minio_multi() {
65+
echo "rclone --config=/tmp/rclone.conf ${S3_ACL} ${RCLONE_ADD_PARAMS} $@"
5766
envsubst < ${BASE}/rclone.conf > /tmp/rclone.conf
5867
rclone --config=/tmp/rclone.conf \
59-
${RCLONE_ADD_PARAMS} $@
68+
${S3_ACL} ${RCLONE_ADD_PARAMS} $@
6069
}
6170

6271
remove_http_proto() {

tests/functions

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ copyfiles() {
8383
FILE_DST="${2}"
8484

8585
docker-compose -f "${COMPOSE_FILE}" run --rm ops-utils \
86-
bucket copy-bucket --provider minio \
86+
bucket copy-bucket --provider minio --acl public-read \
8787
--bucket-src-endpoint "http://minio:9000" --bucket-src seeds --file-src "${FILE_SRC}" \
8888
--bucket-dst-endpoint "http://minio-dst:9000" --bucket-dst dstbucket --file-dst "${FILE_DST}"
8989
}
@@ -97,7 +97,7 @@ copytobucket() {
9797
FILE_DST="${1}"
9898

9999
docker-compose -f "${COMPOSE_FILE}" run --rm ops-utils \
100-
bucket copy-bucket --provider minio \
100+
bucket copy-bucket --provider minio --acl public-read \
101101
--bucket-src-endpoint "http://minio:9000" --bucket-src seeds \
102102
--bucket-dst-endpoint "http://minio-dst:9000" --bucket-dst dstbucket --file-dst "${FILE_DST}"
103103
}
@@ -111,7 +111,7 @@ copyfrombucket() {
111111
FILE_SRC="${1}"
112112

113113
docker-compose -f "${COMPOSE_FILE}" run --rm ops-utils \
114-
bucket copy-bucket --provider minio \
114+
bucket copy-bucket --provider minio --acl public-read \
115115
--bucket-src-endpoint "http://minio:9000" --bucket-src seeds --file-src "${FILE_SRC}" \
116116
--bucket-dst-endpoint "http://minio-dst:9000" --bucket-dst dstbucket
117117
}

0 commit comments

Comments
 (0)