Code Duplication    Length = 79-82 lines in 2 locations

gvm/protocols/gmpv7.py 2 locations

@@ 897-978 (lines=82) @@
894
        cmd.add_element('copy', note_id)
895
        return self._send_xml_command(cmd)
896
897
    def create_override(self, text, nvt_oid, *, seconds_active=None, hosts=None,
898
                        port=None, result_id=None, severity=None,
899
                        new_severity=None, task_id=None, threat=None,
900
                        new_threat=None):
901
        """Create a new override
902
903
        Arguments:
904
            text (str): Text of the new override
905
            nvt_id (str): OID of the nvt to which override applies
906
            seconds_active (int, optional): Seconds override will be active.
907
                -1 on always, 0 off
908
            hosts (list, optional): A list of host addresses
909
            port (int, optional): Port to which the override applies
910
            result_id (str, optional): UUID of a result to which override
911
                applies
912
            severity (decimal, optional): Severity to which override applies
913
            new_severity (decimal, optional): New severity for result
914
            task_id (str, optional): UUID of task to which override applies
915
            threat (str, optional): Threat level to which override applies. One
916
                of High, Medium, Low, Alarm, Log or Debug. Will be converted to
917
                severity.
918
            new_threat (str, optional): New threat level for results. One
919
                of High, Medium, Low, Alarm, Log or Debug. Will be converted to
920
                new_severity.
921
922
        Returns:
923
            The response. See :py:meth:`send_command` for details.
924
        """
925
        if not text:
926
            raise RequiredArgument('create_override requires a text argument')
927
928
        if not nvt_oid:
929
            raise RequiredArgument('create_override requires a nvt_oid '
930
                                   'argument')
931
932
        cmd = XmlCommand('create_override')
933
        cmd.add_element('text', text)
934
        cmd.add_element('nvt', attrs={'oid': nvt_oid})
935
936
        if not seconds_active is None:
937
            cmd.add_element('active', str(seconds_active))
938
939
        if hosts:
940
            cmd.add_element('hosts', ','.join(hosts))
941
942
        if port:
943
            cmd.add_element('port', str(port))
944
945
        if result_id:
946
            cmd.add_element('result', attrs={'id': result_id})
947
948
        if severity:
949
            cmd.add_element('severity', str(severity))
950
951
        if new_severity:
952
            cmd.add_element('new_severity', str(new_severity))
953
954
        if task_id:
955
            cmd.add_element('task', attrs={'id': task_id})
956
957
        if threat is not None:
958
            if threat not in THREAD_TYPES:
959
                raise InvalidArgument(
960
                    'create_override threat argument {0} is invalid. threat'
961
                    'must be one of {1}'.format(threat, ', '.join(THREAD_TYPES))
962
                )
963
964
            cmd.add_element('threat', threat)
965
966
        if new_threat is not None:
967
            if new_threat not in THREAD_TYPES:
968
                raise InvalidArgument(
969
                    'create_override new_threat argument {0} is invalid. '
970
                    'new_threat must be one of {1}'.format(
971
                        new_threat,
972
                        ', '.join(THREAD_TYPES),
973
                    )
974
                )
975
976
            cmd.add_element('new_threat', new_threat)
977
978
        return self._send_xml_command(cmd)
979
980
    def clone_override(self, override_id):
981
        """Clone an existing override
@@ 4266-4344 (lines=79) @@
4263
4264
        return self._send_xml_command(cmd)
4265
4266
    def modify_override(self, override_id, text, *, seconds_active=None,
4267
                        hosts=None, port=None, result_id=None, severity=None,
4268
                        new_severity=None, task_id=None, threat=None,
4269
                        new_threat=None):
4270
        """Modifies an existing override.
4271
4272
        Arguments:
4273
            override_id (str): UUID of override to modify.
4274
            text (str): The text of the override.
4275
            seconds_active (int, optional): Seconds override will be active.
4276
                -1 on always, 0 off.
4277
            hosts (list, optional): A list of host addresses
4278
            port (int, optional): Port to which override applies.
4279
            result_id (str, optional): Result to which override applies.
4280
            severity (decimal, optional): Severity to which override applies.
4281
            new_severity (decimal, optional): New severity score for result.
4282
            task_id (str, optional): Task to which override applies.
4283
            threat (str, optional): Threat level to which override applies. One
4284
                of High, Medium, Low, Alarm, Log or Debug. Will be converted to
4285
                severity.
4286
            new_threat (str, optional): New threat level for results. One
4287
                of High, Medium, Low, Alarm, Log or Debug. Will be converted to
4288
                new_severity.
4289
4290
        Returns:
4291
            The response. See :py:meth:`send_command` for details.
4292
        """
4293
        if not override_id:
4294
            raise RequiredArgument('modify_override requires a override_id '
4295
                                   'argument')
4296
        if not text:
4297
            raise RequiredArgument('modify_override requires a text argument')
4298
4299
        cmd = XmlCommand('modify_override')
4300
        cmd.set_attribute('override_id', override_id)
4301
        cmd.add_element('text', text)
4302
4303
        if not seconds_active is None:
4304
            cmd.add_element('active', str(seconds_active))
4305
4306
        if hosts:
4307
            cmd.add_element('hosts', ','.join(hosts))
4308
4309
        if port:
4310
            cmd.add_element('port', str(port))
4311
4312
        if result_id:
4313
            cmd.add_element('result', attrs={'id': result_id})
4314
4315
        if severity:
4316
            cmd.add_element('severity', str(severity))
4317
4318
        if new_severity:
4319
            cmd.add_element('new_severity', str(new_severity))
4320
4321
        if task_id:
4322
            cmd.add_element('task', attrs={'id': task_id})
4323
4324
        if threat is not None:
4325
            if threat not in THREAD_TYPES:
4326
                raise InvalidArgument(
4327
                    'modify_override threat argument {0} is invalid. threat'
4328
                    'must be one of {1}'.format(threat, ', '.join(THREAD_TYPES))
4329
                )
4330
            cmd.add_element('threat', threat)
4331
4332
        if new_threat is not None:
4333
            if new_threat not in THREAD_TYPES:
4334
                raise InvalidArgument(
4335
                    'modify_override new_threat argument {0} is invalid. '
4336
                    'new_threat must be one of {1}'.format(
4337
                        new_threat,
4338
                        ', '.join(THREAD_TYPES),
4339
                    )
4340
                )
4341
4342
            cmd.add_element('new_threat', new_threat)
4343
4344
        return self._send_xml_command(cmd)
4345
4346
    def modify_permission(self, permission_id, *, comment=None, name=None,
4347
                          resource_id=None, resource_type=None,