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

scripts/maintenance: Support ~/.aws configs for region #75

Merged
merged 1 commit into from
Jul 27, 2018
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
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