Code Duplication    Length = 29-29 lines in 2 locations

gvm/protocols/gmpv208/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/gmpv9/types.py 1 location

@@ 138-166 (lines=29) @@
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
    if entity_type == 'tls_certificate':
159
        return EntityType.TLS_CERTIFICATE
160
161
    try:
162
        return EntityType[entity_type.upper()]
163
    except KeyError:
164
        raise InvalidArgument(
165
            argument='entity_type',
166
            function=get_entity_type_from_string.__name__,
167
        )
168
169