Skip to content

Commit

Permalink
Refactor (#6)
Browse files Browse the repository at this point in the history
* Refactor in progress

* Refactor

* Refactor updates

* Refactor

* Remove netutils

* draft validators

* Project bootrapping

* Refactoring

* validator updates

* yamllint

* black

* test updates

* remove working-directory

* run actions on refactor

* fix github action

* fix ci

* fix ci

* Revert python test matrix

* tweak ci

* isort fixes

* yamllint updates

* tweak ci

* Updates, but still in broken state

* update gitignore to remove ruff_cache

* add devcontainer

* tweak devcontainer

* Refactoring

* Update tests

* Fmt

* Update tests

* Test updates

* Update tests

* Test updates

* pyproject.toml updates

* poetry updates

* devcontainer updates

* remove broken references in CI

* poetry updates

* remove duplicate imports

---------

Co-authored-by: ryanmerolle <ryan.merolle@gmail.com>
Co-authored-by: Ryan Merolle <ryanmerolle@users.noreply.github.com>
  • Loading branch information
3 people authored Feb 3, 2024
1 parent e4a4fb4 commit 0dcb7e4
Show file tree
Hide file tree
Showing 42 changed files with 1,551 additions and 835 deletions.
98 changes: 98 additions & 0 deletions .devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
// For format details, see https://aka.ms/devcontainer.json. For config options, see the
// README at: https://github.com/devcontainers/templates/tree/main/src/python
{
"name": "net_schema",
// Or use a Dockerfile or Docker Compose file. More info: https://containers.dev/guide/dockerfile
"image": "mcr.microsoft.com/devcontainers/python:1-3.8",
"features": {
"ghcr.io/devcontainers-contrib/features/bandit:2": {},
"ghcr.io/devcontainers-contrib/features/black:2": {},
"ghcr.io/devcontainers-contrib/features/flake8:2": {},
"ghcr.io/devcontainers-contrib/features/isort:2": {},
"ghcr.io/devcontainers-contrib/features/mypy:2": {},
"ghcr.io/devcontainers-contrib/features/poetry:2": {},
"ghcr.io/devcontainers-contrib/features/pylint:2": {},
"ghcr.io/devcontainers-contrib/features/ruff:1": {},
"ghcr.io/devcontainers-contrib/features/yamllint:2": {},
"ghcr.io/jungaretti/features/make:1": {}
},

// Features to add to the dev container. More info: https://containers.dev/features.
// "features": {},

// Use 'forwardPorts' to make a list of ports inside the container available locally.
// "forwardPorts": [],

// Use 'postCreateCommand' to run commands after the container is created.
"postCreateCommand": "poetry config virtualenvs.in-project true && poetry install",

// Configure tool-specific properties.
"customizations": {
"vscode": {
"settings": {
"[python]": {
"editor.defaultFormatter": "ms-python.black-formatter",
"venvFolders": ["venv", ".venv"],
"editor.formatOnSave": true,
"files.trimTrailingWhitespace": true
},
"[plaintext]": {
"files.trimTrailingWhitespace": false
},
"editor.rulers": [80, 100],
"editor.bracketPairColorization.enabled": true,
"editor.codeActionsOnSave": {
"source.organizeImports": true
},
"editor.trimAutoWhitespace": false,
"extensions.autoCheckUpdates": true,
"extensions.ignoreRecommendations": true,
"files.insertFinalNewline": true,
"python.analysis.extraPaths": [
"/workspaces/net_schema",
"/workspaces/net_schema/.venv/lib/python3.8/site-packages"
],
"python.pyright.typeCheckingMode": "basic",
"python.analysis.typeCheckingMode": "basic",
"python.autoComplete.extraPaths": [
"/workspaces/net_schema",
"/workspaces/net_schema/.venv/lib/python3.8/site-packages"
],
"python.pythonPath": "/workspaces/net_schema/.venv/bin/python3",
"python.terminal.activateEnvironment": true,
"python.testing.pytestArgs": ["tests"],
"python.testing.pytestEnabled": true,
"python.testing.unittestEnabled": false,
"python.venvPath": "/workspaces/net_schema/.venv"
},
"extensions": [
"ms-python.python",
"Codium.codium",
"GSGBen.fortigate-fortios-syntax",
"GitHub.copilot",
"GitHub.copilot-chat",
"GitHub.copilot-labs",
"GitHub.vscode-codeql",
"GitHub.vscode-github-actions",
"GitHub.vscode-pull-request-github",
"Gruntfuggly.todo-tree",
"KevinRose.vsc-python-indent",
"Tyriar.sort-lines",
"charliermarsh.ruff",
"esbenp.prettier-vscode",
"hbenl.vscode-test-explorer",
"ms-vscode.test-adapter-converter",
"ms-python.black-formatter",
"ms-python.flake8",
"ms-python.isort",
"ms-python.mypy-type-checker",
"ms-python.pylint",
"mutantdino.resourcemonitor",
"paulomenezes.duplicated-code",
"piotrpalarz.vscode-gitignore-generator",
"sourcery.sourcery",
"yzhang.markdown-all-in-one"
]
}
}
}
57 changes: 28 additions & 29 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
---
name: CI

# Commented until CI is deployed
#on:
# push:
# branches: [ "development" ]
# paths:
# - **
# - "!**/README.md"
# pull_request:
# branches: [ "development" ]
# paths:
# - **
# - "!**/README.md"
# workflow_dispatch:
on:
push:
branches: ["development", "refactor"]
#paths:
# - "**/*.py"
# - "!**/README.md"
pull_request:
branches: ["development"]
paths:
- "**/*.py"
- "!**/README.md"
workflow_dispatch:

jobs:
code-quality:
Expand All @@ -36,31 +36,30 @@ jobs:
poetry-version: ${{matrix.poetry-version}}

- name: Format (chk) - black
run: poetry run black . --check
run: poetry run black ./src ./tests
- name: Format (chk) - isort
run: poetry run isort . --check-only --profile black
- name: Format (chk) - autoflake
run: poetry run autoflake -r . --expand-star-imports --remove-unused-variables --remove-all-unused-imports
- name: Format (chk) - bandit
run: poetry run bandit -c pyproject.toml -r .
- name: Lint - flake8
run: poetry run flake8 .
- name: Lint - pydocstyle
run: poetry run pydocstyle .
run: poetry run isort ./src ./tests --check-only --profile black
#- name: Format (chk) - autoflake
# run: poetry run autoflake -r . --expand-star-imports --remove-unused-variables --remove-all-unused-imports
#- name: Format (chk) - bandit
# run: poetry run bandit -c pyproject.toml -r .
#- name: Lint - flake8
# run: poetry run flake8 .
#- name: Lint - pydocstyle
# run: poetry run pydocstyle .
- name: Lint - yamllint
run: poetry run yamllint cyborg_web/ -c .yamllint
run: poetry run yamllint src/ -c .yamllint
- name: Type check - mypy
run: poetry run mypy .
run: poetry run mypy ./src ./tests --config-file pyproject.toml
test:
name: "python-tests"
needs: python-code-quality
needs: "code-quality"
strategy:
matrix:
python-version: [3.8.x]
poetry-version: [1.3.1]
runs-on: ubuntu-latest
working-directory: cyborg_web
steps:
steps:
- name: Check out repository
uses: actions/checkout@v3

Expand All @@ -71,4 +70,4 @@ jobs:
poetry-version: ${{matrix.poetry-version}}

- name: Test
run: poetry run pytest tests -vvv --tb=short
run: poetry run pytest tests -vvv --tb=short
5 changes: 4 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -135,4 +135,7 @@ dmypy.json
.pytype/

# Cython debug symbols
cython_debug/
cython_debug/

# Ruff
.ruff_cache/
14 changes: 0 additions & 14 deletions defs/asn.json

This file was deleted.

9 changes: 0 additions & 9 deletions defs/vlan.json

This file was deleted.

8 changes: 0 additions & 8 deletions examples/defs/dc.yml

This file was deleted.

12 changes: 3 additions & 9 deletions examples/host_vars/rtr001.yml
Original file line number Diff line number Diff line change
@@ -1,15 +1,9 @@
---
asn:
name: admin
password: admin

def1:
name: admin

def2:
id: 1

vlan:
ip: 1.1.1.1
asn: "4294967296"

interfaces:
- name: eth0
Expand All @@ -22,7 +16,7 @@ interfaces:
ip: 10.1.3.1
netmask: 255.255.255.0
- name: eth3
ip: 10.1.4.1
ip: 10.1.4.1000
netmask: 255.255.255.0
- name: eth4
ip: 10.1.5.1
Expand Down
1 change: 1 addition & 0 deletions examples/host_vars/rtr002.yml
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
---
interfaces:
- name: eth0
ip: 10.2.1.1
Expand Down
1 change: 1 addition & 0 deletions examples/host_vars/rtr003.yml
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
---
interfaces:
- name: eth0
ip: 10.3.1.1
Expand Down
1 change: 1 addition & 0 deletions examples/host_vars/rtr004.yml
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
---
interfaces:
- name: eth0
ip: 10.4.1.1
Expand Down
1 change: 1 addition & 0 deletions examples/host_vars/rtr005.yml
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
---
interfaces:
- name: eth0
ip: 10.5.1.1
Expand Down
6 changes: 6 additions & 0 deletions examples/schema.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
type: object
properties:
asn:
type: string
asn: True
15 changes: 0 additions & 15 deletions examples/schema.yml

This file was deleted.

Loading

0 comments on commit 0dcb7e4

Please sign in to comment.