Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 0 additions & 4 deletions .flake8

This file was deleted.

24 changes: 5 additions & 19 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,25 +1,11 @@
# See https://pre-commit.com for more information
# See https://pre-commit.com/hooks.html for more hooks
repos:
- repo: https://github.com/psf/black-pre-commit-mirror
rev: 24.4.2
- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.15.7
hooks:
- id: black
- id: ruff-check
args: ["--fix"]
exclude: netconan/default_reserved_words.py
- repo: https://github.com/PyCQA/isort
rev: 5.13.2
hooks:
- id: isort
args: ["--profile=black"]
exclude: netconan/default_reserved_words.py
- repo: https://github.com/PyCQA/autoflake
rev: v2.3.1
hooks:
- id: autoflake
args: ["--in-place", "--remove-all-unused-imports", "--remove-unused-variables"]
- id: ruff-format
exclude: netconan/default_reserved_words.py
- repo: https://github.com/pycqa/flake8
rev: 7.1.0
hooks:
- id: flake8
additional_dependencies: [flake8-docstrings]
5 changes: 3 additions & 2 deletions netconan/anonymize_files.py
Original file line number Diff line number Diff line change
Expand Up @@ -224,8 +224,9 @@ def _process_one(file_anonymizer: FileAnonymizer, in_path: str, out_path: str) -
_mkdirs(out_path)
if os.path.isdir(out_path):
raise ValueError(
"Cannot write output file; "
"output file is a directory ({})".format(out_path)
"Cannot write output file; output file is a directory ({})".format(
out_path
)
)

in_io: IO[str] = sys.stdin if use_stdin else open(in_path, "r")
Expand Down
1 change: 0 additions & 1 deletion netconan/default_pwd_regexes.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@
# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
# POSSIBILITY OF SUCH DAMAGE.


# A raw regex rule: (pattern_string, capture_group_index_or_None)
RegexRule = tuple[str, int | None]

Expand Down
6 changes: 3 additions & 3 deletions netconan/ip_anonymization.py
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,8 @@ def __init__(
self._preserve_addresses: list[ipaddress.IPv4Network] = []
if preserve_addresses is not None:
self._preserve_addresses = [
ipaddress.ip_network(n) for n in preserve_addresses # type: ignore[misc]
ipaddress.ip_network(n) # type: ignore[misc]
for n in preserve_addresses
]
# Make sure the prefixes are also preserved for preserved blocks, so
# anonymized addresses outside the block don't accidentally collide
Expand Down Expand Up @@ -259,8 +260,7 @@ def get_addr_pattern(cls) -> re.Pattern[str]:

@classmethod
def make_addr(cls, addr_str: str) -> ipaddress.IPv4Address:
"""
Return an IPv4 address from the given string.
"""Return an IPv4 address from the given string.

If the octets in `addr_str` have leading zeros, such as in 1.2.3.040,
those zeros will be ignored (1.2.3.40) -- they will NOT be interpreted
Expand Down
3 changes: 1 addition & 2 deletions netconan/netconan.py
Original file line number Diff line number Diff line change
Expand Up @@ -223,8 +223,7 @@ def main(argv: list[str] = sys.argv[1:]) -> None:
]
):
logging.warning(
"No anonymization options turned on, "
"no output file(s) will be generated."
"No anonymization options turned on, no output file(s) will be generated."
)
else:
anonymize_files(
Expand Down
8 changes: 5 additions & 3 deletions netconan/sensitive_item_removal.py
Original file line number Diff line number Diff line change
Expand Up @@ -424,9 +424,11 @@ def replace_matching_item(

output_line = compiled_re.sub(
# This is text preceding the password and shouldn't be anonymized
lambda m: (m.group("prefix") if "prefix" in m.groupdict() else "")
+ _anonymize_value(
m.group(sensitive_item_num), pwd_lookup, reserved_words, salt
lambda m: (
(m.group("prefix") if "prefix" in m.groupdict() else "")
+ _anonymize_value(
m.group(sensitive_item_num), pwd_lookup, reserved_words, salt
)
),
output_line,
)
Expand Down
9 changes: 8 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ dependencies = [
dynamic = ["version"]

[project.optional-dependencies]
dev = ["flake8<8.0.0", "flake8-docstrings<2.0.0", "pydocstyle<6.0.0"]
dev = ["ruff>=0.15"]
test = [
"pytest>=7",
"pytest-cov<6.0.0",
Expand All @@ -55,6 +55,13 @@ netconan = ["py.typed"]
[tool.setuptools.dynamic]
version = {attr = "netconan.__version__"}

[tool.ruff]
exclude = ["netconan/default_reserved_words.py"]

[tool.ruff.lint]
select = ["E", "W", "F", "D", "I"]
ignore = ["E203", "E501", "D203", "D213", "D401", "D413"]

[tool.pytest.ini_options]
addopts = "--cov=netconan"
testpaths = ["tests"]
Expand Down
3 changes: 1 addition & 2 deletions tests/unit/test_ip_anonymization.py
Original file line number Diff line number Diff line change
Expand Up @@ -305,8 +305,7 @@ def test_preserve_address_preserves_prefix():


def _cpl_v4(left, right):
"""
Return the common prefix length for two IPv4 addresses.
"""Return the common prefix length for two IPv4 addresses.

e.g.
_cpl_v4(1.0.0.1, 1.0.0.1) == 32
Expand Down
Loading