Skip to content

Commit ae0fe79

Browse files
committed
fix: misc fixes, use bandit
- use `bandit` instead of `codeql` - updates docstring - makes `value` positional only argument
1 parent 3142916 commit ae0fe79

File tree

10 files changed

+97
-97
lines changed

10 files changed

+97
-97
lines changed

.github/workflows/bandit.yml

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
# This workflow uses actions that are not certified by GitHub.
2+
# They are provided by a third-party and are governed by
3+
# separate terms of service, privacy policy, and support
4+
# documentation.
5+
6+
# Bandit is a security linter designed to find common security issues in Python code.
7+
# This action will run Bandit on your codebase.
8+
# The results of the scan will be found under the Security tab of your repository.
9+
10+
# https://github.com/marketplace/actions/bandit-scan is ISC licensed, by abirismyname
11+
# https://pypi.org/project/bandit/ is Apache v2.0 licensed, by PyCQA
12+
13+
name: Bandit
14+
on:
15+
workflow_dispatch:
16+
push:
17+
branches: ["master"]
18+
pull_request:
19+
# The branches below must be a subset of the branches above
20+
branches: ["master"]
21+
schedule:
22+
- cron: "28 12 * * 2"
23+
24+
jobs:
25+
bandit:
26+
permissions:
27+
contents: read # for actions/checkout to fetch code
28+
security-events: write # for github/codeql-action/upload-sarif to upload SARIF results
29+
actions: read # only required for a private repository by github/codeql-action/upload-sarif to get the Action run status
30+
31+
runs-on: ubuntu-latest
32+
steps:
33+
- uses: actions/checkout@v2
34+
- name: Bandit Scan
35+
uses: shundor/python-bandit-scan@9cc5aa4a006482b8a7f91134412df6772dbda22c
36+
with: # optional arguments
37+
# exit with 0, even with results found
38+
exit_zero: true # optional, default is DEFAULT
39+
# Github token of the repository (automatically created by Github)
40+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} # Needed to get PR information.
41+
# File or directory to run bandit on
42+
path: ./validators # optional, default is .
43+
# Report only issues of a given severity level or higher. Can be LOW, MEDIUM or HIGH. Default is UNDEFINED (everything)
44+
# level: # optional, default is UNDEFINED
45+
# Report only issues of a given confidence level or higher. Can be LOW, MEDIUM or HIGH. Default is UNDEFINED (everything)
46+
# confidence: # optional, default is UNDEFINED
47+
# comma-separated list of paths (glob patterns supported) to exclude from scan (note that these are in addition to the excluded paths provided in the config file) (default: .svn,CVS,.bzr,.hg,.git,__pycache__,.tox,.eggs,*.egg)
48+
excluded_paths: tests,docs,.github # optional, default is DEFAULT
49+
# comma-separated list of test IDs to skip
50+
# skips: # optional, default is DEFAULT
51+
# path to a .bandit file that supplies command line arguments
52+
# ini_path: # optional, default is DEFAULT

.github/workflows/codeql.yml

Lines changed: 0 additions & 77 deletions
This file was deleted.

poetry.lock

Lines changed: 14 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pyproject.toml

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@ classifiers = [
2828
python = "^3.9"
2929

3030
[tool.poetry.group.dev.dependencies]
31-
bandit = "^1.7.4"
3231
black = "^23.1.0"
3332
flake8 = "^6.0.0"
3433
flake8-docstrings = "^1.7.0"
@@ -39,6 +38,9 @@ setuptools = "^67.2.0"
3938
[tool.poetry.group.tests.dependencies]
4039
pytest = "^7.2.2"
4140

41+
[tool.poetry.group.sast.dependencies]
42+
bandit = { extras = ["toml"], version = "^1.7.4" }
43+
4244
[tool.poetry.group.docs.dependencies]
4345
mkdocs = "^1.4.2"
4446
mkdocs-material = "^9.1.1"
@@ -56,6 +58,9 @@ build-backend = "poetry.core.masonry.api"
5658
line-length = 100
5759
target-version = ['py39', 'py310', 'py311']
5860

61+
[tool.bandit]
62+
exclude_dirs = [".github", ".pytest_cache", ".tox", ".vscode", "tests", "docs"]
63+
5964
[tool.tox]
6065
legacy_tox_ini = '''
6166
[tox]

tests/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
"""Tests."""

validators/hashes.py

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99

1010

1111
@validator
12-
def md5(value: str):
12+
def md5(value: str, /):
1313
"""Return whether or not given value is a valid MD5 hash.
1414
1515
Examples:
@@ -19,7 +19,8 @@ def md5(value: str):
1919
# Output: ValidationFailure(func=md5, args={'value': '900zz11'})
2020
2121
Args:
22-
value: MD5 string to validate.
22+
value:
23+
MD5 string to validate.
2324
2425
Returns:
2526
(Literal[True]):
@@ -33,7 +34,7 @@ def md5(value: str):
3334

3435

3536
@validator
36-
def sha1(value: str):
37+
def sha1(value: str, /):
3738
"""Return whether or not given value is a valid SHA1 hash.
3839
3940
Examples:
@@ -43,7 +44,8 @@ def sha1(value: str):
4344
# Output: ValidationFailure(func=sha1, args={'value': '900zz11'})
4445
4546
Args:
46-
value: SHA1 string to validate.
47+
value:
48+
SHA1 string to validate.
4749
4850
Returns:
4951
(Literal[True]):
@@ -57,7 +59,7 @@ def sha1(value: str):
5759

5860

5961
@validator
60-
def sha224(value: str):
62+
def sha224(value: str, /):
6163
"""Return whether or not given value is a valid SHA224 hash.
6264
6365
Examples:
@@ -67,7 +69,8 @@ def sha224(value: str):
6769
# Output: ValidationFailure(func=sha224, args={'value': '900zz11'})
6870
6971
Args:
70-
value: SHA224 string to validate.
72+
value:
73+
SHA224 string to validate.
7174
7275
Returns:
7376
(Literal[True]):
@@ -81,7 +84,7 @@ def sha224(value: str):
8184

8285

8386
@validator
84-
def sha256(value: str):
87+
def sha256(value: str, /):
8588
"""Return whether or not given value is a valid SHA256 hash.
8689
8790
Examples:
@@ -94,7 +97,8 @@ def sha256(value: str):
9497
# Output: ValidationFailure(func=sha256, args={'value': '900zz11'})
9598
9699
Args:
97-
value: SHA256 string to validate.
100+
value:
101+
SHA256 string to validate.
98102
99103
Returns:
100104
(Literal[True]):
@@ -108,7 +112,7 @@ def sha256(value: str):
108112

109113

110114
@validator
111-
def sha512(value: str):
115+
def sha512(value: str, /):
112116
"""Return whether or not given value is a valid SHA512 hash.
113117
114118
Examples:
@@ -122,7 +126,8 @@ def sha512(value: str):
122126
# Output: ValidationFailure(func=sha512, args={'value': '900zz11'})
123127
124128
Args:
125-
value: SHA512 string to validate.
129+
value:
130+
SHA512 string to validate.
126131
127132
Returns:
128133
(Literal[True]):

validators/iban.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ def _mod_check(value: str):
2121

2222

2323
@validator
24-
def iban(value: str):
24+
def iban(value: str, /):
2525
"""Return whether or not given value is a valid IBAN code.
2626
2727
Examples:
@@ -31,7 +31,8 @@ def iban(value: str):
3131
# Output: ValidationFailure(func=iban, ...)
3232
3333
Args:
34-
value: IBAN string to validate.
34+
value:
35+
IBAN string to validate.
3536
3637
Returns:
3738
(Literal[True]):

validators/mac_address.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99

1010

1111
@validator
12-
def mac_address(value: str):
12+
def mac_address(value: str, /):
1313
"""Return whether or not given value is a valid MAC address.
1414
1515
This validator is based on [WTForms MacAddress validator][1].
@@ -24,7 +24,7 @@ def mac_address(value: str):
2424
2525
Args:
2626
value:
27-
A string to validate.
27+
MAC address string to validate.
2828
2929
Returns:
3030
(Literal[True]):

validators/slug.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99

1010

1111
@validator
12-
def slug(value: str):
12+
def slug(value: str, /):
1313
"""Validate whether or not given value is valid slug.
1414
1515
Valid slug can contain only lowercase alphanumeric characters and hyphens.
@@ -23,7 +23,7 @@ def slug(value: str):
2323
2424
Args:
2525
value:
26-
A string to validate.
26+
Slug string to validate.
2727
2828
Returns:
2929
(Literal[True]):

validators/uuid.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010

1111

1212
@validator
13-
def uuid(value: Union[str, UUID]):
13+
def uuid(value: Union[str, UUID], /):
1414
"""Return whether or not given value is a valid UUID-v4 string.
1515
1616
This validator is based on [WTForms UUID validator][1].
@@ -25,7 +25,7 @@ def uuid(value: Union[str, UUID]):
2525
2626
Args:
2727
value:
28-
A string or UUID object to validate.
28+
UUID string or object to validate.
2929
3030
Returns:
3131
(Literal[True]):

0 commit comments

Comments
 (0)