Skip to content

Commit

Permalink
Merge pull request #27 from kiraum/kiraum/pyproject_precommit_docstring
Browse files Browse the repository at this point in the history
chore: Adding pyproject, pre-commit, updating docstring/requirements, and others
  • Loading branch information
kiraum authored May 8, 2024
2 parents f43908e + ae08042 commit ef566ec
Show file tree
Hide file tree
Showing 7 changed files with 191 additions and 35 deletions.
37 changes: 37 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: 'v4.5.0'
hooks:
- id: check-yaml
- id: end-of-file-fixer
- id: trailing-whitespace
- repo: local
hooks:
- id: isort
name: isort
entry: isort -m3 --tc
language: system
- repo: local
hooks:
- id: black
name: black
entry: black
language: python
types_or: [python, pyi]
- repo: local
hooks:
- id: ruff
name: ruff
entry: ruff check --force-exclude
language: python
types_or: [python, pyi]
- repo: local
hooks:
- id: pylint
name: pylint
entry: pylint
args:
- --rcfile=pyproject.toml
- -d format
language: system
types: [python]
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,15 +43,15 @@ pip install -r requirements.txt
```
i% ./peering_gossip.py -lg https://alice-rs.linx.net
rs1-in2-lon1-linx-net-v4
rs1-in2-lon1-linx-net-v6
rs1-in2-lon1-linx-net-v6
rs3-tch-lon1-linx-net-v4
rs3-tch-lon1-linx-net-v6
rs2-in2-lon2-linx-net-v4
rs2-in2-lon2-linx-net-v6
rs1-tcw-man1-linx-net-v4
rs1-tcw-man1-linx-net-v6
rs1-pue-sco1-linx-net-v4
rs1-pue-sco1-linx-net-v6
rs1-pue-sco1-linx-net-v4
rs1-pue-sco1-linx-net-v6
rs1-ngd-car1-linx-net-v4
rs1-ngd-car1-linx-net-v6
rs1-imm-nva1-linx-net-v4
Expand All @@ -68,7 +68,7 @@ rs2-tcj-man1-linx-net-v4
rs2-tcj-man1-linx-net-v6
Filtered prefixes @ https://alice-rs.linx.net | ASN | NAME | Contacts | PeeringDB link
3066 | 3216 | SOVAM-AS | [email protected],[email protected],[email protected],[email protected],[email protected] | https://www.peeringdb.com/asn/3216
1182 | 39386 | STC-IGW-AS | [email protected],[email protected],[email protected] | https://www.peeringdb.com/asn/39386
1182 | 39386 | STC-IGW-AS | [email protected],[email protected],[email protected] | https://www.peeringdb.com/asn/39386
783 | 7713 | telkomnet-as-ap | [email protected],[email protected],[email protected],[email protected] | https://www.peeringdb.com/asn/7713
546 | 57463 | NetIX | [email protected],[email protected] | https://www.peeringdb.com/asn/57463
...
Expand Down
4 changes: 2 additions & 2 deletions peering_gossip.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,14 @@
Peering Gossip - Gossiping about bad practices!
"""

import sys
import argparse
import sys

from pgossip.pgossip import PGossip


def main():
"""Peering Gossip main"""
"""Peering Gossip"""
parser = argparse.ArgumentParser(
description="Peering Gossip - Gossiping about bad practices!"
)
Expand Down
1 change: 1 addition & 0 deletions pgossip/config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,4 @@ ixps:
- https://lg.ams-ix.net
- https://lg.de-cix.net
- https://alice-rs.linx.net
- https://lg.ix.br
80 changes: 71 additions & 9 deletions pgossip/pgossip.py
Original file line number Diff line number Diff line change
@@ -1,19 +1,43 @@
""" Peering Gossip """
import sys

import json
import sys
import time
import yaml

import requests
import yaml


class PGossip:
"""
Peering Buddy class
Peering Buddy main functions for analyzing peering information.
Provides methods for generating a hall of shame, fetching information about alive route servers
and their neighbors, retrieving ASN whois information, creating a report, and loading a YAML config file.
Attributes:
None
Methods:
alice_hos: Generate hall of shame based on provided URL.
alice_rs: Get alive looking glass route servers.
alice_neighbours: Get alive looking glass neighbors for a specific route server.
bv_asn_whois: Return ASN whois information from BGPView API.
create_report: Create a pastebin-like report using glot.io API.
load_yaml: Load a YAML config file.
"""

# pylint: disable=too-many-locals
def alice_hos(self, url):
"""generate hall of shame"""
"""
Generate hall of shame based on provided URL.
Args:
url (str): The URL to fetch data from.
Returns:
None
"""
filtered_routes_sorted = None
filtered_routes_clean = None
filtered_routes_sum = {}
Expand Down Expand Up @@ -68,7 +92,15 @@ def alice_hos(self, url):
tfile.write("\n".join(map(str, text)))

def alice_rs(self, url):
"""get alive lg rs"""
"""
Get alive looking glass route servers.
Args:
url (str): The base URL.
Returns:
list: List of alive route servers.
"""
url = f"{url}/api/v1/routeservers"
with requests.Session() as session:
response = session.get(url)
Expand All @@ -83,7 +115,16 @@ def alice_rs(self, url):
return rs_list

def alice_neighbours(self, url, route_server):
"""get alive lg neighbors"""
"""
Get alive looking glass neighbors for a specific route server.
Args:
url (str): The base URL.
route_server (str): The ID of the route server.
Returns:
dict: Dictionary containing neighbor ASNs and their filtered routes.
"""
url = f"{url}/api/v1/routeservers/{route_server}/neighbors"
with requests.Session() as session:
response = session.get(url)
Expand Down Expand Up @@ -111,7 +152,15 @@ def alice_neighbours(self, url, route_server):
return neighbour_dict

def bv_asn_whois(self, asn):
"""return asn whois information"""
"""
Return ASN whois information from BGPView API.
Args:
asn (int): The ASN to retrieve information for.
Returns:
dict: Dictionary containing ASN whois information.
"""
url = f"https://api.bgpview.io/asn/{asn}"
with requests.Session() as session:
response = session.get(url)
Expand All @@ -131,7 +180,15 @@ def bv_asn_whois(self, asn):
return result

def create_report(self, data):
"""create a pastebin like report"""
"""
Create a pastebin-like report using glot.io API.
Args:
data (str): The data to include in the report.
Returns:
str: URL of the created report.
"""
url = "https://glot.io/api/snippets"
headers = {"Content-Type": "application/json; charset=utf-8"}
payload = {
Expand All @@ -150,7 +207,12 @@ def create_report(self, data):
return report_url

def load_yaml(self):
"""load yaml config file"""
"""
Load a YAML config file.
Returns:
dict: Dictionary containing the YAML config data.
"""
with open("pgossip/config.yaml", "r", encoding="utf8") as file:
data = yaml.load(file, Loader=yaml.FullLoader)
return data
30 changes: 30 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
[project]
name = "peering_gossip"
description = "The idea is to have a gossip tool generating a Hall of Shame for Autonomous Systems that are not so polite."
version = "0.0.1"
authors = [{ name = "Tiago Felipe Goncalves", email = "[email protected]" }]
readme = "README.md"
requires-python = ">=3.12"
keywords = ["peering", "tool", "shame", "hall"]
dependencies = [
"requests",
"black",
"isort",
"pylint",
"ruff",
"pytest",
"yamllint",
"uv",
]

[project.urls]
documentation = "https://github.com/kiraum/peering_buddy/blob/main/README.md"
repository = "https://github.com/kiraum/peering_buddy/"

[tool.pylint.messages_control]
disable = [
"format",
]

[tool.isort]
profile = "black"
66 changes: 46 additions & 20 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1,23 +1,49 @@
astroid==2.15.5
black==23.3.0
certifi==2023.5.7
charset-normalizer==3.1.0
click==8.1.3
dill==0.3.6
idna==3.4
isort==5.12.0
lazy-object-proxy==1.9.0
# This file was autogenerated by uv via the following command:
# uv pip compile pyproject.toml
astroid==3.1.0
# via pylint
black==24.4.2
certifi==2024.2.2
# via requests
charset-normalizer==3.3.2
# via requests
click==8.1.7
# via black
dill==0.3.8
# via pylint
idna==3.7
# via requests
iniconfig==2.0.0
# via pytest
isort==5.13.2
# via pylint
mccabe==0.7.0
# via pylint
mypy-extensions==1.0.0
packaging==23.1
pathspec==0.11.1
platformdirs==3.5.1
pyaml==23.5.9
pylint==2.17.4
PyYAML==6.0
# via black
packaging==24.0
# via
# black
# pytest
pathspec==0.12.1
# via
# black
# yamllint
platformdirs==4.2.1
# via
# black
# pylint
pluggy==1.5.0
# via pytest
pylint==3.1.0
pytest==8.2.0
pyyaml==6.0.1
# via yamllint
requests==2.31.0
tomli==2.0.1
tomlkit==0.11.8
typing_extensions==4.6.3
urllib3==1.26.16
wrapt==1.15.0
ruff==0.4.3
tomlkit==0.12.5
# via pylint
urllib3==2.2.1
# via requests
uv==0.1.41
yamllint==1.35.1

0 comments on commit ef566ec

Please sign in to comment.