Skip to content

Commit

Permalink
added comments
Browse files Browse the repository at this point in the history
  • Loading branch information
ssw committed Jan 6, 2023
1 parent 2e5b2fa commit eaed521
Showing 1 changed file with 29 additions and 3 deletions.
32 changes: 29 additions & 3 deletions main.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
import json
import os

# point to templates directory relative to home directory
template_dir = template_dir = os.path.join(os.path.dirname(__file__), 'templates')

app = Flask(__name__, template_folder=template_dir)
def get_asn_from_as(asn):
# Remove the "AS" from the beginning of the ASN
Expand All @@ -26,7 +26,12 @@ def get_more_specifics(data):
origins.append(prefix_origin['origin'])
return [prefixes, origins]
def get_prefix_roa_status(prefix, origin):
""" given a prefix, determine if it is covered by an existing ROA"""
"""
:param prefix: prefix to check
:param origin: origin ASN to check
:return: ROV status of the prefix based on RIPEstat ROA data
"""

url = f"https://stat.ripe.net/data/rpki-validation/data.json?resource={origin}&prefix={prefix}"
response = requests.get(url)
data = json.loads(response.text)
Expand All @@ -38,7 +43,10 @@ def get_prefix_roa_status(prefix, origin):
return None
return(validation_status)
def get_prefix_info(prefix):
""" given a prefix, return the more specific prefixes and their origins as seen by RIPEstat"""
"""
:param prefix: covering prefix to check for more specific prefixes
:return: list of more specific prefixes and their origins
"""
url = "https://stat.ripe.net/data/routing-status/data.json?resource=" + prefix
try:
response = requests.get(url)
Expand Down Expand Up @@ -92,6 +100,11 @@ def is_valid_asn(asn):
return False

def is_valid_prefix_maxlength(ip_prefix, prefix_maxlength):
""" check to see prefix_maxlength is a valid value for the prefix
:param ip_prefix: prefix to check
:param prefix_maxlength: maximum length of the prefix
:return: True if prefix_maxlength is valid, False otherwise
"""
try:
# Try to parse the prefix maxlength as an integer
prefix_maxlength = int(prefix_maxlength)
Expand All @@ -106,6 +119,15 @@ def is_valid_prefix_maxlength(ip_prefix, prefix_maxlength):


def check_list_of_prefixes_against_ROA(origin, prefixes, origins, roa_prefix, roa_maxlen, roa_asn):
""" given a list of prefixes and their origins, check if the ROA covers them
:param origin: origin ASN
:param prefixes: list of prefixes
:param origins: list of origins
:param roa_prefix: prefix from the ROA
:param roa_maxlen: maximum length of the prefix from the ROA
:param roa_asn: ASN from the ROA
:return: list output lines to be displayed on the web page
"""

messages = []
existing_roa_status = get_prefix_roa_status(roa_prefix, origin)
Expand All @@ -120,6 +142,10 @@ def check_list_of_prefixes_against_ROA(origin, prefixes, origins, roa_prefix, ro

@app.route('/', methods=['GET', 'POST'])
def index():
""" main function to handle the web page
:return: web page
"""

if request.method == 'POST':
# Get the user input
roa_ip_prefix = request.form['ip_prefix']
Expand Down

0 comments on commit eaed521

Please sign in to comment.