Code Duplication    Length = 26-29 lines in 2 locations

gvm/protocols/gmpv9/types.py 1 location

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

gvm/protocols/gmpv8/types.py 1 location

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