1919
2020from typing import Any , List , Optional
2121
22- from gvm .errors import RequiredArgument
22+ from gvm .errors import InvalidArgument , RequiredArgument
2323from gvm .protocols .gmpv208 .entities .overrides import (
2424 OverridesMixin as Gmp208OverridesMixin ,
2525)
2626from 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
2828from gvm .xml import XmlCommand
2929
3030
@@ -36,7 +36,7 @@ def create_override(
3636 * ,
3737 days_active : Optional [int ] = None ,
3838 hosts : Optional [List [str ]] = None ,
39- port : Optional [int ] = None ,
39+ port : Optional [str ] = None ,
4040 result_id : Optional [str ] = None ,
4141 severity : Optional [Severity ] = None ,
4242 new_severity : Optional [Severity ] = None ,
@@ -51,7 +51,8 @@ def create_override(
5151 nvt_id: OID of the nvt to which override applies
5252 days_active: Days override will be active. -1 on always, 0 off
5353 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}
5556 result_id: UUID of a result to which override applies
5657 severity: Severity to which override applies
5758 new_severity: New severity for result
@@ -83,7 +84,12 @@ def create_override(
8384 cmd .add_element ("hosts" , to_comma_list (hosts ))
8485
8586 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+ )
8793
8894 if result_id :
8995 cmd .add_element ("result" , attrs = {"id" : result_id })
@@ -120,7 +126,7 @@ def modify_override(
120126 * ,
121127 days_active : Optional [int ] = None ,
122128 hosts : Optional [List [str ]] = None ,
123- port : Optional [int ] = None ,
129+ port : Optional [str ] = None ,
124130 result_id : Optional [str ] = None ,
125131 severity : Optional [Severity ] = None ,
126132 new_severity : Optional [Severity ] = None ,
@@ -136,7 +142,8 @@ def modify_override(
136142 days_active: Days override will be active. -1 on always,
137143 0 off.
138144 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}
140147 result_id: Result to which override applies.
141148 severity: Severity to which override applies.
142149 new_severity: New severity score for result.
@@ -167,7 +174,12 @@ def modify_override(
167174 cmd .add_element ("hosts" , to_comma_list (hosts ))
168175
169176 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+ )
171183
172184 if result_id :
173185 cmd .add_element ("result" , attrs = {"id" : result_id })
0 commit comments