Code Duplication    Length = 102-102 lines in 2 locations

gvm/protocols/gmpv7/gmpv7.py 1 location

@@ 5849-5950 (lines=102) @@
5846
5847
        return self._send_xml_command(cmd)
5848
5849
    def modify_target(
5850
        self,
5851
        target_id: str,
5852
        *,
5853
        name: Optional[str] = None,
5854
        comment: Optional[str] = None,
5855
        hosts: Optional[List[str]] = None,
5856
        exclude_hosts: Optional[List[str]] = None,
5857
        ssh_credential_id: Optional[str] = None,
5858
        ssh_credential_port: Optional[bool] = None,
5859
        smb_credential_id: Optional[str] = None,
5860
        esxi_credential_id: Optional[str] = None,
5861
        snmp_credential_id: Optional[str] = None,
5862
        alive_test: Optional[AliveTest] = None,
5863
        reverse_lookup_only: Optional[bool] = None,
5864
        reverse_lookup_unify: Optional[bool] = None,
5865
        port_list_id: Optional[str] = None,
5866
    ) -> Any:
5867
        """Modifies an existing target.
5868
5869
        Arguments:
5870
            target_id: ID of target to modify.
5871
            comment: Comment on target.
5872
            name: Name of target.
5873
            hosts: List of target hosts.
5874
            exclude_hosts: A list of hosts to exclude.
5875
            ssh_credential_id: UUID of SSH credential to use on target.
5876
            ssh_credential_port: The port to use for ssh credential
5877
            smb_credential_id: UUID of SMB credential to use on target.
5878
            esxi_credential_id: UUID of ESXi credential to use on target.
5879
            snmp_credential_id: UUID of SNMP credential to use on target.
5880
            port_list_id: UUID of port list describing ports to scan.
5881
            alive_test: Which alive tests to use.
5882
            reverse_lookup_only: Whether to scan only hosts that have names.
5883
            reverse_lookup_unify: Whether to scan only one IP when multiple IPs
5884
                have the same name.
5885
5886
        Returns:
5887
            The response. See :py:meth:`send_command` for details.
5888
        """
5889
        if not target_id:
5890
            raise RequiredArgument(
5891
                function=self.modify_target.__name__, argument='target_id'
5892
            )
5893
5894
        cmd = XmlCommand("modify_target")
5895
        cmd.set_attribute("target_id", target_id)
5896
5897
        if comment:
5898
            cmd.add_element("comment", comment)
5899
5900
        if name:
5901
            cmd.add_element("name", name)
5902
5903
        if hosts:
5904
            cmd.add_element("hosts", _to_comma_list(hosts))
5905
            if exclude_hosts is None:
5906
                exclude_hosts = ['']
5907
5908
        if exclude_hosts:
5909
            cmd.add_element("exclude_hosts", _to_comma_list(exclude_hosts))
5910
5911
        if alive_test:
5912
            if not isinstance(alive_test, AliveTest):
5913
                raise InvalidArgumentType(
5914
                    function=self.modify_target.__name__,
5915
                    argument='alive_test',
5916
                    arg_type=AliveTest.__name__,
5917
                )
5918
            cmd.add_element("alive_tests", alive_test.value)
5919
5920
        if ssh_credential_id:
5921
            _xmlssh = cmd.add_element(
5922
                "ssh_credential", attrs={"id": ssh_credential_id}
5923
            )
5924
5925
            if ssh_credential_port:
5926
                _xmlssh.add_element("port", str(ssh_credential_port))
5927
5928
        if smb_credential_id:
5929
            cmd.add_element("smb_credential", attrs={"id": smb_credential_id})
5930
5931
        if esxi_credential_id:
5932
            cmd.add_element("esxi_credential", attrs={"id": esxi_credential_id})
5933
5934
        if snmp_credential_id:
5935
            cmd.add_element("snmp_credential", attrs={"id": snmp_credential_id})
5936
5937
        if reverse_lookup_only is not None:
5938
            cmd.add_element(
5939
                "reverse_lookup_only", _to_bool(reverse_lookup_only)
5940
            )
5941
5942
        if reverse_lookup_unify is not None:
5943
            cmd.add_element(
5944
                "reverse_lookup_unify", _to_bool(reverse_lookup_unify)
5945
            )
5946
5947
        if port_list_id:
5948
            cmd.add_element("port_list", attrs={"id": port_list_id})
5949
5950
        return self._send_xml_command(cmd)
5951
5952
    def modify_task(
5953
        self,

gvm/protocols/gmpv208/gmpv208.py 1 location

@@ 6810-6911 (lines=102) @@
6807
6808
        return self._send_xml_command(cmd)
6809
6810
    def modify_target(
6811
        self,
6812
        target_id: str,
6813
        *,
6814
        name: Optional[str] = None,
6815
        comment: Optional[str] = None,
6816
        hosts: Optional[List[str]] = None,
6817
        exclude_hosts: Optional[List[str]] = None,
6818
        ssh_credential_id: Optional[str] = None,
6819
        ssh_credential_port: Optional[bool] = None,
6820
        smb_credential_id: Optional[str] = None,
6821
        esxi_credential_id: Optional[str] = None,
6822
        snmp_credential_id: Optional[str] = None,
6823
        alive_test: Optional[AliveTest] = None,
6824
        reverse_lookup_only: Optional[bool] = None,
6825
        reverse_lookup_unify: Optional[bool] = None,
6826
        port_list_id: Optional[str] = None,
6827
    ) -> Any:
6828
        """Modifies an existing target.
6829
6830
        Arguments:
6831
            target_id: ID of target to modify.
6832
            comment: Comment on target.
6833
            name: Name of target.
6834
            hosts: List of target hosts.
6835
            exclude_hosts: A list of hosts to exclude.
6836
            ssh_credential_id: UUID of SSH credential to use on target.
6837
            ssh_credential_port: The port to use for ssh credential
6838
            smb_credential_id: UUID of SMB credential to use on target.
6839
            esxi_credential_id: UUID of ESXi credential to use on target.
6840
            snmp_credential_id: UUID of SNMP credential to use on target.
6841
            port_list_id: UUID of port list describing ports to scan.
6842
            alive_test: Which alive tests to use.
6843
            reverse_lookup_only: Whether to scan only hosts that have names.
6844
            reverse_lookup_unify: Whether to scan only one IP when multiple IPs
6845
                have the same name.
6846
6847
        Returns:
6848
            The response. See :py:meth:`send_command` for details.
6849
        """
6850
        if not target_id:
6851
            raise RequiredArgument(
6852
                function=self.modify_target.__name__, argument='target_id'
6853
            )
6854
6855
        cmd = XmlCommand("modify_target")
6856
        cmd.set_attribute("target_id", target_id)
6857
6858
        if comment:
6859
            cmd.add_element("comment", comment)
6860
6861
        if name:
6862
            cmd.add_element("name", name)
6863
6864
        if hosts:
6865
            cmd.add_element("hosts", _to_comma_list(hosts))
6866
            if exclude_hosts is None:
6867
                exclude_hosts = ['']
6868
6869
        if exclude_hosts:
6870
            cmd.add_element("exclude_hosts", _to_comma_list(exclude_hosts))
6871
6872
        if alive_test:
6873
            if not isinstance(alive_test, AliveTest):
6874
                raise InvalidArgumentType(
6875
                    function=self.modify_target.__name__,
6876
                    argument='alive_test',
6877
                    arg_type=AliveTest.__name__,
6878
                )
6879
            cmd.add_element("alive_tests", alive_test.value)
6880
6881
        if ssh_credential_id:
6882
            _xmlssh = cmd.add_element(
6883
                "ssh_credential", attrs={"id": ssh_credential_id}
6884
            )
6885
6886
            if ssh_credential_port:
6887
                _xmlssh.add_element("port", str(ssh_credential_port))
6888
6889
        if smb_credential_id:
6890
            cmd.add_element("smb_credential", attrs={"id": smb_credential_id})
6891
6892
        if esxi_credential_id:
6893
            cmd.add_element("esxi_credential", attrs={"id": esxi_credential_id})
6894
6895
        if snmp_credential_id:
6896
            cmd.add_element("snmp_credential", attrs={"id": snmp_credential_id})
6897
6898
        if reverse_lookup_only is not None:
6899
            cmd.add_element(
6900
                "reverse_lookup_only", _to_bool(reverse_lookup_only)
6901
            )
6902
6903
        if reverse_lookup_unify is not None:
6904
            cmd.add_element(
6905
                "reverse_lookup_unify", _to_bool(reverse_lookup_unify)
6906
            )
6907
6908
        if port_list_id:
6909
            cmd.add_element("port_list", attrs={"id": port_list_id})
6910
6911
        return self._send_xml_command(cmd)
6912
6913
    def modify_task(
6914
        self,