Skip to content

Instantly share code, notes, and snippets.

@rubyman
Last active September 19, 2025 00:01
Show Gist options
  • Select an option

  • Save rubyman/cef14548ac4fb71762ff7ba8ab8f15d8 to your computer and use it in GitHub Desktop.

Select an option

Save rubyman/cef14548ac4fb71762ff7ba8ab8f15d8 to your computer and use it in GitHub Desktop.
A shell script to upload a file to minio buckets - Original script: https://github.com/kneufeld/minio-put/
#!/bin/bash
# usage: ./minio-upload my-bucket my-file.zip minio-host.com access_key secret
bucket=$1
file=$2
minio_host=$3
access_key=$4
secret=$5
host=${S3_HOST:-$minio_host}
s3_key=${S3_KEY:-$access_key}
s3_secret=${S3_SECRET:-$secret}
base_file=`basename ${file}`
resource="/${bucket}/${base_file}"
content_type="application/octet-stream"
date=`date -R`
_signature="PUT\n\n${content_type}\n${date}\n${resource}"
signature=`echo -en ${_signature} | openssl sha1 -hmac ${s3_secret} -binary | base64`
# change to https
curl -v -X PUT -T "${file}" \
-H "Host: $host" \
-H "Date: ${date}" \
-H "Content-Type: ${content_type}" \
-H "Authorization: AWS ${s3_key}:${signature}" \
http://$host${resource}
@rubyman
Copy link
Author

rubyman commented Jan 30, 2021

Gitlab CI:

dynamic analysis:
stage: dast
image: owasp/zap2docker-stable:2.10.0
before_script:
- curl https://gist.githubusercontent.com/rubyman/cef14548ac4fb71762ff7ba8ab8f15d8/raw/eb83a9e8d0c7942b6a99b7142c74d8adcf0cb03c/minio-upload.sh > /zap/minio-upload.sh
- chmod +x /zap/minio-upload.sh
script:
- mkdir /zap/wrk
- python /zap/zap-baseline.py -r $FILE_NAME.html -t $DEPLOYMENT_ADDRESS || true
- cp /zap/wrk/$FILE_NAME.html .
- /zap/minio-upload.sh $MINIO_BUCKET_NAME $FILE_NAME.html $MINIO_ADDRESS $MINIO_ACCESS_KEY $MINIO_ACCESS_SECRET

@wwulfric
Copy link

wwulfric commented Oct 8, 2021

Hi, what does S3_HOST mean in host=${S3_HOST:-$minio_host}?

@konstantingoretzki
Copy link

@wwulfric

From https://www.gnu.org/savannah-checkouts/gnu/bash/manual/bash.html#Shell-Parameter-Expansion:

${parameter:-word}
    If parameter is unset or null, the expansion of word is substituted. Otherwise, the value of parameter is substituted.

For this example: host will be the value of the variable minio_host if S3_HOST is undefined (unset or null). Otherwise (will never be the case) host will be the value of S3_HOST. The host variable is needed for the network request.

However I am not 100% sure why this is used that way.
If it's used for a default value then shouldn't it be host=${minio_host:-S3_HOST} or host=${3:-S3_HOST}?
That way the value of minio_host is used if available and otherwise it's the static string S3_HOST.

@wwulfric
Copy link

@konstantingoretzki Got it, thanks. Perhaps the author preferred env param rather than command line one😂

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment