def do_list_rules(args): groups = args.aws.ec2.SecurityGroups.get(filters={'group-id': args.groups}) rs = RuleSet() rs.flatten_groups(groups) for rule in rs: print(RuleFormatter(args.aws.account_id).format_rule(rule), file=args.outfile) return 0
def test_adds_missing_ports(self): groups = [{ "GroupId": "sg-23456789", "IpPermissions": [{ "IpProtocol": -1, "UserIdGroupPairs": [], "IpRanges": [{ "CidrIp": "5.6.7.8/32", }], }], "IpPermissionsEgress": [], }] rs = RuleSet() rs.flatten_groups(groups) for group in rs: self.assertEqual(group["FromPort"], -1) self.assertEqual(group["ToPort"], -1)
def test_flatten_groups(self): # ensure that a group structure is flattened to the equivalent set of Rules rs = RuleSet() rs.flatten_groups(self.groups) for group in rs: self.assertIn(dict(group), self.flat)