-
Notifications
You must be signed in to change notification settings - Fork 51
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #211 from networktocode/develop
Push 1.4.1 to Main
- Loading branch information
Showing
18 changed files
with
39,580 additions
and
75,840 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
--- | ||
name: "Protocol-Updates" | ||
|
||
on: # yamllint disable-line rule:truthy | ||
schedule: | ||
- cron: "0 8 * * 4" | ||
|
||
jobs: | ||
data_gathering: | ||
runs-on: "ubuntu-latest" | ||
env: | ||
BRANCH_NAME: "PROTO_Updates" | ||
steps: | ||
# Checkout repo | ||
- name: "Check out code" | ||
uses: "actions/checkout@v2" | ||
with: | ||
ref: "develop" | ||
# Create branch for Flatbot | ||
- name: "Create Flatbot branch" | ||
run: "git checkout -b $BRANCH_NAME" | ||
# Push new branch so Flatbot can make its commit | ||
- name: "Push Flatbot branch" | ||
run: "git push --set-upstream origin $BRANCH_NAME" | ||
# Install Black | ||
- name: "Install Python Black" | ||
run: "pip install black" | ||
# This step installs Deno, which is a new Javascript runtime that improves on Node. Can be used for an optional postprocessing step | ||
- name: "Setup deno" | ||
uses: "denoland/setup-deno@main" | ||
with: | ||
deno-version: "v1.10.x" | ||
# The Flat Action step. We fetch the data in the http_url and save it as downloaded_filename | ||
- name: "Fetch data" | ||
uses: "githubocto/flat@v3" | ||
with: | ||
http_url: "https://www.iana.org/assignments/service-names-port-numbers/service-names-port-numbers.csv" | ||
downloaded_filename: "./netutils/data_files/protocol_mappings.py" | ||
postprocess: "./flat_postprocess/protocol_postprocess.ts" | ||
pr_creation: | ||
runs-on: "ubuntu-latest" | ||
needs: "data_gathering" | ||
steps: | ||
# Checkout repo | ||
- name: "Check out code" | ||
uses: "actions/checkout@v2" | ||
with: | ||
ref: "PROTO_Updates" | ||
# Create PR from branch created above into develop | ||
- name: "Create a Pull Request" | ||
run: "gh pr create -B develop -H PROTO_Updates --title 'Flatbot PROTOCOL File Updates' --body 'Created by Flatbot action'" | ||
env: | ||
GITHUB_TOKEN: "${{ secrets.GITHUB_TOKEN }}" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
# BGP ASNs | ||
# Passwords | ||
|
||
::: netutils.asn | ||
::: netutils.password | ||
options: | ||
show_submodules: True |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
"""Python code used to postprocess Flat github action data related to Protocol mappings.""" | ||
import csv | ||
import os | ||
import sys | ||
from urllib.request import urlopen | ||
|
||
|
||
if __name__ == "__main__": | ||
if len(sys.argv) == 2: | ||
URL = "https://www.iana.org/assignments/service-names-port-numbers/service-names-port-numbers.csv" | ||
oui_textfile = urlopen(URL).read().decode("utf-8") # nosec: pylint: disable=consider-using-with | ||
with open(sys.argv[1], "w", encoding="utf-8") as proto_mappings: | ||
proto_mappings.write(oui_textfile) | ||
|
||
protocol_mapping = {} | ||
with open(sys.argv[1], encoding="utf-8") as file: | ||
next(file) | ||
reader = csv.reader(file) | ||
for row in reader: | ||
name = row[0] | ||
port = row[1] | ||
protocol = row[2] | ||
if not port.isnumeric(): | ||
continue | ||
if name and port and protocol: | ||
if protocol_mapping.get(name) and protocol_mapping[name]["port_number"] != int(port): | ||
name = name + "-secondary" | ||
if not protocol_mapping.get(name): | ||
protocol_mapping[name] = {"port_number": int(port), "protocols": []} | ||
protocol_mapping[name]["protocols"].append(protocol) | ||
|
||
with open(sys.argv[1], "w", encoding="utf-8") as proto_mappings: | ||
proto_mappings.write('"""Dictionary object to store Protocol information."""\n') | ||
proto_mappings.write("# pylint: disable=too-many-lines\n") | ||
proto_mappings.write("from typing import Any, Dict\n\n") | ||
proto_mappings.write(f"PROTOCOLS: Dict[str, Any] = {protocol_mapping}") | ||
|
||
os.system(f"black {sys.argv[1]}") # nosec |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
// Forwards the execution to the python script | ||
const py_run = Deno.run({ | ||
// Run `python ./flat_postprocess/protocol_postprocess.py netutils/data_files/protocol_mappings.py` to test locally. | ||
cmd: ["python", "./flat_postprocess/protocol_postprocess.py"].concat(Deno.args), | ||
}); | ||
|
||
await py_run.status(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.