greenbone / python-gvm

Greenbone Vulnerability Management Python Library
https://greenbone.github.io/python-gvm/
GNU General Public License v3.0
106 stars 60 forks source link

Handling removals from e.g. Tasks, Targets in modify functions #303

Closed y0urself closed 3 years ago

y0urself commented 3 years ago

It seems to be impossible to remove a certain field of an entity in the modify functions. See this Issue for more information ...

Expected behaviour

Remove the Field from the Entity.

Current behaviour

Treated as None, what leads to remain the Field untouched in that Entity.

Steps to reproduce

GVM versions

all?!

Environment

Operating system: all

Installation method / source: (packages, source installation) all

bjoernricks commented 3 years ago

My idea is to use a different default value then None and allow to pass None to reset e.g. a target of a task

__UNDEFINED_VALUE = -1

    def modify_task(
        self,
        task_id: str,
        *,
        name: Optional[str] = None,
        config_id: Optional[str] = __UNDEFINED_VALUE,
        target_id: Optional[str] = __UNDEFINED_VALUE,
        scanner_id: Optional[str] = __UNDEFINED_VALUE,
        alterable: Optional[bool] = None,
        hosts_ordering: Optional[HostsOrdering] = None,
        schedule_id: Optional[str] = __UNDEFINED_VALUE,
        schedule_periods: Optional[int] = None,
        comment: Optional[str] = None,
        alert_ids: Optional[List[str]] = None,
        observers: Optional[List[str]] = None,
        preferences: Optional[dict] = None
    ) -> Any
        if target_id is None:
             cmd.add_element("target", attrs={"id": "0"}) # not sure about "0"
        elif target_id and target_id != __UNDEFINED_VALUE:
            cmd.add_element("target", attrs={"id": target_id})
y0urself commented 3 years ago

This issue is not existing at all ... we support removals as Björn mentioned in his comment. Just pass the "0" as ID ...