From 53ba8f50a2c6e5f638179e0d017ccf56444f0902 Mon Sep 17 00:00:00 2001 From: Rick Donato Date: Wed, 29 Jul 2020 19:48:11 +0100 Subject: [PATCH] Fix linting, bandit, format issues --- Makefile | 4 +- acl_auditor/auditor.py | 1 - acl_auditor/helpers.py | 2 +- docker-compose.yml | 12 ++--- poetry.lock | 110 ++++++++++++++++++++++++++++++++++++++++- pyproject.toml | 2 + 6 files changed, 119 insertions(+), 12 deletions(-) diff --git a/Makefile b/Makefile index dbf5f15..1c8d4a8 100644 --- a/Makefile +++ b/Makefile @@ -19,7 +19,7 @@ flake8: ## Python linting via Flake8. find . -name venv -prune -o -name '*.py' -exec flake8 {} + yamllint: ## YAML linting via Yamllint. - find . \( -name *.yaml -o -name *.yml \) | xargs yamllint + find \( -name *.yaml -o -name *.yml \) | xargs yamllint -d "{ignore: docker-compose.yml}" black: ## Format checking via Black. black --check . --exclude venv/ @@ -30,6 +30,6 @@ pytest: ## Unit tests via Pytest. bandit: ## Security checks via Bandit. bandit --exclude ./venv --recursive --config .bandit.yml . -tests: pylint yamllint black pytest bandit pytest ## Format, lint, security and unit tests +tests: flake8 yamllint black pytest bandit ## Format, lint, security and unit tests # :%s/^[ ]\+/\t/g - automatically replace all tabs with spaces diff --git a/acl_auditor/auditor.py b/acl_auditor/auditor.py index 73bc3ec..7ee939f 100755 --- a/acl_auditor/auditor.py +++ b/acl_auditor/auditor.py @@ -2,7 +2,6 @@ import argparse import logging -import os import sys from pybatfish.client.commands import bf_session diff --git a/acl_auditor/helpers.py b/acl_auditor/helpers.py index e5efcba..ca08ae9 100644 --- a/acl_auditor/helpers.py +++ b/acl_auditor/helpers.py @@ -16,7 +16,7 @@ def write_file(filename, data): def read_yaml(filename): with open(filename) as file: - return yaml.load(file, Loader=yaml.FullLoader) + return yaml.safe_load(file) def return_rc(results): diff --git a/docker-compose.yml b/docker-compose.yml index 99932ae..2b340e1 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -1,7 +1,7 @@ version: '3.5' services: ntc-soteria: - container_name: acl_auditor + container_name: ntc-soteria build: context: . dockerfile: Dockerfile @@ -12,8 +12,8 @@ services: volumes: - ./data:/source/data batfish: - container_name: batfish - image: batfish/batfish:latest - ports: - - 9997:9997 - - 9996:9996 + container_name: batfish + image: batfish/batfish:latest + ports: + - 9997:9997 + - 9996:9996 diff --git a/poetry.lock b/poetry.lock index ae74f42..d3b84e6 100644 --- a/poetry.lock +++ b/poetry.lock @@ -46,6 +46,21 @@ dev = ["coverage", "hypothesis", "pympler", "pytest (>=4.3.0)", "six", "zope.int docs = ["sphinx", "zope.interface"] tests = ["coverage", "hypothesis", "pympler", "pytest (>=4.3.0)", "six", "zope.interface"] +[[package]] +category = "main" +description = "Security oriented static analyser for python code." +name = "bandit" +optional = false +python-versions = "*" +version = "1.6.2" + +[package.dependencies] +GitPython = ">=1.0.1" +PyYAML = ">=3.13" +colorama = ">=0.3.9" +six = ">=1.10.0" +stevedore = ">=1.20.0" + [[package]] category = "main" description = "The bidirectional mapping library for Python." @@ -112,7 +127,7 @@ version = "7.1.2" [[package]] category = "main" description = "Cross-platform colored terminal text." -marker = "sys_platform == \"win32\"" +marker = "sys_platform == \"win32\" or platform_system == \"Windows\"" name = "colorama" optional = false python-versions = ">=2.7, !=3.0.*, !=3.1.*, !=3.2.*, !=3.3.*, !=3.4.*" @@ -174,6 +189,28 @@ pyflakes = ">=2.2.0,<2.3.0" python = "<3.8" version = "*" +[[package]] +category = "main" +description = "Git Object Database" +name = "gitdb" +optional = false +python-versions = ">=3.4" +version = "4.0.5" + +[package.dependencies] +smmap = ">=3.0.1,<4" + +[[package]] +category = "main" +description = "Python Git Library" +name = "gitpython" +optional = false +python-versions = ">=3.4" +version = "3.1.7" + +[package.dependencies] +gitdb = ">=4.0.1,<5" + [[package]] category = "main" description = "Internationalized Domain Names in Applications (IDNA)" @@ -350,6 +387,14 @@ optional = false python-versions = ">=2.7, !=3.0.*, !=3.1.*, !=3.2.*, !=3.3.*, !=3.4.*" version = "0.8.0" +[[package]] +category = "main" +description = "Python Build Reasonableness" +name = "pbr" +optional = false +python-versions = "*" +version = "5.4.5" + [[package]] category = "main" description = "plugin and hook calling mechanisms for python" @@ -565,6 +610,25 @@ optional = false python-versions = ">=2.7, !=3.0.*, !=3.1.*, !=3.2.*" version = "1.15.0" +[[package]] +category = "main" +description = "A pure Python implementation of a sliding window memory map manager" +name = "smmap" +optional = false +python-versions = ">=2.7, !=3.0.*, !=3.1.*, !=3.2.*, !=3.3.*" +version = "3.0.4" + +[[package]] +category = "main" +description = "Manage dynamic plugins for Python applications" +name = "stevedore" +optional = false +python-versions = ">=3.6" +version = "2.0.1" + +[package.dependencies] +pbr = ">=2.0.0,<2.1.0 || >2.1.0" + [[package]] category = "main" description = "Pretty-print tabular data" @@ -621,6 +685,18 @@ optional = false python-versions = "*" version = "1.12.1" +[[package]] +category = "main" +description = "A linter for YAML files." +name = "yamllint" +optional = false +python-versions = ">=2.7, !=3.0.*, !=3.1.*, !=3.2.*, !=3.3.*" +version = "1.24.2" + +[package.dependencies] +pathspec = ">=0.5.3" +pyyaml = "*" + [[package]] category = "main" description = "Backport of pathlib-compatible object wrapper for zip files" @@ -635,7 +711,8 @@ docs = ["sphinx", "jaraco.packaging (>=3.2)", "rst.linker (>=1.9)"] testing = ["jaraco.itertools", "func-timeout"] [metadata] -content-hash = "ba83335e969a7d242e0892ff2d9a1e603d339a852cee34f771f1fc9a1e99afdb" +content-hash = "9b31b5e55f3839e392b50baeaab3d07b90b05e829a70ff247af6eaec4a04a178" +lock-version = "1.0" python-versions = "^3.6" [metadata.files] @@ -655,6 +732,10 @@ attrs = [ {file = "attrs-19.3.0-py2.py3-none-any.whl", hash = "sha256:08a96c641c3a74e44eb59afb61a24f2cb9f4d7188748e76ba4bb5edfa3cb7d1c"}, {file = "attrs-19.3.0.tar.gz", hash = "sha256:f7b7ce16570fe9965acd6d30101a28f62fb4a7f9e926b3bbc9b61f8b04247e72"}, ] +bandit = [ + {file = "bandit-1.6.2-py2.py3-none-any.whl", hash = "sha256:336620e220cf2d3115877685e264477ff9d9abaeb0afe3dc7264f55fa17a3952"}, + {file = "bandit-1.6.2.tar.gz", hash = "sha256:41e75315853507aa145d62a78a2a6c5e3240fe14ee7c601459d0df9418196065"}, +] bidict = [ {file = "bidict-0.19.0-py2.py3-none-any.whl", hash = "sha256:754756ef233b3c71984b185b7028fdd6f402382e84c9d3e89b0b866d40dd5d45"}, {file = "bidict-0.19.0.tar.gz", hash = "sha256:ef7461a18fb4a6f3ccaa73f43ffe2e98661fba4b43b647ec7886b3298c8e9187"}, @@ -694,6 +775,14 @@ flake8 = [ {file = "flake8-3.8.3-py2.py3-none-any.whl", hash = "sha256:15e351d19611c887e482fb960eae4d44845013cc142d42896e9862f775d8cf5c"}, {file = "flake8-3.8.3.tar.gz", hash = "sha256:f04b9fcbac03b0a3e58c0ab3a0ecc462e023a9faf046d57794184028123aa208"}, ] +gitdb = [ + {file = "gitdb-4.0.5-py3-none-any.whl", hash = "sha256:91f36bfb1ab7949b3b40e23736db18231bf7593edada2ba5c3a174a7b23657ac"}, + {file = "gitdb-4.0.5.tar.gz", hash = "sha256:c9e1f2d0db7ddb9a704c2a0217be31214e91a4fe1dea1efad19ae42ba0c285c9"}, +] +gitpython = [ + {file = "GitPython-3.1.7-py3-none-any.whl", hash = "sha256:fa3b92da728a457dd75d62bb5f3eb2816d99a7fe6c67398e260637a40e3fafb5"}, + {file = "GitPython-3.1.7.tar.gz", hash = "sha256:2db287d71a284e22e5c2846042d0602465c7434d910406990d5b74df4afb0858"}, +] idna = [ {file = "idna-2.9-py2.py3-none-any.whl", hash = "sha256:a068a21ceac8a4d63dbfd964670474107f541babbd2250d61922f029858365fa"}, {file = "idna-2.9.tar.gz", hash = "sha256:7588d1c14ae4c77d74036e8c22ff447b26d0fde8f007354fd48a7814db15b7cb"}, @@ -843,6 +932,10 @@ pathspec = [ {file = "pathspec-0.8.0-py2.py3-none-any.whl", hash = "sha256:7d91249d21749788d07a2d0f94147accd8f845507400749ea19c1ec9054a12b0"}, {file = "pathspec-0.8.0.tar.gz", hash = "sha256:da45173eb3a6f2a5a487efba21f050af2b41948be6ab52b6a1e3ff22bb8b7061"}, ] +pbr = [ + {file = "pbr-5.4.5-py2.py3-none-any.whl", hash = "sha256:579170e23f8e0c2f24b0de612f71f648eccb79fb1322c814ae6b3c07b5ba23e8"}, + {file = "pbr-5.4.5.tar.gz", hash = "sha256:07f558fece33b05caf857474a366dfcc00562bca13dd8b47b2b3e22d9f9bf55c"}, +] pluggy = [ {file = "pluggy-0.13.1-py2.py3-none-any.whl", hash = "sha256:966c145cd83c96502c3c3868f50408687b38434af77734af1e9ca461a4081d2d"}, {file = "pluggy-0.13.1.tar.gz", hash = "sha256:15b2acde666561e1298d71b523007ed7364de07029219b604cf808bfa1c765b0"}, @@ -923,6 +1016,7 @@ regex = [ {file = "regex-2020.6.8.tar.gz", hash = "sha256:e9b64e609d37438f7d6e68c2546d2cb8062f3adb27e6336bc129b51be20773ac"}, ] requests = [ + {file = "requests-2.23.0-py2.7.egg", hash = "sha256:5d2d0ffbb515f39417009a46c14256291061ac01ba8f875b90cad137de83beb4"}, {file = "requests-2.23.0-py2.py3-none-any.whl", hash = "sha256:43999036bfa82904b6af1d99e4882b560e5e2c68e5c4b0aa03b655f3d7d73fee"}, {file = "requests-2.23.0.tar.gz", hash = "sha256:b3f43d496c6daba4493e7c431722aeb7dbc6288f52a6e04e7b6023b0247817e6"}, ] @@ -967,6 +1061,14 @@ six = [ {file = "six-1.15.0-py2.py3-none-any.whl", hash = "sha256:8b74bedcbbbaca38ff6d7491d76f2b06b3592611af620f8426e82dddb04a5ced"}, {file = "six-1.15.0.tar.gz", hash = "sha256:30639c035cdb23534cd4aa2dd52c3bf48f06e5f4a941509c8bafd8ce11080259"}, ] +smmap = [ + {file = "smmap-3.0.4-py2.py3-none-any.whl", hash = "sha256:54c44c197c819d5ef1991799a7e30b662d1e520f2ac75c9efbeb54a742214cf4"}, + {file = "smmap-3.0.4.tar.gz", hash = "sha256:9c98bbd1f9786d22f14b3d4126894d56befb835ec90cef151af566c7e19b5d24"}, +] +stevedore = [ + {file = "stevedore-2.0.1-py3-none-any.whl", hash = "sha256:c4724f8d7b8f6be42130663855d01a9c2414d6046055b5a65ab58a0e38637688"}, + {file = "stevedore-2.0.1.tar.gz", hash = "sha256:609912b87df5ad338ff8e44d13eaad4f4170a65b79ae9cb0aa5632598994a1b7"}, +] tabulate = [ {file = "tabulate-0.8.7-py3-none-any.whl", hash = "sha256:ac64cb76d53b1231d364babcd72abbb16855adac7de6665122f97b593f1eb2ba"}, {file = "tabulate-0.8.7.tar.gz", hash = "sha256:db2723a20d04bcda8522165c73eea7c300eda74e0ce852d9022e0159d7895007"}, @@ -1009,6 +1111,10 @@ wcwidth = [ wrapt = [ {file = "wrapt-1.12.1.tar.gz", hash = "sha256:b62ffa81fb85f4332a4f609cab4ac40709470da05643a082ec1eb88e6d9b97d7"}, ] +yamllint = [ + {file = "yamllint-1.24.2-py2.py3-none-any.whl", hash = "sha256:ad3b0d30317dca005d7af99ff27248d459cae2d931a2ff06a134b67bcd405b30"}, + {file = "yamllint-1.24.2.tar.gz", hash = "sha256:40b68de6bacdccec1585dbd54072731b10da7fc2f9cfd96517a71f066208b61f"}, +] zipp = [ {file = "zipp-3.1.0-py3-none-any.whl", hash = "sha256:aa36550ff0c0b7ef7fa639055d797116ee891440eac1a56f378e2d3179e0320b"}, {file = "zipp-3.1.0.tar.gz", hash = "sha256:c599e4d75c98f6798c509911d08a22e6c021d074469042177c8c86fb92eefd96"}, diff --git a/pyproject.toml b/pyproject.toml index fd58582..7a93bcc 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -37,6 +37,8 @@ black = "^19.10b0" jinja2 = "^2.11.2" rope = "^0.17.0" tabulate = "^0.8.7" +yamllint = "^1.24.2" +bandit = "^1.6.2" [tool.poetry.dev-dependencies]