Skip to content

Commit

Permalink
Move is_external_cidr to common
Browse files Browse the repository at this point in the history
  • Loading branch information
0xdabbad00 committed Jun 12, 2018
1 parent f3049eb commit 70109ea
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 12 deletions.
13 changes: 1 addition & 12 deletions commands/prepare.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
import argparse
import pyjq
from netaddr import IPNetwork, IPAddress
from shared.common import get_account, query_aws, get_regions
from shared.common import get_account, query_aws, get_regions, is_external_cidr
from shared.nodes import Account, Region, Vpc, Az, Subnet, Ec2, Elb, Rds, Cidr, Connection

__description__ = "Generate network connection information file"
Expand Down Expand Up @@ -92,17 +92,6 @@ def get_sgs(vpc):
return pyjq.all('.SecurityGroups[] | select(.VpcId == "{}")'.format(vpc.local_id), sgs)


def is_external_cidr(cidr):
ipnetwork = IPNetwork(cidr)
if (
ipnetwork in IPNetwork("10.0.0.0/8") or
ipnetwork in IPNetwork("172.16.0.0/12") or
ipnetwork in IPNetwork("192.168.0.0/16")
):
return False
return True


def get_external_cidrs(account, config):
external_cidrs = []
unique_cidrs = {}
Expand Down
14 changes: 14 additions & 0 deletions shared/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import datetime
import pyjq
import sys
from netaddr import IPNetwork

class Severity:
DEBUG = 0
Expand Down Expand Up @@ -61,6 +62,8 @@ def log_issue(severity, msg, location=None, reasons=[]):
'Reasons': reasons
}
print(json.dumps(json_issue, sort_keys=True), file=sys.stderr)


def datetime_handler(x):
if isinstance(x, datetime.datetime):
return x.isoformat()
Expand All @@ -73,6 +76,17 @@ def make_list(v):
return v


def is_external_cidr(cidr):
ipnetwork = IPNetwork(cidr)
if (
ipnetwork in IPNetwork("10.0.0.0/8") or
ipnetwork in IPNetwork("172.16.0.0/12") or
ipnetwork in IPNetwork("192.168.0.0/16")
):
return False
return True


def query_aws(account, query, region=None):
if not region:
file_name = 'account-data/{}/{}.json'.format(account.name, query)
Expand Down

0 comments on commit 70109ea

Please sign in to comment.