Code Duplication    Length = 29-29 lines in 2 locations

gvm/protocols/gmpv9/types.py 1 location

@@ 189-217 (lines=29) @@
186
    VULNERABILITY = "vuln"
187
188
189
def get_entity_type_from_string(
190
    entity_type: Optional[str],
191
) -> Optional[EntityType]:
192
    """Convert a entity type string to an actual EntityType instance
193
194
    Arguments:
195
        entity_type: Entity type string to convert to a EntityType
196
    """
197
    if not entity_type:
198
        return None
199
200
    if entity_type == 'vuln':
201
        return EntityType.VULNERABILITY
202
203
    if entity_type == 'os':
204
        return EntityType.OPERATING_SYSTEM
205
206
    if entity_type == 'config':
207
        return EntityType.SCAN_CONFIG
208
209
    if entity_type == 'tls_certificate':
210
        return EntityType.TLS_CERTIFICATE
211
212
    try:
213
        return EntityType[entity_type.upper()]
214
    except KeyError:
215
        raise InvalidArgument(
216
            argument='entity_type',
217
            function=get_entity_type_from_string.__name__,
218
        ) from None
219
220

gvm/protocols/gmpv208/types.py 1 location

@@ 162-190 (lines=29) @@
159
    VULNERABILITY = "vuln"
160
161
162
def get_entity_type_from_string(
163
    entity_type: Optional[str],
164
) -> Optional[EntityType]:
165
    """Convert a entity type string to an actual EntityType instance
166
167
    Arguments:
168
        entity_type: Entity type string to convert to a EntityType
169
    """
170
    if not entity_type:
171
        return None
172
173
    if entity_type == 'vuln':
174
        return EntityType.VULNERABILITY
175
176
    if entity_type == 'os':
177
        return EntityType.OPERATING_SYSTEM
178
179
    if entity_type == 'config':
180
        return EntityType.SCAN_CONFIG
181
182
    if entity_type == 'tls_certificate':
183
        return EntityType.TLS_CERTIFICATE
184
185
    try:
186
        return EntityType[entity_type.upper()]
187
    except KeyError:
188
        raise InvalidArgument(
189
            argument='entity_type',
190
            function=get_entity_type_from_string.__name__,
191
        ) from None
192
193