Code Duplication    Length = 22-26 lines in 2 locations

gvm/protocols/gmpv8/types.py 1 location

@@ 138-163 (lines=26) @@
135
    VULNERABILITY = "vuln"
136
137
138
def get_entity_type_from_string(
139
    entity_type: Optional[str]
140
) -> Optional[EntityType]:
141
    """ Convert a entity type string to an actual EntityType instance
142
143
    Arguments:
144
        entity_type: Entity type string to convert to a EntityType
145
    """
146
    if not entity_type:
147
        return None
148
149
    if entity_type == 'vuln':
150
        return EntityType.VULNERABILITY
151
152
    if entity_type == 'os':
153
        return EntityType.OPERATING_SYSTEM
154
155
    if entity_type == 'config':
156
        return EntityType.SCAN_CONFIG
157
158
    try:
159
        return EntityType[entity_type.upper()]
160
    except KeyError:
161
        raise InvalidArgument(
162
            argument='entity_type',
163
            function=get_entity_type_from_string.__name__,
164
        )
165
166

gvm/protocols/gmpv7/types.py 1 location

@@ 343-364 (lines=22) @@
340
    USER = "user"
341
342
343
def get_entity_type_from_string(
344
    entity_type: Optional[str]
345
) -> Optional[EntityType]:
346
    """ Convert a entity type string to an actual EntityType instance
347
348
    Arguments:
349
        entity_type: Resource type string to convert to a EntityType
350
    """
351
    if not entity_type:
352
        return None
353
354
    if entity_type == 'config':
355
        return EntityType.SCAN_CONFIG
356
    if entity_type == 'os':
357
        return EntityType.OPERATING_SYSTEM
358
359
    try:
360
        return EntityType[entity_type.upper()]
361
    except KeyError:
362
        raise InvalidArgument(
363
            argument='entity_type',
364
            function=get_entity_type_from_string.__name__,
365
        )
366
367