Code Duplication    Length = 71-72 lines in 2 locations

gvm/protocols/gmpv214/entities/notes.py 2 locations

@@ 32-103 (lines=72) @@
29
30
31
class NotesMixin(Gmp208NotesMixin):
32
    def create_note(
33
        self,
34
        text: str,
35
        nvt_oid: str,
36
        *,
37
        days_active: Optional[int] = None,
38
        hosts: Optional[List[str]] = None,
39
        port: Optional[int] = None,
40
        result_id: Optional[str] = None,
41
        severity: Optional[Severity] = None,
42
        task_id: Optional[str] = None,
43
        threat: Any = None,
44
    ) -> Any:
45
        """Create a new note
46
47
        Arguments:
48
            text: Text of the new note
49
            nvt_id: OID of the nvt to which note applies
50
            days_active: Days note will be active. -1 on
51
                always, 0 off
52
            hosts: A list of hosts addresses
53
            port: Port to which the note applies
54
            result_id: UUID of a result to which note applies
55
            severity: Severity to which note applies
56
            task_id: UUID of task to which note applies
57
            threat: deprecated
58
59
        Returns:
60
            The response. See :py:meth:`send_command` for details.
61
        """
62
        if not text:
63
            raise RequiredArgument(
64
                function=self.create_note.__name__, argument='text'
65
            )
66
67
        if not nvt_oid:
68
            raise RequiredArgument(
69
                function=self.create_note.__name__, argument='nvt_oid'
70
            )
71
72
        cmd = XmlCommand("create_note")
73
        cmd.add_element("text", text)
74
        cmd.add_element("nvt", attrs={"oid": nvt_oid})
75
76
        if days_active is not None:
77
            cmd.add_element("active", str(days_active))
78
79
        if hosts:
80
            cmd.add_element("hosts", to_comma_list(hosts))
81
82
        if port:
83
            cmd.add_element("port", str(port))
84
85
        if result_id:
86
            cmd.add_element("result", attrs={"id": result_id})
87
88
        if severity:
89
            cmd.add_element("severity", str(severity))
90
91
        if task_id:
92
            cmd.add_element("task", attrs={"id": task_id})
93
94
        if threat is not None:
95
            deprecation(
96
                "The threat parameter has been removed in GMP"
97
                " version {}{}".format(
98
                    self.get_protocol_version()[0],
99
                    self.get_protocol_version()[1],
100
                )
101
            )
102
103
        return self._send_xml_command(cmd)
104
105
    def modify_note(
106
        self,
@@ 105-175 (lines=71) @@
102
103
        return self._send_xml_command(cmd)
104
105
    def modify_note(
106
        self,
107
        note_id: str,
108
        text: str,
109
        *,
110
        days_active: Optional[int] = None,
111
        hosts: Optional[List[str]] = None,
112
        port: Optional[int] = None,
113
        result_id: Optional[str] = None,
114
        severity: Optional[Severity] = None,
115
        task_id: Optional[str] = None,
116
        threat: Any = None,
117
    ) -> Any:
118
        """Modifies an existing note.
119
120
        Arguments:
121
            note_id: UUID of note to modify.
122
            text: The text of the note.
123
            days_active: Days note will be active. -1 on always, 0 off.
124
            hosts: A list of hosts addresses
125
            port: Port to which note applies.
126
            result_id: Result to which note applies.
127
            severity: Severity to which note applies.
128
            task_id: Task to which note applies.
129
            threat: deprecated
130
131
        Returns:
132
            The response. See :py:meth:`send_command` for details.
133
        """
134
        if not note_id:
135
            raise RequiredArgument(
136
                function=self.modify_note.__name__, argument='note_id'
137
            )
138
139
        if not text:
140
            raise RequiredArgument(
141
                function=self.modify_note.__name__, argument='text'
142
            )
143
144
        cmd = XmlCommand("modify_note")
145
        cmd.set_attribute("note_id", note_id)
146
        cmd.add_element("text", text)
147
148
        if days_active is not None:
149
            cmd.add_element("active", str(days_active))
150
151
        if hosts:
152
            cmd.add_element("hosts", to_comma_list(hosts))
153
154
        if port:
155
            cmd.add_element("port", str(port))
156
157
        if result_id:
158
            cmd.add_element("result", attrs={"id": result_id})
159
160
        if severity:
161
            cmd.add_element("severity", str(severity))
162
163
        if task_id:
164
            cmd.add_element("task", attrs={"id": task_id})
165
166
        if threat is not None:
167
            deprecation(
168
                "The threat parameter has been removed in GMP"
169
                " version {}{}".format(
170
                    self.get_protocol_version()[0],
171
                    self.get_protocol_version()[1],
172
                )
173
            )
174
175
        return self._send_xml_command(cmd)
176