2016-03-10 18:18:11 +01:00
|
|
|
#!/bin/sh
|
|
|
|
|
|
|
|
# http://concourse.ci/implementing-resources.html#resource-check
|
|
|
|
|
|
|
|
set -e
|
|
|
|
|
2016-03-22 22:29:42 +01:00
|
|
|
# parse incoming config data
|
|
|
|
payload=`cat`
|
|
|
|
bucket=$(echo "$payload" | jq -r '.source.bucket')
|
2016-10-04 16:33:07 +02:00
|
|
|
prefix="$(echo "$payload" | jq -r '.source.path // ""')"
|
2016-03-22 22:29:42 +01:00
|
|
|
|
|
|
|
# export for `aws` cli
|
2016-08-18 11:31:03 +02:00
|
|
|
AWS_ACCESS_KEY_ID=$(echo "$payload" | jq -r '.source.access_key_id')
|
|
|
|
AWS_SECRET_ACCESS_KEY=$(echo "$payload" | jq -r '.source.secret_access_key')
|
|
|
|
|
|
|
|
# Due to precedence rules, must be unset to support AWS IAM Roles.
|
|
|
|
if [ -n "$AWS_ACCESS_KEY_ID" ] && [ -n "$AWS_SECRET_ACCESS_KEY" ]; then
|
|
|
|
export AWS_ACCESS_KEY_ID=$AWS_ACCESS_KEY_ID
|
|
|
|
export AWS_SECRET_ACCESS_KEY=$AWS_SECRET_ACCESS_KEY
|
|
|
|
fi
|
2016-03-22 22:29:42 +01:00
|
|
|
|
|
|
|
# Consider the most recent LastModified timestamp as the most recent version.
|
2016-10-04 16:33:07 +02:00
|
|
|
timestamps=$(aws s3api list-objects --bucket $bucket --prefix "$prefix" --query 'Contents[].{LastModified: LastModified}')
|
2016-03-22 22:29:42 +01:00
|
|
|
recent="$(echo $timestamps | jq -r 'max_by(.LastModified)')"
|
|
|
|
echo "[$recent]"
|