diff --git a/pyproject.toml b/pyproject.toml index dd67719..ecb672c 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -181,10 +181,24 @@ enable_error_code = [ "possibly-undefined", "truthy-bool", "truthy-iterable", + "unused-awaitable", + "explicit-override", + "mutable-override", + "unimported-reveal", "ignore-without-code", + "narrowed-type-not-subtype", ] untyped_calls_exclude = ["gvm.transforms"] follow_imports = "silent" +strict_concatenate = true +allow_redefinition = false +allow_untyped_globals = false +disallow_any_decorated = true +disallow_any_explicit = true +disallow_any_unimported = true +disallow_incomplete_defs = true +disallow_subclassing_any = true +warn_incomplete_stub = true [tool.pydantic-mypy] init_forbid_extra = true diff --git a/src/gvm_sync_targets/cli/__init__.py b/src/gvm_sync_targets/cli/__init__.py index dd7ef1d..a801a04 100644 --- a/src/gvm_sync_targets/cli/__init__.py +++ b/src/gvm_sync_targets/cli/__init__.py @@ -44,9 +44,20 @@ def gvm_sync_targets( ) as gmp: gmp = cast(Gmpv225, gmp) hosts = read_lines(hosts_file.read()) + host_map: dict[str, str | None] = {} + for entry in hosts: + if " " in entry: + k, v = entry.split(None, 1) + else: + k = entry + v = None + + host_map[k] = v + gmp.authenticate(username, password) - to_add = hosts.copy() + to_add = list(host_map.keys()) to_remove: list[str] = [] + to_update: list[tuple[str, str]] = [] for host in get_all_hosts(gmp, details=True): ips = { @@ -62,11 +73,16 @@ def gvm_sync_targets( for ip in ips: if ip in to_add: to_add.remove(ip) + if host.comment != host_map.get(ip): + to_update.append((host.uuid, ip)) else: to_remove.append(host.uuid) for ip in set(to_add): - gmp.create_host(ip) + gmp.create_host(ip, comment=host_map.get(ip)) + + for ip, uuid in set(to_update): + gmp.modify_host(uuid, comment=host_map.get(ip)) for uuid in set(to_remove): gmp.delete_host(uuid) diff --git a/src/gvm_sync_targets/models/__init__.py b/src/gvm_sync_targets/models/__init__.py index e8dd456..26faf4b 100644 --- a/src/gvm_sync_targets/models/__init__.py +++ b/src/gvm_sync_targets/models/__init__.py @@ -3,7 +3,7 @@ # SPDX-License-Identifier: MIT from collections.abc import Mapping -from typing import cast +from typing import cast, override from gvm.transforms import EtreeCheckCommandTransform @@ -66,6 +66,7 @@ class ModelTransform(EtreeCheckCommandTransform): def __init__(self) -> None: super().__init__() # type: ignore[no-untyped-call] + @override def __call__(self, data: str) -> Response: elem = cast(Element, super().__call__(data)) return _MODEL_MAP[elem.tag].from_xml_tree(elem) # type: ignore[arg-type] # etree.Element isn't a type but that's what this function expects