Code Duplication    Length = 29-32 lines in 2 locations

gvm/protocols/gmpv9/types.py 1 location

@@ 207-238 (lines=32) @@
204
    VULNERABILITY = "vuln"
205
206
207
def get_filter_type_from_string(
208
    filter_type: Optional[str]
209
) -> Optional[FilterType]:
210
    """ Convert a filter type string to an actual FilterType instance
211
212
    Arguments:
213
        filter_type (str): Filter type string to convert to a FilterType
214
    """
215
    if not filter_type:
216
        return None
217
218
    if filter_type == 'vuln':
219
        return FilterType.VULNERABILITY
220
221
    if filter_type == 'os':
222
        return FilterType.OPERATING_SYSTEM
223
224
    if filter_type == 'config':
225
        return FilterType.SCAN_CONFIG
226
227
    if filter_type == 'secinfo':
228
        return FilterType.ALL_SECINFO
229
230
    if filter_type == 'tls_certificate':
231
        return FilterType.TLS_CERTIFICATE
232
233
    try:
234
        return FilterType[filter_type.upper()]
235
    except KeyError:
236
        raise InvalidArgument(
237
            argument='filter_type',
238
            function=get_filter_type_from_string.__name__,
239
        )
240
241

gvm/protocols/gmpv8/types.py 1 location

@@ 199-227 (lines=29) @@
196
    VULNERABILITY = "vuln"
197
198
199
def get_filter_type_from_string(
200
    filter_type: Optional[str]
201
) -> Optional[FilterType]:
202
    """ Convert a filter type string to an actual FilterType instance
203
204
    Arguments:
205
        filter_type (str): Filter type string to convert to a FilterType
206
    """
207
    if not filter_type:
208
        return None
209
210
    if filter_type == 'vuln':
211
        return FilterType.VULNERABILITY
212
213
    if filter_type == 'os':
214
        return FilterType.OPERATING_SYSTEM
215
216
    if filter_type == 'config':
217
        return FilterType.SCAN_CONFIG
218
219
    if filter_type == 'secinfo':
220
        return FilterType.ALL_SECINFO
221
222
    try:
223
        return FilterType[filter_type.upper()]
224
    except KeyError:
225
        raise InvalidArgument(
226
            argument='filter_type',
227
            function=get_filter_type_from_string.__name__,
228
        )
229
230