Skip to content

Commit

Permalink
Add bandit, remove pyroma
Browse files Browse the repository at this point in the history
  • Loading branch information
sbrunner committed Sep 22, 2021
1 parent d829110 commit e5b7a5b
Show file tree
Hide file tree
Showing 14 changed files with 44 additions and 17 deletions.
5 changes: 5 additions & 0 deletions .bandit.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
skips:
- B101 # Use of assert detected.
- B603 # subprocess call - check for execution of untrusted input
- B607 # Starting a process with a partial executable path
- B108 # Probable insecure usage of temp file/directory.
5 changes: 5 additions & 0 deletions .prospector.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -37,5 +37,10 @@ pep257:
mypy:
run: true

bandit:
run: true
options:
config: .bandit.yaml

mccabe:
run: false
3 changes: 2 additions & 1 deletion Pipfile
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,10 @@ google-auth-oauthlib = "==0.4.6"
jsonschema = "==3.2.0"
jsonschema-gentypes = "==0.9.4"
node-vm2 = "==0.4.0"
defusedxml = "==0.7.1"

[dev-packages]
prospector = {version = "==1.5.1", extras = ["with_bandit", "with_pyroma"]}
prospector = {version = "==1.5.1", extras = ["with_bandit", "with_mypy"]}
types-requests = "==2.25.6"
types-pyyaml = "==5.4.10"
types-setuptools = "==57.0.2"
Expand Down
10 changes: 9 additions & 1 deletion Pipfile.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion c2cciutils/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
import os.path
import pkgutil
import re
import subprocess
import subprocess # nosec
import sys
from typing import Any, Dict, List, Match, Optional, Pattern, Tuple, TypedDict, cast

Expand Down
2 changes: 1 addition & 1 deletion c2cciutils/audit.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import json
import os.path
import re
import subprocess
import subprocess # nosec
import sys
from argparse import Namespace
from typing import Any, Callable, Dict, List
Expand Down
12 changes: 6 additions & 6 deletions c2cciutils/checks.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import glob
import os
import re
import subprocess
import subprocess # nosec
import sys
from argparse import Namespace
from io import StringIO
Expand Down Expand Up @@ -246,7 +246,7 @@ def eof(config: None, full_config: c2cciutils.configuration.Configuration, args:
if (
subprocess.call(
f"git check-attr -a '{filename}' | grep ' text: set'",
shell=True,
shell=True, # nosec
stdout=FNULL,
)
== 0
Expand Down Expand Up @@ -300,7 +300,7 @@ def workflows(
files += glob.glob(".github/workflows/*.yml")
for filename in files:
with open(filename, encoding="utf-8") as open_file:
workflow = yaml.load(open_file, yaml.SafeLoader)
workflow = yaml.load(open_file, Loader=yaml.SafeLoader)

for name, job in workflow.get("jobs").items():
if job.get("runs-on") in config.get("images_blacklist", []):
Expand Down Expand Up @@ -367,7 +367,7 @@ def required_workflows(
continue

with open(filename, encoding="utf-8") as open_file:
workflow = yaml.load(open_file, yaml.SafeLoader)
workflow = yaml.load(open_file, Loader=yaml.SafeLoader)

for name, job in workflow.get("jobs").items():
if "if" in conf:
Expand Down Expand Up @@ -557,7 +557,7 @@ def _versions_audit(all_versions: Set[str], full_config: c2cciutils.configuratio
success = False
else:
with open(filename, encoding="utf-8") as open_file:
workflow = yaml.load(open_file, yaml.SafeLoader)
workflow = yaml.load(open_file, Loader=yaml.SafeLoader)

branch_to_version_re = c2cciutils.compile_re(full_config["version"].get("branch_to_version_re", []))

Expand Down Expand Up @@ -603,7 +603,7 @@ def _versions_rebuild(
success = False
else:
with open(filename, encoding="utf-8") as open_file:
workflow = yaml.load(open_file, yaml.SafeLoader)
workflow = yaml.load(open_file, Loader=yaml.SafeLoader)

for _, job in workflow.get("jobs").items():
rebuild_versions += _get_branch_matrix(job, branch_to_version_re)
Expand Down
6 changes: 3 additions & 3 deletions c2cciutils/publish.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
import datetime
import glob
import os
import pickle
import subprocess
import pickle # nosec
import subprocess # nosec
import sys
import uuid
from typing import Optional
Expand Down Expand Up @@ -68,7 +68,7 @@ def init_calendar_service(self) -> Credentials:
# time.
if os.path.exists(self.credentials_pickle_file):
with open(self.credentials_pickle_file, "rb") as token:
creds = pickle.load(token)
creds = pickle.load(token) # nosec
# If there are no (valid) credentials available, let the user log in.
if not creds or not creds.valid:
if creds and creds.expired and creds.refresh_token:
Expand Down
2 changes: 1 addition & 1 deletion c2cciutils/scripts/publish.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
import argparse
import os
import re
import subprocess
import subprocess # nosec
import sys
import tarfile
from typing import Match, Optional, cast
Expand Down
4 changes: 2 additions & 2 deletions c2cciutils/security.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
Read the table of versions from SECURITY.md.
"""

import xml.etree.ElementTree
import defusedxml.ElementTree
from typing import List, Optional

import markdown
Expand Down Expand Up @@ -40,7 +40,7 @@ def __init__(self, status: str):
for row in self.data:
row.append("")

def _pe(self, elem: xml.etree.ElementTree.Element) -> None:
def _pe(self, elem: defusedxml.ElementTree.Element) -> None:
"""
Parse the HTML table.
Expand Down
2 changes: 2 additions & 0 deletions example-project/.bandit.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
skips:
- B101 # Use of assert detected.
5 changes: 5 additions & 0 deletions example-project/.prospector.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -27,5 +27,10 @@ mypy:
check-untyped-defs: True
skip-version-check: True

bandit:
run: true
options:
config: .bandit.yaml

mccabe:
run: false
2 changes: 1 addition & 1 deletion example-project/Pipfile
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ url = "https://pypi.org/simple"
verify_ssl = true

[dev-packages]
prospector = {extras = ["with_mypy", "with_bandit", "with_pyroma"],version = "==1.5.1"}
prospector = {extras = ["with_mypy", "with_bandit"],version = "==1.5.1"}

[packages]

Expand Down
1 change: 1 addition & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,4 @@ google-auth-oauthlib==0.4.4
ruamel.yaml==0.17.16
jsonschema==3.2.0
jsonschema_gentypes==0.9.3
defusedxml==0.7.1

0 comments on commit e5b7a5b

Please sign in to comment.