Skip to content

Commit

Permalink
fix no rule exist error
Browse files Browse the repository at this point in the history
  • Loading branch information
piyushsonigra committed Feb 19, 2020
1 parent 8664acc commit 31fbfc5
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 6 deletions.
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -107,3 +107,7 @@ Run the aws_ipadd command with aws_ipadd profile.
## Licence

- [aws_ipadd](https://github.com/piyushsonigra/aws_ipadd/blob/master/LICENSE)

## Thanks

- [amazonaws_checkip](https://checkip.amazonaws.com)
8 changes: 2 additions & 6 deletions aws_ipadd
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ def revoke_ip_permission(security_group_id, ip):
'IpRanges': [{'CidrIp': ip}]
}])

public_ip = requests.get('https://ipinfo.io/ip').text.strip() + '/32'
public_ip = requests.get('https://checkip.amazonaws.com').text.strip() + '/32'

try:
security_group = session.describe_security_groups(GroupIds=[security_group_id])
Expand All @@ -67,11 +67,7 @@ except ClientError as e:
print(e)
sys.exit()

try:
security_group_rule = [security_group_rule for security_group_rule in security_group_rules if security_group_rule['FromPort'] == port]
except Exception as e:
print("No rules exist for {}.".format(port))
sys.exit()
security_group_rule = [security_group_rule for security_group_rule in security_group_rules if 'FromPort' in security_group_rule]

if len(security_group_rule) == 0:
try:
Expand Down

0 comments on commit 31fbfc5

Please sign in to comment.