Code Duplication    Length = 54-57 lines in 2 locations

gvm/protocols/gmpv7.py 2 locations

@@ 1082-1135 (lines=54) @@
1079
        cmd.add_element('copy', role_id)
1080
        return self._send_xml_command(cmd)
1081
1082
    def create_scanner(self, name, host, port, scanner_type, ca_pub,
1083
                       credential_id, *, comment=None):
1084
        """Create a new scanner
1085
1086
        Arguments:
1087
            name (str): Name of the scanner
1088
            host (str): The host of the scanner
1089
            port (str): The port of the scanner
1090
            scanner_type (str): Type of the scanner.
1091
                '1' for OSP, '2' for OpenVAS (classic) Scanner.
1092
            ca_pub (str): Certificate of CA to verify scanner certificate
1093
            credential_id (str): UUID of client certificate credential for the
1094
                scanner
1095
            comment (str, optional): Comment for the scanner
1096
1097
        Returns:
1098
            The response. See :py:meth:`send_command` for details.
1099
        """
1100
        if not name:
1101
            raise RequiredArgument('create_scanner requires a name argument')
1102
1103
        if not host:
1104
            raise RequiredArgument('create_scanner requires a host argument')
1105
1106
        if not port:
1107
            raise RequiredArgument('create_scanner requires a port argument')
1108
1109
        if not scanner_type:
1110
            raise RequiredArgument('create_scanner requires a scanner_type '
1111
                                   'argument')
1112
        if not ca_pub:
1113
            raise RequiredArgument('create_scanner requires a ca_pub argument')
1114
1115
        if not credential_id:
1116
            raise RequiredArgument('create_scanner requires a credential_id '
1117
                                   'argument')
1118
1119
        if scanner_type not in SCANNER_TYPES:
1120
            raise InvalidArgument('create_scanner requires a scanner_type '
1121
                                  'argument which must be either "1" for OSP '
1122
                                  'or "2" OpenVAS (Classic).')
1123
1124
        cmd = XmlCommand('create_scanner')
1125
        cmd.add_element('name', name)
1126
        cmd.add_element('host', host)
1127
        cmd.add_element('port', port)
1128
        cmd.add_element('type', scanner_type)
1129
        cmd.add_element('ca_pub', ca_pub)
1130
        cmd.add_element('credential', attrs={'id': str(credential_id)})
1131
1132
        if comment:
1133
            cmd.add_element('comment', comment)
1134
1135
        return self._send_xml_command(cmd)
1136
1137
    def clone_scanner(self, scanner_id):
1138
        """Clone an existing scanner
@@ 3924-3980 (lines=57) @@
3921
3922
        return self._send_xml_command(cmd)
3923
3924
    def modify_scanner(self, scanner_id, host, port, scanner_type, *,
3925
                       comment=None, name=None, ca_pub=None,
3926
                       credential_id=None):
3927
        """Modifies an existing scanner.
3928
3929
        Arguments:
3930
            scanner_id (str): UUID of scanner to modify.
3931
            host (str): Host of the scanner.
3932
            port (str): Port of the scanner.
3933
            scanner_type (str): Type of the scanner.
3934
                '1' for OSP, '2' for OpenVAS (classic) Scanner.
3935
            comment (str, optional): Comment on scanner.
3936
            name (str, optional): Name of scanner.
3937
            ca_pub (str, optional): Certificate of CA to verify scanner's
3938
                certificate.
3939
            credential_id (str, optional): UUID of the client certificate
3940
                credential for the Scanner.
3941
3942
        Returns:
3943
            The response. See :py:meth:`send_command` for details.
3944
        """
3945
        if not scanner_id:
3946
            raise RequiredArgument(
3947
                'modify_scanner requires a scanner_id argument')
3948
        if not host:
3949
            raise RequiredArgument('modify_scanner requires a host argument')
3950
        if not port:
3951
            raise RequiredArgument('modify_scanner requires a port argument')
3952
        if not scanner_type:
3953
            raise RequiredArgument('modify_scanner requires a scanner_type '
3954
                                   'argument')
3955
3956
        cmd = XmlCommand('modify_scanner')
3957
        cmd.set_attribute('scanner_id', scanner_id)
3958
        cmd.add_element('host', host)
3959
        cmd.add_element('port', port)
3960
3961
        if scanner_type not in SCANNER_TYPES:
3962
            raise InvalidArgument('modify_scanner requires a scanner_type '
3963
                                  'argument which must be either "1" for OSP '
3964
                                  'or "2" OpenVAS (Classic).')
3965
3966
        cmd.add_element('type', scanner_type)
3967
3968
        if comment:
3969
            cmd.add_element('comment', comment)
3970
3971
        if name:
3972
            cmd.add_element('name', name)
3973
3974
        if ca_pub:
3975
            cmd.add_element('ca_pub', ca_pub)
3976
3977
        if credential_id:
3978
            cmd.add_element('credential', attrs={'id': str(credential_id)})
3979
3980
        return self._send_xml_command(cmd)
3981
3982
    def modify_schedule(self, schedule_id, *, comment=None, name=None,
3983
                        first_time_minute=None, first_time_hour=None,