Skip to content

Commit

Permalink
Merge pull request #75 from wking/script-region-config
Browse files Browse the repository at this point in the history
scripts/maintenance: Support ~/.aws configs for region
  • Loading branch information
openshift-merge-robot authored Jul 27, 2018
2 parents 8074825 + 17171f7 commit d310cf5
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 18 deletions.
26 changes: 17 additions & 9 deletions scripts/maintenance/clean-aws.sh
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,10 @@ Options:
hash of a grafiti image hosted in quay.io.
--aws-region The AWS region you wish to query for taggable resources. This
flag is optional if AWS_REGION is set. AWS_REGION overrides
values passed in by this flag.
flag is optional if AWS_REGION is set. You can also set a
default region for the default profile in your ~/.aws
configuration files, although for this you must have the 'aws'
command installed).
--config-file A grafiti configuration file. See an example at
https://github.com/coreos/grafiti/blob/master/config.toml.
Expand Down Expand Up @@ -90,20 +92,26 @@ if ! command -V docker >/dev/null || ! command -V jq >/dev/null; then
exit 1
fi

if [ -n "$AWS_REGION" ]; then
region="${AWS_REGION:-}"
if [ -z "$region" ]; then
if [ -n "$AWS_REGION" ]; then
region="${AWS_REGION:-}"
elif ! command -V aws >/dev/null; then
echo "Without the 'aws' command, you must set either --aws-region or \$AWS_REGION" >&2
exit 1
else
region="$(aws configure get region)"
if [ -z "$region" ]; then
echo "Must provide an AWS region, set the AWS_REGION, or set a region in your ~/.aws/config" >&2
exit 1
fi
fi
fi

if [ -z "$version" ]; then
echo "Grafiti image version required." >&2
exit 1
fi

if [ -z "$region" ]; then
echo "Must provide an AWS region, set the AWS_REGION, or set a region in your ~/.aws/config" >&2
exit 1
fi

if [ -n "$tag_file" ] && [ -n "$date_override" ]; then
echo "Cannot use both --tag-file and --date-override flags simultaneously." >&2
exit 1
Expand Down
26 changes: 17 additions & 9 deletions scripts/maintenance/tag-aws.sh
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,10 @@ Options:
hash of a grafiti image hosted in quay.io.
--aws-region The AWS region you wish to query for taggable resources. This
flag is optional if AWS_REGION is set. AWS_REGION overrides
values passed in by this flag.
flag is optional if AWS_REGION is set. You can also set a
default region for the default profile in your ~/.aws
configuration files, although for this you must have the 'aws'
command installed).
--config-file A grafiti configuration file. See an example at
https://github.com/coreos/grafiti/blob/master/config.toml.
Expand Down Expand Up @@ -104,8 +106,19 @@ if ! command -V docker >/dev/null; then
exit 1
fi

if [ -n "$AWS_REGION" ]; then
region="${AWS_REGION:-}"
if [ -z "$region" ]; then
if [ -n "$AWS_REGION" ]; then
region="${AWS_REGION:-}"
elif ! command -V aws >/dev/null; then
echo "Without the 'aws' command, you must set either --aws-region or \$AWS_REGION" >&2
exit 1
else
region="$(aws configure get region)"
if [ -z "$region" ]; then
echo "Must provide an AWS region, set the AWS_REGION, or set a region in your ~/.aws/config" >&2
exit 1
fi
fi
fi

if [ -z "$version" ]; then
Expand All @@ -118,11 +131,6 @@ if [ -z "$start_hour" ] || [ -z "$end_hour" ]; then
exit 1
fi

if [ -z "$region" ]; then
echo "Must provide an AWS region, set the AWS_REGION, or set a region in your ~/.aws/config" >&2
exit 1
fi

set -e

# Tag all resources present in CloudTrail over the specified time period with the
Expand Down

0 comments on commit d310cf5

Please sign in to comment.