Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Load schemas dynamically #1135

Merged
merged 39 commits into from
Sep 19, 2024
Merged

Load schemas dynamically #1135

merged 39 commits into from
Sep 19, 2024

Conversation

udgover
Copy link
Collaborator

@udgover udgover commented Sep 14, 2024

This PR adds the concept of private schemas. Observables, entities and indicators are dynamically registered. Loading is implemented in core.schemas.__init__.py. It also automatically extends each type enums.

  • Implement dynamic loader for observables
  • Replace observables validators as field validators
  • Implement dynamic loader for entities
  • Implement dynamic loader for indicators

Types definition are based on filename.

@udgover udgover added enhancement needs work python Pull requests that update Python code noteworthy PRs that are noteworthy / introduce new features core labels Sep 14, 2024
@udgover
Copy link
Collaborator Author

udgover commented Sep 14, 2024

generic_observable.py has been renamed generic.py and GenericObservable class has been renamed Generic. SsdeepHash class has been renamed Ssdeep for clarity as well.

core unit tests are currently broken because of add_text tests that relies on validators.

Copy link
Collaborator

@tomchop tomchop left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks great! Happy to have this also for indicators and entities in this PR too. The field validators should go in another one IMHO.

Also, wdyt about merging all observables into 1 file (like indicators and entities)? having one line per file is weird... (also in another PR to keep changes clean)

core/schemas/__init__.py Outdated Show resolved Hide resolved
core/schemas/__init__.py Outdated Show resolved Hide resolved
core/schemas/__init__.py Show resolved Hide resolved
@udgover
Copy link
Collaborator Author

udgover commented Sep 15, 2024

This looks great! Happy to have this also for indicators and entities in this PR too.

Indicators and entities will be part of this PR as well.

The field validators should go in another one IMHO.

The problem with field validator is that's not possible to keep the current implementation as it's breaking add_text method. Since we are building the ObservableType enum dynamically from __init__.py which imports observable.py the TYPE_VALIDATOR_MAP cannot be created. I also think it makes sense to include validators as part of each object to validate field.

Also, wdyt about merging all observables into 1 file (like indicators and entities)? having one line per file is weird... (also in another PR to keep changes clean)

I do not have a strong opinion on this. However, I find it faster to know what is already defined just by browsing the folder rather than reading the code.

@tomchop
Copy link
Collaborator

tomchop commented Sep 15, 2024

Re: validation - Gotcha. Then let's bring the validation changes here

Let's keep the one-file-per-obs type in that case. We should still (at some point) also do the same for entities / indicators, just to be consistent.

@udgover udgover changed the title Load observables dynamically Load schemas dynamically Sep 16, 2024
@udgover udgover marked this pull request as ready for review September 17, 2024 12:29
core/schemas/entity.py Show resolved Hide resolved
core/schemas/observables/path.py Outdated Show resolved Hide resolved
core/schemas/__init__.py Show resolved Hide resolved
core/schemas/__init__.py Show resolved Hide resolved
@tomchop tomchop merged commit 4ef72ea into main Sep 19, 2024
3 checks passed
@tomchop tomchop deleted the private_schemas branch September 19, 2024 05:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
core enhancement needs work noteworthy PRs that are noteworthy / introduce new features python Pull requests that update Python code
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants