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

Fixes #23 #25

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open

Fixes #23 #25

wants to merge 5 commits into from

Conversation

rk295
Copy link
Contributor

@rk295 rk295 commented Dec 13, 2018

I also found having the VpcId in the output useful, so I took the
liberty to add it.

I appreciate this might be a breaking change if somebody is depending on
the output of this tool.

rk295 and others added 2 commits December 13, 2018 12:24
I also found having the VpcId in the output useful, so I took the
liberty to add it.

I appreciate this might be a breaking change if somebody is depending on
the output of this tool.
Copy link
Member

@lra lra left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I got an error on the csv output:

Traceback (most recent call last):
  File "/Users/analogue/.pyenv/versions/3.7.0/bin/ec2-security-groups-dumper", line 11, in <module>
    load_entry_point('ec2-security-groups-dumper', 'console_scripts', 'ec2-security-groups-dumper')()
  File "/Users/analogue/src/ec2-security-groups-dumper/ec2_security_groups_dumper/main.py", line 390, in main
    print(firewall.csv)
  File "/Users/analogue/src/ec2-security-groups-dumper/ec2_security_groups_dumper/main.py", line 281, in csv
    for fr in self.rules:
  File "/Users/analogue/src/ec2-security-groups-dumper/ec2_security_groups_dumper/main.py", line 224, in rules
    main_row['vpc_id'])
  File "/Users/analogue/src/ec2-security-groups-dumper/ec2_security_groups_dumper/main.py", line 66, in __init__
    assert isinstance(vpc_id, str)
AssertionError

@rk295
Copy link
Contributor Author

rk295 commented Dec 13, 2018

I've pushed a minor tweak, the JSON output was incorrect.

I'm a bit confused about that AssertionError, what is the AWS API returning for VpcId for you? I've tried it against a bunch of AWS accounts I have and all seem fine.

The only thing I can think of is maybe you have some Security Groups for the pre VPC era and the VpcId field is being returned as null or something?

@lra
Copy link
Member

lra commented Dec 14, 2018

Yes, I have some old classic stuff around, and in this case, the vpc_id is a NoneType.

@rk295
Copy link
Contributor Author

rk295 commented Dec 14, 2018

I'm not sure how you'd prefer this fixed, I've pushed a commit which works around the lack of the VpcId field by defaulting it to an empty string. See line 316.

Copy link
Member

@lra lra left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good, just a few comments to embrace the fact that a VPC is optional due to classic.

@@ -61,6 +63,7 @@ def __init__(self,
assert isinstance(id, str), "Invalid id: {}".format(id)
assert isinstance(name, str)
assert isinstance(description, str)
assert isinstance(vpc_id, str)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Taking classic into account, a firewall rule does not need to be in a VPC, so let's make this str or NoneType.

@@ -36,6 +36,7 @@ def __init__(self,
id,
name,
description,
vpc_id,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

make it default to None to support classic.

@@ -175,6 +180,7 @@ def rules(self):
main_row['id'],
main_row['name'],
main_row['description'],
main_row['vpc_id'],
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can use a named param as vpc_id is optional.

@@ -189,6 +195,7 @@ def rules(self):
main_row['id'],
main_row['name'],
main_row['description'],
main_row['vpc_id'],
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ditto

@@ -204,6 +211,7 @@ def rules(self):
main_row['id'],
main_row['name'],
main_row['description'],
main_row['vpc_id'],
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ditto

@@ -212,14 +220,16 @@ def rules(self):
else:
fr = FirewallRule(main_row['id'],
main_row['name'],
main_row['description'])
main_row['description'],
main_row['vpc_id'])
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ditto

@@ -301,6 +313,7 @@ def _get_rules_from_aws(self):
group_dict['id'] = group['GroupId']
group_dict['name'] = group['GroupName']
group_dict['description'] = group.get('Description', None)
group_dict['vpc_id'] = group.get('VpcId', "")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Like the optional fields use None instead of an empty string.

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

Successfully merging this pull request may close these issues.

2 participants