Skip to content

Commit

Permalink
style: clean up issues
Browse files Browse the repository at this point in the history
  • Loading branch information
linuxdaemon committed May 20, 2024
1 parent 18ba5ba commit b973c30
Show file tree
Hide file tree
Showing 3 changed files with 87 additions and 29 deletions.
2 changes: 0 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -113,13 +113,11 @@ extend-safe-fixes = [
"D200",
]
ignore = [
"TRY003", # TODO(aspen): Switch to custom exceptions
"ANN101", # Due to be deprecated in ruff
"ANN102", # Due to be deprecated in ruff
"COM812", # Conflicts with formatter
"ISC001", # Conflicts with formatter
"EXE002", # pre-commit does it better, works with SMB shares
"FA100",
"D",
]
select = ["ALL"]
Expand Down
15 changes: 9 additions & 6 deletions src/gvm_sync_targets/cli/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,19 @@
# SPDX-License-Identifier: MIT

import logging
from typing import TextIO
from typing import TYPE_CHECKING, TextIO

import click
from gvm.connections import DebugConnection, UnixSocketConnection
from gvm.protocols.gmp import Gmp

from gvm_sync_targets import __version__
from gvm_sync_targets.models import GetTargetsResponse, ModelTransform
from gvm_sync_targets.models.targets_response import CreateTargetResponse
from gvm_sync_targets.util import get_all_hosts, read_lines

if TYPE_CHECKING:
from gvm_sync_targets.models.targets_response import CreateTargetResponse


@click.group(
context_settings={
Expand Down Expand Up @@ -82,10 +84,11 @@ def gvm_sync_targets(

target = resp.targets[0]
click.echo(target)
if target.tasks:
task_ids = [task.uuid for task in target.tasks.tasks]
else:
task_ids = []
task_ids = (
[task.uuid for task in target.tasks.tasks]
if target.tasks
else []
)

for task_id in task_ids:
gmp.modify_task(task_id, target_id=new_target.uuid)
Expand Down
99 changes: 78 additions & 21 deletions tests/gvm_sync_targets/models/targets_response_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,27 +85,63 @@
<name></name>
<trash>0</trash>
</smb_credential>
<esxi_credential id=""><name></name><trash>0</trash></esxi_credential>
<snmp_credential id=""><name></name><trash>0</trash></snmp_credential>
<ssh_elevate_credential id=""><name></name><trash>0</trash></ssh_elevate_credential>
<esxi_credential id="">
<name></name>
<trash>0</trash>
</esxi_credential>
<snmp_credential id="">
<name></name>
<trash>0</trash>
</snmp_credential>
<ssh_elevate_credential id="">
<name></name>
<trash>0</trash>
</ssh_elevate_credential>
<reverse_lookup_only>0</reverse_lookup_only>
<reverse_lookup_unify>0</reverse_lookup_unify>
<alive_tests>Scan Config Default</alive_tests><allow_simultaneous_ips>1</allow_simultaneous_ips>
<alive_tests>Scan Config Default</alive_tests>
<allow_simultaneous_ips>1</allow_simultaneous_ips>
</target>
<target id="1a11fc20-b767-4407-82ee-e87fbddbc74a">
<owner><name>admin</name></owner><name>Unnamed</name>
<comment></comment><creation_time>2024-05-15T20:41:23Z</creation_time>
<modification_time>2024-05-15T20:41:23Z</modification_time>
<writable>1</writable><in_use>1</in_use>
<permissions><permission><name>Everything</name></permission></permissions>
<permissions>
<permission><name>Everything</name></permission>
</permissions>
<hosts>1.2.3.4, 1::1</hosts>
<exclude_hosts></exclude_hosts><max_hosts>41</max_hosts>
<port_list id="33d0cd82-57c6-11e1-8ed1-406186ea4fc5"><name>All IANA assigned TCP</name><trash>0</trash></port_list>
<ssh_credential id="416d4541-8cb4-4745-ba27-7d509cec9455"><name>SSH auth</name><port>22</port><trash>0</trash></ssh_credential>
<smb_credential id=""><name></name><trash>0</trash></smb_credential><esxi_credential id=""><name></name><trash>0</trash></esxi_credential>
<snmp_credential id=""><name></name><trash>0</trash></snmp_credential><ssh_elevate_credential id=""><name></name><trash>0</trash></ssh_elevate_credential>
<reverse_lookup_only>0</reverse_lookup_only><reverse_lookup_unify>0</reverse_lookup_unify>
<alive_tests>Scan Config Default</alive_tests><allow_simultaneous_ips>1</allow_simultaneous_ips>
<exclude_hosts></exclude_hosts>
<max_hosts>41</max_hosts>
<port_list id="33d0cd82-57c6-11e1-8ed1-406186ea4fc5">
<name>All IANA assigned TCP</name>
<trash>0</trash>
</port_list>
<ssh_credential id="416d4541-8cb4-4745-ba27-7d509cec9455">
<name>SSH auth</name>
<port>22</port>
<trash>0</trash>
</ssh_credential>
<smb_credential id="">
<name></name>
<trash>0</trash>
</smb_credential>
<esxi_credential id="">
<name></name>
<trash>0</trash>
</esxi_credential>
<snmp_credential id="">
<name></name>
<trash>0</trash>
</snmp_credential>
<ssh_elevate_credential id="">
<name></name>
<trash>0</trash>
</ssh_elevate_credential>
<reverse_lookup_only>0</reverse_lookup_only>
<reverse_lookup_unify>0</reverse_lookup_unify>
<alive_tests>Scan Config Default</alive_tests>
<allow_simultaneous_ips>1</allow_simultaneous_ips>
</target>
<filters id="">
<term>first=1 rows=10 sort=name</term>
Expand Down Expand Up @@ -227,25 +263,46 @@
</smb_credential>
<esxi_credential id=""><name></name><trash>0</trash></esxi_credential>
<snmp_credential id=""><name></name><trash>0</trash></snmp_credential>
<ssh_elevate_credential id=""><name></name><trash>0</trash></ssh_elevate_credential>
<ssh_elevate_credential id="">
<name></name><trash>0</trash>
</ssh_elevate_credential>
<reverse_lookup_only>0</reverse_lookup_only>
<reverse_lookup_unify>0</reverse_lookup_unify>
<alive_tests>Scan Config Default</alive_tests><allow_simultaneous_ips>1</allow_simultaneous_ips>
<alive_tests>Scan Config Default</alive_tests>
<allow_simultaneous_ips>1</allow_simultaneous_ips>
</target>
<target id="1a11fc20-b767-4407-82ee-e87fbddbc74a">
<owner><name>admin</name></owner><name>Unnamed</name>
<comment></comment><creation_time>2024-05-15T20:41:23Z</creation_time>
<modification_time>2024-05-15T20:41:23Z</modification_time>
<writable>1</writable><in_use>1</in_use>
<permissions><permission><name>Everything</name></permission></permissions>
<permissions>
<permission><name>Everything</name></permission>
</permissions>
<hosts>1.2.3.4, 1::1</hosts>
<exclude_hosts></exclude_hosts><max_hosts>41</max_hosts>
<port_list id="33d0cd82-57c6-11e1-8ed1-406186ea4fc5"><name>All IANA assigned TCP</name><trash>0</trash></port_list>
<ssh_credential id="416d4541-8cb4-4745-ba27-7d509cec9455"><name>SSH auth</name><port>22</port><trash>0</trash></ssh_credential>
<smb_credential id=""><name></name><trash>0</trash></smb_credential><esxi_credential id=""><name></name><trash>0</trash></esxi_credential>
<snmp_credential id=""><name></name><trash>0</trash></snmp_credential><ssh_elevate_credential id=""><name></name><trash>0</trash></ssh_elevate_credential>
<reverse_lookup_only>0</reverse_lookup_only><reverse_lookup_unify>0</reverse_lookup_unify>
<alive_tests>Scan Config Default</alive_tests><allow_simultaneous_ips>1</allow_simultaneous_ips>
<port_list id="33d0cd82-57c6-11e1-8ed1-406186ea4fc5">
<name>All IANA assigned TCP</name><trash>0</trash>
</port_list>
<ssh_credential id="416d4541-8cb4-4745-ba27-7d509cec9455">
<name>SSH auth</name><port>22</port><trash>0</trash>
</ssh_credential>
<smb_credential id="">
<name></name><trash>0</trash>
</smb_credential>
<esxi_credential id="">
<name></name><trash>0</trash>
</esxi_credential>
<snmp_credential id="">
<name></name><trash>0</trash>
</snmp_credential>
<ssh_elevate_credential id="">
<name></name><trash>0</trash>
</ssh_elevate_credential>
<reverse_lookup_only>0</reverse_lookup_only>
<reverse_lookup_unify>0</reverse_lookup_unify>
<alive_tests>Scan Config Default</alive_tests>
<allow_simultaneous_ips>1</allow_simultaneous_ips>
</target>
<filters id="">
<term>first=1 rows=10 sort=name</term>
Expand Down

0 comments on commit b973c30

Please sign in to comment.