Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(copyToS3): Upload to S3 only when indicated. #1134

Merged
merged 1 commit into from
May 12, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 7 additions & 16 deletions include/outputs_bucket
Original file line number Diff line number Diff line change
Expand Up @@ -13,23 +13,14 @@

if [[ $OUTPUT_BUCKET ]]; then
# output mode has to be set to other than text
if [[ "${MODES[@]}" =~ "html" ]] || [[ "${MODES[@]}" =~ "csv" ]] || [[ "${MODES[@]}" =~ "json" ]] || [[ "${MODES[@]}" =~ "json-asff" ]]; then
OUTPUT_BUCKET_WITHOUT_FOLDERS=$(echo $OUTPUT_BUCKET | awk -F'/' '{ print $1 }')
# OUTPUT_BUCKET_STATUS=$($AWSCLI s3api head-bucket --bucket "$OUTPUT_BUCKET" 2>&1 || true)
# if [[ -z $OUTPUT_BUCKET_STATUS ]]; then
# echo "$OPTRED ERROR!$OPTNORMAL wrong bucket name or not right permissions."
# exit 1
# else
# need to make sure last / is not set to avoid // in S3
if [[ $OUTPUT_BUCKET != *"/" ]]; then
OUTPUT_BUCKET="$OUTPUT_BUCKET"
else
OUTPUT_BUCKET=${OUTPUT_BUCKET::-1}
fi
# fi
else
echo "$OPTRED ERROR!$OPTNORMAL - Mode (-M) has to be set as well. Use -h for help."
if [[ "${MODES[*]}" =~ "text" ]]; then
echo "$OPTRED ERROR!$OPTNORMAL - Mode (-M) can't be text when using custom output bucket. Use -h for help."
exit 1
else
# need to make sure last / is not set to avoid // in S3
if [[ $OUTPUT_BUCKET == *"/" ]]; then
OUTPUT_BUCKET=${OUTPUT_BUCKET::-1}
fi
fi
fi

Expand Down
12 changes: 9 additions & 3 deletions prowler
Original file line number Diff line number Diff line change
Expand Up @@ -694,7 +694,9 @@ if [[ $GROUP_ID_READ ]];then
if [[ $OUTPUT_BUCKET_NOASSUME ]]; then
restoreInitialAWSCredentials
fi
copyToS3
if [[ $OUTPUT_BUCKET ]]; then
copyToS3
fi
exit $EXITCODE
else
textFail "Group ${GROUP_ID_READ} does not exist. Use a valid check group ID i.e.: group1, extras, forensics-ready, etc."
Expand Down Expand Up @@ -725,7 +727,9 @@ if [[ $CHECK_ID ]];then
if [[ $OUTPUT_BUCKET_NOASSUME ]]; then
restoreInitialAWSCredentials
fi
copyToS3
if [[ $OUTPUT_BUCKET ]]; then
copyToS3
fi
scoring
cleanTemp
exit $EXITCODE
Expand All @@ -742,6 +746,8 @@ cleanTemp
if [[ $OUTPUT_BUCKET_NOASSUME ]]; then
restoreInitialAWSCredentials
fi
copyToS3
if [[ $OUTPUT_BUCKET ]]; then
copyToS3
fi

exit $EXITCODE