Code Duplication    Length = 126-126 lines in 2 locations

gvm/protocols/gmpv208/gmpv208.py 1 location

@@ 6881-7006 (lines=126) @@
6878
6879
        return self._send_xml_command(cmd)
6880
6881
    def modify_task(
6882
        self,
6883
        task_id: str,
6884
        *,
6885
        name: Optional[str] = None,
6886
        config_id: Optional[str] = None,
6887
        target_id: Optional[str] = None,
6888
        scanner_id: Optional[str] = None,
6889
        alterable: Optional[bool] = None,
6890
        hosts_ordering: Optional[HostsOrdering] = None,
6891
        schedule_id: Optional[str] = None,
6892
        schedule_periods: Optional[int] = None,
6893
        comment: Optional[str] = None,
6894
        alert_ids: Optional[List[str]] = None,
6895
        observers: Optional[List[str]] = None,
6896
        preferences: Optional[dict] = None,
6897
    ) -> Any:
6898
        """Modifies an existing task.
6899
6900
        Arguments:
6901
            task_id: UUID of task to modify.
6902
            name: The name of the task.
6903
            config_id: UUID of scan config to use by the task
6904
            target_id: UUID of target to be scanned
6905
            scanner_id: UUID of scanner to use for scanning the target
6906
            comment: The comment on the task.
6907
            alert_ids: List of UUIDs for alerts to be applied to the task
6908
            hosts_ordering: The order hosts are scanned in
6909
            schedule_id: UUID of a schedule when the task should be run.
6910
            schedule_periods: A limit to the number of times the task will be
6911
                scheduled, or 0 for no limit.
6912
            observers: List of names or ids of users which should be allowed to
6913
                observe this task
6914
            preferences: Name/Value pairs of scanner preferences.
6915
6916
        Returns:
6917
            The response. See :py:meth:`send_command` for details.
6918
        """
6919
        if not task_id:
6920
            raise RequiredArgument(
6921
                function=self.modify_task.__name__, argument='task_id argument'
6922
            )
6923
6924
        cmd = XmlCommand("modify_task")
6925
        cmd.set_attribute("task_id", task_id)
6926
6927
        if name:
6928
            cmd.add_element("name", name)
6929
6930
        if comment:
6931
            cmd.add_element("comment", comment)
6932
6933
        if config_id:
6934
            cmd.add_element("config", attrs={"id": config_id})
6935
6936
        if target_id:
6937
            cmd.add_element("target", attrs={"id": target_id})
6938
6939
        if alterable is not None:
6940
            cmd.add_element("alterable", _to_bool(alterable))
6941
6942
        if hosts_ordering:
6943
            if not isinstance(hosts_ordering, HostsOrdering):
6944
                raise InvalidArgumentType(
6945
                    function=self.modify_task.__name__,
6946
                    argument='hosts_ordering',
6947
                    arg_type=HostsOrdering.__name__,
6948
                )
6949
            cmd.add_element("hosts_ordering", hosts_ordering.value)
6950
6951
        if scanner_id:
6952
            cmd.add_element("scanner", attrs={"id": scanner_id})
6953
6954
        if schedule_id:
6955
            cmd.add_element("schedule", attrs={"id": schedule_id})
6956
6957
        if schedule_periods is not None:
6958
            if (
6959
                not isinstance(schedule_periods, numbers.Integral)
6960
                or schedule_periods < 0
6961
            ):
6962
                raise InvalidArgument(
6963
                    "schedule_periods must be an integer greater or equal "
6964
                    "than 0"
6965
                )
6966
            cmd.add_element("schedule_periods", str(schedule_periods))
6967
6968
        if alert_ids is not None:
6969
            if not _is_list_like(alert_ids):
6970
                raise InvalidArgumentType(
6971
                    function=self.modify_task.__name__,
6972
                    argument='alert_ids',
6973
                    arg_type='list',
6974
                )
6975
6976
            if len(alert_ids) == 0:
6977
                cmd.add_element("alert", attrs={"id": "0"})
6978
            else:
6979
                for alert in alert_ids:
6980
                    cmd.add_element("alert", attrs={"id": str(alert)})
6981
6982
        if observers is not None:
6983
            if not _is_list_like(observers):
6984
                raise InvalidArgumentType(
6985
                    function=self.modify_task.__name__,
6986
                    argument='observers',
6987
                    arg_type='list',
6988
                )
6989
6990
            cmd.add_element("observers", _to_comma_list(observers))
6991
6992
        if preferences is not None:
6993
            if not isinstance(preferences, collections.abc.Mapping):
6994
                raise InvalidArgumentType(
6995
                    function=self.modify_task.__name__,
6996
                    argument='preferences',
6997
                    arg_type=collections.abc.Mapping.__name__,
6998
                )
6999
7000
            _xmlprefs = cmd.add_element("preferences")
7001
            for pref_name, pref_value in preferences.items():
7002
                _xmlpref = _xmlprefs.add_element("preference")
7003
                _xmlpref.add_element("scanner_name", pref_name)
7004
                _xmlpref.add_element("value", str(pref_value))
7005
7006
        return self._send_xml_command(cmd)
7007
7008
    def modify_user(
7009
        self,

gvm/protocols/gmpv7/gmpv7.py 1 location

@@ 5952-6077 (lines=126) @@
5949
5950
        return self._send_xml_command(cmd)
5951
5952
    def modify_task(
5953
        self,
5954
        task_id: str,
5955
        *,
5956
        name: Optional[str] = None,
5957
        config_id: Optional[str] = None,
5958
        target_id: Optional[str] = None,
5959
        scanner_id: Optional[str] = None,
5960
        alterable: Optional[bool] = None,
5961
        hosts_ordering: Optional[HostsOrdering] = None,
5962
        schedule_id: Optional[str] = None,
5963
        schedule_periods: Optional[int] = None,
5964
        comment: Optional[str] = None,
5965
        alert_ids: Optional[List[str]] = None,
5966
        observers: Optional[List[str]] = None,
5967
        preferences: Optional[dict] = None,
5968
    ) -> Any:
5969
        """Modifies an existing task.
5970
5971
        Arguments:
5972
            task_id: UUID of task to modify.
5973
            name: The name of the task.
5974
            config_id: UUID of scan config to use by the task
5975
            target_id: UUID of target to be scanned
5976
            scanner_id: UUID of scanner to use for scanning the target
5977
            comment: The comment on the task.
5978
            alert_ids: List of UUIDs for alerts to be applied to the task
5979
            hosts_ordering: The order hosts are scanned in
5980
            schedule_id: UUID of a schedule when the task should be run.
5981
            schedule_periods: A limit to the number of times the task will be
5982
                scheduled, or 0 for no limit.
5983
            observers: List of names or ids of users which should be allowed to
5984
                observe this task
5985
            preferences: Name/Value pairs of scanner preferences.
5986
5987
        Returns:
5988
            The response. See :py:meth:`send_command` for details.
5989
        """
5990
        if not task_id:
5991
            raise RequiredArgument(
5992
                function=self.modify_task.__name__, argument='task_id argument'
5993
            )
5994
5995
        cmd = XmlCommand("modify_task")
5996
        cmd.set_attribute("task_id", task_id)
5997
5998
        if name:
5999
            cmd.add_element("name", name)
6000
6001
        if comment:
6002
            cmd.add_element("comment", comment)
6003
6004
        if config_id:
6005
            cmd.add_element("config", attrs={"id": config_id})
6006
6007
        if target_id:
6008
            cmd.add_element("target", attrs={"id": target_id})
6009
6010
        if alterable is not None:
6011
            cmd.add_element("alterable", _to_bool(alterable))
6012
6013
        if hosts_ordering:
6014
            if not isinstance(hosts_ordering, HostsOrdering):
6015
                raise InvalidArgumentType(
6016
                    function=self.modify_task.__name__,
6017
                    argument='hosts_ordering',
6018
                    arg_type=HostsOrdering.__name__,
6019
                )
6020
            cmd.add_element("hosts_ordering", hosts_ordering.value)
6021
6022
        if scanner_id:
6023
            cmd.add_element("scanner", attrs={"id": scanner_id})
6024
6025
        if schedule_id:
6026
            cmd.add_element("schedule", attrs={"id": schedule_id})
6027
6028
        if schedule_periods is not None:
6029
            if (
6030
                not isinstance(schedule_periods, numbers.Integral)
6031
                or schedule_periods < 0
6032
            ):
6033
                raise InvalidArgument(
6034
                    "schedule_periods must be an integer greater or equal "
6035
                    "than 0"
6036
                )
6037
            cmd.add_element("schedule_periods", str(schedule_periods))
6038
6039
        if alert_ids is not None:
6040
            if not _is_list_like(alert_ids):
6041
                raise InvalidArgumentType(
6042
                    function=self.modify_task.__name__,
6043
                    argument='alert_ids',
6044
                    arg_type='list',
6045
                )
6046
6047
            if len(alert_ids) == 0:
6048
                cmd.add_element("alert", attrs={"id": "0"})
6049
            else:
6050
                for alert in alert_ids:
6051
                    cmd.add_element("alert", attrs={"id": str(alert)})
6052
6053
        if observers is not None:
6054
            if not _is_list_like(observers):
6055
                raise InvalidArgumentType(
6056
                    function=self.modify_task.__name__,
6057
                    argument='observers',
6058
                    arg_type='list',
6059
                )
6060
6061
            cmd.add_element("observers", _to_comma_list(observers))
6062
6063
        if preferences is not None:
6064
            if not isinstance(preferences, collections.abc.Mapping):
6065
                raise InvalidArgumentType(
6066
                    function=self.modify_task.__name__,
6067
                    argument='preferences',
6068
                    arg_type=collections.abc.Mapping.__name__,
6069
                )
6070
6071
            _xmlprefs = cmd.add_element("preferences")
6072
            for pref_name, pref_value in preferences.items():
6073
                _xmlpref = _xmlprefs.add_element("preference")
6074
                _xmlpref.add_element("scanner_name", pref_name)
6075
                _xmlpref.add_element("value", str(pref_value))
6076
6077
        return self._send_xml_command(cmd)
6078
6079
    def modify_user(
6080
        self,