Skip to content

Commit

Permalink
Merge pull request #698 from 0xdabbad00/tgrushka-region-filter
Browse files Browse the repository at this point in the history
Tgrushka region filter
  • Loading branch information
0xdabbad00 authored May 8, 2020
2 parents 81aa36e + c88cdd4 commit ceebed1
Showing 1 changed file with 20 additions and 0 deletions.
20 changes: 20 additions & 0 deletions commands/collect.py
Original file line number Diff line number Diff line change
Expand Up @@ -216,6 +216,13 @@ def collect(arguments):
else:
default_region = 'us-east-1'

regions_filter = None
if len(arguments.regions_filter) > 0:
regions_filter = arguments.regions_filter.lower().split(",")
# Force include of default region -- seems to be required
if default_region not in regions_filter:
regions_filter.append(default_region)

session_data = {"region_name": default_region}

if arguments.profile_name:
Expand Down Expand Up @@ -267,6 +274,11 @@ def collect(arguments):
print("* Getting region names", flush=True)
ec2 = session.client("ec2")
region_list = ec2.describe_regions()

if regions_filter is not None:
filtered_regions = [r for r in region_list["Regions"] if r["RegionName"] in regions_filter]
region_list["Regions"] = filtered_regions

with open("account-data/{}/describe-regions.json".format(account_dir), "w+") as f:
f.write(json.dumps(region_list, indent=4, sort_keys=True))

Expand Down Expand Up @@ -512,6 +524,14 @@ def run(arguments):
dest="max_attempts",
default=4
)
parser.add_argument(
"--regions",
help="Filter and query AWS only for the given regions (CSV)",
required=False,
type=str,
dest="regions_filter",
default=""
)

args = parser.parse_args(arguments)

Expand Down

0 comments on commit ceebed1

Please sign in to comment.