19
19
20
20
from typing import Any , List , Optional
21
21
22
- from gvm .errors import RequiredArgument
22
+ from gvm .errors import InvalidArgument , RequiredArgument
23
23
from gvm .protocols .gmpv208 .entities .overrides import (
24
24
OverridesMixin as Gmp208OverridesMixin ,
25
25
)
26
26
from gvm .protocols .gmpv208 .entities .severity import Severity
27
- from gvm .utils import deprecation , to_comma_list
27
+ from gvm .utils import check_port , deprecation , to_comma_list
28
28
from gvm .xml import XmlCommand
29
29
30
30
@@ -36,7 +36,7 @@ def create_override(
36
36
* ,
37
37
days_active : Optional [int ] = None ,
38
38
hosts : Optional [List [str ]] = None ,
39
- port : Optional [int ] = None ,
39
+ port : Optional [str ] = None ,
40
40
result_id : Optional [str ] = None ,
41
41
severity : Optional [Severity ] = None ,
42
42
new_severity : Optional [Severity ] = None ,
@@ -51,7 +51,8 @@ def create_override(
51
51
nvt_id: OID of the nvt to which override applies
52
52
days_active: Days override will be active. -1 on always, 0 off
53
53
hosts: A list of host addresses
54
- port: Port to which the override applies
54
+ port: Port to which the override applies, needs to be a string
55
+ in the form {number}/{protocol}
55
56
result_id: UUID of a result to which override applies
56
57
severity: Severity to which override applies
57
58
new_severity: New severity for result
@@ -83,7 +84,12 @@ def create_override(
83
84
cmd .add_element ("hosts" , to_comma_list (hosts ))
84
85
85
86
if port :
86
- cmd .add_element ("port" , str (port ))
87
+ if check_port (port ):
88
+ cmd .add_element ("port" , str (port ))
89
+ else :
90
+ raise InvalidArgument (
91
+ function = self .create_override .__name__ , argument = 'port'
92
+ )
87
93
88
94
if result_id :
89
95
cmd .add_element ("result" , attrs = {"id" : result_id })
@@ -120,7 +126,7 @@ def modify_override(
120
126
* ,
121
127
days_active : Optional [int ] = None ,
122
128
hosts : Optional [List [str ]] = None ,
123
- port : Optional [int ] = None ,
129
+ port : Optional [str ] = None ,
124
130
result_id : Optional [str ] = None ,
125
131
severity : Optional [Severity ] = None ,
126
132
new_severity : Optional [Severity ] = None ,
@@ -136,7 +142,8 @@ def modify_override(
136
142
days_active: Days override will be active. -1 on always,
137
143
0 off.
138
144
hosts: A list of host addresses
139
- port: Port to which override applies.
145
+ port: Port to which the override applies, needs to be a string
146
+ in the form {number}/{protocol}
140
147
result_id: Result to which override applies.
141
148
severity: Severity to which override applies.
142
149
new_severity: New severity score for result.
@@ -167,7 +174,12 @@ def modify_override(
167
174
cmd .add_element ("hosts" , to_comma_list (hosts ))
168
175
169
176
if port :
170
- cmd .add_element ("port" , str (port ))
177
+ if check_port (port ):
178
+ cmd .add_element ("port" , str (port ))
179
+ else :
180
+ raise InvalidArgument (
181
+ function = self .modify_override .__name__ , argument = 'port'
182
+ )
171
183
172
184
if result_id :
173
185
cmd .add_element ("result" , attrs = {"id" : result_id })
0 commit comments