Skip to content

Commit

Permalink
Merge pull request #73 from networktocode/develop
Browse files Browse the repository at this point in the history
Bump version to 0.2.4 in main
  • Loading branch information
itdependsnetworks authored Nov 13, 2021
2 parents a498c86 + 1c605a0 commit 828a307
Show file tree
Hide file tree
Showing 37 changed files with 3,156 additions and 324 deletions.
219 changes: 219 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,219 @@
---
name: "CI"
on: # yamllint disable
- "push"
- "pull_request"

jobs:
black:
runs-on: "ubuntu-20.04"
env:
INVOKE_LOCAL: "True"
steps:
- name: "Check out repository code"
uses: "actions/checkout@v2"
- name: "Setup environment"
uses: "networktocode/gh-action-setup-poetry-environment@v2"
- name: "Linting: black"
run: "poetry run invoke black"
bandit:
runs-on: "ubuntu-20.04"
env:
INVOKE_LOCAL: "True"
steps:
- name: "Check out repository code"
uses: "actions/checkout@v2"
- name: "Setup environment"
uses: "networktocode/gh-action-setup-poetry-environment@v2"
- name: "Linting: bandit"
run: "poetry run invoke bandit"
needs:
- "black"
pydocstyle:
runs-on: "ubuntu-20.04"
env:
INVOKE_LOCAL: "True"
steps:
- name: "Check out repository code"
uses: "actions/checkout@v2"
- name: "Setup environment"
uses: "networktocode/gh-action-setup-poetry-environment@v2"
- name: "Linting: pydocstyle"
run: "poetry run invoke pydocstyle"
needs:
- "black"
flake8:
runs-on: "ubuntu-20.04"
env:
INVOKE_LOCAL: "True"
steps:
- name: "Check out repository code"
uses: "actions/checkout@v2"
- name: "Setup environment"
uses: "networktocode/gh-action-setup-poetry-environment@v2"
- name: "Linting: flake8"
run: "poetry run invoke flake8"
needs:
- "black"
yamllint:
runs-on: "ubuntu-20.04"
env:
INVOKE_LOCAL: "True"
steps:
- name: "Check out repository code"
uses: "actions/checkout@v2"
- name: "Setup environment"
uses: "networktocode/gh-action-setup-poetry-environment@v2"
- name: "Linting: yamllint"
run: "poetry run invoke yamllint"
needs:
- "black"
build:
strategy:
fail-fast: true
matrix:
python-version: ["3.6", "3.7", "3.8", "3.9"]
runs-on: "ubuntu-20.04"
env:
PYTHON_VER: "${{ matrix.python-version }}"
IMAGE_NAME: "netutils"
steps:
- name: "Check out repository code"
uses: "actions/checkout@v2"
- name: "Setup environment"
uses: "networktocode/gh-action-setup-poetry-environment@v2"
- name: "Create tmp docker dir"
run: "mkdir /tmp/docker"
- name: "Cache Docker images"
uses: "actions/cache@v2"
id: "cached-docker-images"
with:
path: "/tmp/docker"
key: "${{ runner.os }}-docker-${{ matrix.python-version }}-${{ hashFiles('./Dockerfile') }}"
- name: "Build Container"
if: "steps.cached-docker-images.outputs.cache-hit != 'true'"
run: "poetry run invoke build"
- name: "Show Docker images"
if: "steps.cached-docker-images.outputs.cache-hit != 'true'"
run: "docker image ls"
- name: "Save the Docker image"
if: "steps.cached-docker-images.outputs.cache-hit != 'true'"
run: "docker save `echo ${IMAGE_NAME}`:`poetry version -s`-py${{ matrix.python-version }} > /tmp/docker/netutils-py${{ matrix.python-version }}.tar"
- name: "Show files"
run: "ls -al /tmp/docker"
needs:
- "bandit"
- "pydocstyle"
- "flake8"
- "yamllint"
pylint:
strategy:
fail-fast: true
matrix:
python-version: ["3.7"]
runs-on: "ubuntu-20.04"
steps:
- name: "Check out repository code"
uses: "actions/checkout@v2"
- name: "Setup environment"
uses: "networktocode/gh-action-setup-poetry-environment@v2"
# - name: "Cache Docker images"
# uses: "actions/cache@v2"
# id: "cached-docker-images"
# with:
# path: "/tmp/docker"
# key: "${{ runner.os }}-docker-${{ matrix.python-version }}-${{ hashFiles('./Dockerfile') }}"
# - name: "Load docker image"
# run: "docker load < /tmp/docker/netutils-py${{ matrix.python-version }}.tar"
# - name: "Show docker images"
# run: "docker image ls"
- name: "Build Container"
run: "poetry run invoke build"
- name: "Linting: Pylint"
run: "poetry run invoke pylint"
needs:
- "build"
pytest:
strategy:
fail-fast: true
matrix:
python-version: ["3.6", "3.7", "3.8", "3.9"]
runs-on: "ubuntu-20.04"
env:
PYTHON_VER: "${{ matrix.python-version }}"
steps:
- name: "Check out repository code"
uses: "actions/checkout@v2"
- name: "Setup environment"
uses: "networktocode/gh-action-setup-poetry-environment@v2"
# - name: "Cache Docker images"
# uses: "actions/cache@v2"
# id: "cached-docker-images"
# with:
# path: "/tmp/docker"
# key: "${{ runner.os }}-docker-${{ matrix.python-version }}-${{ hashFiles('./Dockerfile') }}"
# - name: "Load docker image"
# run: "docker load < /tmp/docker/netutils-py${{ matrix.python-version }}.tar"
- name: "Build Container"
run: "poetry run invoke build"
- name: "Linting: Pylint"
run: "poetry run invoke pylint"
- name: "Run Tests"
run: "poetry run invoke pytest"
needs:
- "pylint"
publish_gh:
name: "Publish to GitHub"
runs-on: "ubuntu-20.04"
if: "startsWith(github.ref, 'refs/tags/v')"
steps:
- name: "Check out repository code"
uses: "actions/checkout@v2"
- name: "Set up Python"
uses: "actions/setup-python@v2"
with:
python-version: "3.9"
- name: "Install Python Packages"
run: "pip install poetry"
- name: "Set env"
run: "echo RELEASE_VERSION=${GITHUB_REF:10} >> $GITHUB_ENV"
- name: "Run Poetry Version"
run: "poetry version $RELEASE_VERSION"
- name: "Run Poetry Build"
run: "poetry build"
- name: "Upload binaries to release"
uses: "svenstaro/upload-release-action@v2"
with:
repo_token: "${{ secrets.NTC_GITHUB_TOKEN }}"
file: "dist/*"
tag: "${{ github.ref }}"
overwrite: true
file_glob: true
needs:
- "pytest"
publish_pypi:
name: "Push Package to PyPI"
runs-on: "ubuntu-20.04"
if: "startsWith(github.ref, 'refs/tags/v')"
steps:
- name: "Check out repository code"
uses: "actions/checkout@v2"
- name: "Set up Python"
uses: "actions/setup-python@v2"
with:
python-version: "3.9"
- name: "Install Python Packages"
run: "pip install poetry"
- name: "Set env"
run: "echo RELEASE_VERSION=${GITHUB_REF:10} >> $GITHUB_ENV"
- name: "Run Poetry Version"
run: "poetry version $RELEASE_VERSION"
- name: "Run Poetry Build"
run: "poetry build"
- name: "Push to PyPI"
uses: "pypa/gh-action-pypi-publish@release/v1"
with:
user: "__token__"
password: "${{ secrets.PYPI_API_TOKEN }}"
needs:
- "pytest"
74 changes: 0 additions & 74 deletions .travis.yml

This file was deleted.

22 changes: 22 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,27 @@
# Changelog

## v0.2.4 - 2021-11

### Added

- #33 Add interface range compress function
- #53 Add get peer address function
- #59 Add bandwidth converting function
- #65 Added Docker caching
- #68 Add Fortinet Fortios Parser support

### Changed

- #64 CI implementation on GitHub actions

### Fixed

- #52 Update pyproject.toml build-server
- #55 update version in toml and init files
- #63 Fix lack of zero padding on ip to binary conversion
- #70 Fix lack of zero padding on ip to hex conversion
- #68 Update Black pinning

## v0.2.3 - 2021-09

### Added
Expand Down
33 changes: 32 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ The following function will help in deploying list of VLANs and match the config
>>> vlan_cfg = vlanlist_to_config([1, 2, 3, 5, 6, 1000, 1002, 1004, 1006, 1008, 1010, 1012, 1014, 1016, 1018])
>>>
>>> vlan_cfg
['1-3,5,6,1000,1002,1004,1006,1008,1010,1012,1014', '1016,1018']
["1-3,5,6,1000,1002,1004,1006,1008,1010,1012,1014", "1016,1018"]
>>>
>>> for index, line in enumerate(vlan_cfg):
... if index == 0:
Expand Down Expand Up @@ -150,6 +150,37 @@ The project is following Network to Code software development guidelines and are
- Black, Pylint, Bandit, flake8, and pydocstyle for Python linting and formatting.
- pytest, coverage, and unittest for unit tests.

There are a number of things that are required in order to have a successfull PR.

- All new functions must contain at least 1 example in their docstrings.
- Docstrings must conform to the google docstring [convention](https://google.github.io/styleguide/pyguide.html#381-docstrings).
- Unit test for newly added functions are required.
- If applicable, tests related to config parsing and compliuance must be added.
- Update the jinja2 filter for any new functions (see below for details).
- If you create a new file in the `netutils` folder, you must create a new folder and `index.rst` in the docs folde r(see below for details).
- Your PR must not introduce any required dependencies. You can introduce optional or development dependencies.

## Adding to the jinja2 filter function

To add a new function to the jinja2 filter, add a new entry to the `_JINJA2_FUNCTION_MAPPINGS` located in the `utils.py` file. When adding an entry, the key corresponds with the name to call the function and the value to the path to find the function.

## Adding docs for a new python file

If adding a new python file, the docs must be updated to account for the new file.

1. Create a new folder in `docs/source/netutils` matching the name of your new file.
2. Create an `index.rst` file in that folder.
3. Add the following to the newly created file.

```python
#############################
# ENTER THE TITLE OF THE PAGE
##############################

.. automodule:: netutils.newfile
:members:
```

## CLI Helper Commands

The project features a CLI helper based on [invoke](http://www.pyinvoke.org/) to help setup the development environment. The commands are listed below in 3 categories:
Expand Down
2 changes: 1 addition & 1 deletion docs/source/contributing/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@ Contributing

.. mdinclude:: ../../../README.md
:start-line: 144
:end-line: 197
:end-line: 228
9 changes: 8 additions & 1 deletion docs/source/netutils/configs/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,11 @@ Configs
:members:

.. automodule:: netutils.config.parser
:members:
:members:

Edge Cases
==============

Fortinet Fortios Parser
-----------------------
- In order to support html blocks that exist in Fortios configurations, some preprocessing is executed, this is a regex that specifically grabs everything between quotes after the 'set buffer' sub-command. It's explicitly looking for double quote followed by a newline ("\n) to end the captured data. This support for html data will not support any other html that doesn't follow this convention.
Loading

0 comments on commit 828a307

Please sign in to comment.