Skip to content

refactor(enrichers): deduplicate shared logic into base classes and consolidate utils#2

Open
devin-ai-integration[bot] wants to merge 1 commit into
mainfrom
devin/1782487849-refactor-deduplicate-shared-utils
Open

refactor(enrichers): deduplicate shared logic into base classes and consolidate utils#2
devin-ai-integration[bot] wants to merge 1 commit into
mainfrom
devin/1782487849-refactor-deduplicate-shared-utils

Conversation

@devin-ai-integration

Copy link
Copy Markdown

Summary

Eliminates ~1,850 lines of duplicated code across enrichers and utility modules by extracting shared logic into base classes and consolidating triplicated utility functions.

Utility consolidation

Three copies of 13+ identical functions (is_valid_email, is_valid_domain, is_valid_ip, flatten, unflatten, etc.) existed in flowsint-core/utils.py, flowsint-enrichers/utils.py, and flowsint-api/app/utils.py. Since both flowsint-api and flowsint-enrichers depend on flowsint-core, the core copy is now the single source of truth. The other two files are deleted. get_root_domain() (previously only in enrichers) was added to core.

Enricher base classes (_shared/)

Created three base classes in flowsint-enrichers/_shared/:

DehashedBase — 4 enrichers (domain/email/ip/social → Individual):

# Each subclass is now ~35 lines, down from ~160:
class DomainToDehashed(DehashedBase):
    InputType = Domain
    def query_field(cls) -> str: return "domain"   # DeHashed API field
    def input_attr(cls) -> str: return "domain"     # attribute on InputType

Base handles API call (/search?query={field}:{value}), Individual construction, error handling, and Neo4j BREACH_FOUND_IN relationships.

HudsonRockBase — 3 enrichers (email/phone/social → Device):

class EmailToHudsonrock(HudsonRockBase):
    InputType = Email
    def api_search_type(cls) -> str: return "email"  # HudsonRock endpoint param
    def input_attr(cls) -> str: return "email"

Base handles cavalier API call, Device construction with _parse_ip_addresses() for string/list/null IP handling, and Neo4j relationships.

AsnmapBase — 3 enrichers (domain/ip/organization → ASN):

class DomainToAsnEnricher(AsnmapBase):
    InputType = Domain
    def asnmap_type(cls) -> str: return "domain"     # asnmap tool type param
    def input_attr(cls) -> str: return "domain"
    def relationship_type(cls) -> str: return "HOSTED_IN"  # default is BELONGS_TO

Base handles AsnmapTool invocation, PDCP_API_KEY vault/env resolution, ASN number parsing, and Neo4j relationships.

Link to Devin session: https://app.devin.ai/sessions/bae2d12602f34bbabfd124c29af15fa7
Requested by: @netty-linux

…onsolidate utils

- Consolidate triplicated utility functions (13+ functions) from
  flowsint-api/app/utils.py and flowsint-enrichers/utils.py into
  flowsint-core/utils.py as single source of truth
- Add get_root_domain() to flowsint-core/utils.py (was only in enrichers)
- Create DehashedBase, HudsonRockBase, AsnmapBase in _shared/ module
- Refactor 4 DeHashed enrichers (domain/email/ip/social) to use DehashedBase
- Refactor 3 HudsonRock enrichers (email/phone/social) to use HudsonRockBase
- Refactor 3 ASN enrichers (domain/ip/organization) to use AsnmapBase
- Delete duplicate utils.py files from flowsint-api and flowsint-enrichers
- Clean up unused imports in domain/to_root_domain.py

Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
@netty-linux netty-linux self-assigned this Jun 26, 2026
@devin-ai-integration

Copy link
Copy Markdown
Author

🤖 Devin AI Engineer

I'll be helping with this pull request! Here's what you should know:

✅ I will automatically:

  • Address comments on this PR. Add '(aside)' to your comment to have me ignore it.
  • Look at CI failures and help fix them

Note: I can only respond to comments from users who have write access to this repository.

⚙️ Control Options:

  • Disable automatic comment, CI, and merge conflict monitoring

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant