Code Duplication    Length = 126-126 lines in 2 locations

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,

gvm/protocols/gmpv208/gmpv208.py 1 location

@@ 6913-7038 (lines=126) @@
6910
6911
        return self._send_xml_command(cmd)
6912
6913
    def modify_task(
6914
        self,
6915
        task_id: str,
6916
        *,
6917
        name: Optional[str] = None,
6918
        config_id: Optional[str] = None,
6919
        target_id: Optional[str] = None,
6920
        scanner_id: Optional[str] = None,
6921
        alterable: Optional[bool] = None,
6922
        hosts_ordering: Optional[HostsOrdering] = None,
6923
        schedule_id: Optional[str] = None,
6924
        schedule_periods: Optional[int] = None,
6925
        comment: Optional[str] = None,
6926
        alert_ids: Optional[List[str]] = None,
6927
        observers: Optional[List[str]] = None,
6928
        preferences: Optional[dict] = None,
6929
    ) -> Any:
6930
        """Modifies an existing task.
6931
6932
        Arguments:
6933
            task_id: UUID of task to modify.
6934
            name: The name of the task.
6935
            config_id: UUID of scan config to use by the task
6936
            target_id: UUID of target to be scanned
6937
            scanner_id: UUID of scanner to use for scanning the target
6938
            comment: The comment on the task.
6939
            alert_ids: List of UUIDs for alerts to be applied to the task
6940
            hosts_ordering: The order hosts are scanned in
6941
            schedule_id: UUID of a schedule when the task should be run.
6942
            schedule_periods: A limit to the number of times the task will be
6943
                scheduled, or 0 for no limit.
6944
            observers: List of names or ids of users which should be allowed to
6945
                observe this task
6946
            preferences: Name/Value pairs of scanner preferences.
6947
6948
        Returns:
6949
            The response. See :py:meth:`send_command` for details.
6950
        """
6951
        if not task_id:
6952
            raise RequiredArgument(
6953
                function=self.modify_task.__name__, argument='task_id argument'
6954
            )
6955
6956
        cmd = XmlCommand("modify_task")
6957
        cmd.set_attribute("task_id", task_id)
6958
6959
        if name:
6960
            cmd.add_element("name", name)
6961
6962
        if comment:
6963
            cmd.add_element("comment", comment)
6964
6965
        if config_id:
6966
            cmd.add_element("config", attrs={"id": config_id})
6967
6968
        if target_id:
6969
            cmd.add_element("target", attrs={"id": target_id})
6970
6971
        if alterable is not None:
6972
            cmd.add_element("alterable", _to_bool(alterable))
6973
6974
        if hosts_ordering:
6975
            if not isinstance(hosts_ordering, HostsOrdering):
6976
                raise InvalidArgumentType(
6977
                    function=self.modify_task.__name__,
6978
                    argument='hosts_ordering',
6979
                    arg_type=HostsOrdering.__name__,
6980
                )
6981
            cmd.add_element("hosts_ordering", hosts_ordering.value)
6982
6983
        if scanner_id:
6984
            cmd.add_element("scanner", attrs={"id": scanner_id})
6985
6986
        if schedule_id:
6987
            cmd.add_element("schedule", attrs={"id": schedule_id})
6988
6989
        if schedule_periods is not None:
6990
            if (
6991
                not isinstance(schedule_periods, numbers.Integral)
6992
                or schedule_periods < 0
6993
            ):
6994
                raise InvalidArgument(
6995
                    "schedule_periods must be an integer greater or equal "
6996
                    "than 0"
6997
                )
6998
            cmd.add_element("schedule_periods", str(schedule_periods))
6999
7000
        if alert_ids is not None:
7001
            if not _is_list_like(alert_ids):
7002
                raise InvalidArgumentType(
7003
                    function=self.modify_task.__name__,
7004
                    argument='alert_ids',
7005
                    arg_type='list',
7006
                )
7007
7008
            if len(alert_ids) == 0:
7009
                cmd.add_element("alert", attrs={"id": "0"})
7010
            else:
7011
                for alert in alert_ids:
7012
                    cmd.add_element("alert", attrs={"id": str(alert)})
7013
7014
        if observers is not None:
7015
            if not _is_list_like(observers):
7016
                raise InvalidArgumentType(
7017
                    function=self.modify_task.__name__,
7018
                    argument='observers',
7019
                    arg_type='list',
7020
                )
7021
7022
            cmd.add_element("observers", _to_comma_list(observers))
7023
7024
        if preferences is not None:
7025
            if not isinstance(preferences, collections.abc.Mapping):
7026
                raise InvalidArgumentType(
7027
                    function=self.modify_task.__name__,
7028
                    argument='preferences',
7029
                    arg_type=collections.abc.Mapping.__name__,
7030
                )
7031
7032
            _xmlprefs = cmd.add_element("preferences")
7033
            for pref_name, pref_value in preferences.items():
7034
                _xmlpref = _xmlprefs.add_element("preference")
7035
                _xmlpref.add_element("scanner_name", pref_name)
7036
                _xmlpref.add_element("value", str(pref_value))
7037
7038
        return self._send_xml_command(cmd)
7039
7040
    def modify_user(
7041
        self,