-
Notifications
You must be signed in to change notification settings - Fork 59
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Support setting a custom JSON schema for copied boefjes (#3344)
Signed-off-by: Donny Peeters <[email protected]> Co-authored-by: Jan Klopper <[email protected]> Co-authored-by: stephanie0x00 <[email protected]>
- Loading branch information
1 parent
917f33d
commit 47866c0
Showing
14 changed files
with
475 additions
and
92 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
62 changes: 62 additions & 0 deletions
62
boefjes/boefjes/migrations/versions/5be152459a7b_introduce_schema_field_to_boefje_model.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
"""Introduce schema field to Boefje model | ||
Revision ID: 5be152459a7b | ||
Revises: f9de6eb7824b | ||
Create Date: 2024-08-08 14:47:12.582017 | ||
""" | ||
|
||
import logging | ||
|
||
import sqlalchemy as sa | ||
from alembic import op | ||
from sqlalchemy.orm import sessionmaker | ||
|
||
from boefjes.local_repository import get_local_repository | ||
from boefjes.sql.plugin_storage import create_plugin_storage | ||
from boefjes.storage.interfaces import PluginNotFound | ||
|
||
# revision identifiers, used by Alembic. | ||
revision = "5be152459a7b" | ||
down_revision = "f9de6eb7824b" | ||
branch_labels = None | ||
depends_on = None | ||
|
||
logger = logging.getLogger(__name__) | ||
|
||
|
||
def upgrade() -> None: | ||
# ### commands auto generated by Alembic - please adjust! ### | ||
op.add_column("boefje", sa.Column("schema", sa.JSON(), nullable=True)) | ||
|
||
local_repo = get_local_repository() | ||
session = sessionmaker(bind=op.get_bind())() | ||
|
||
with create_plugin_storage(session) as storage: | ||
plugins = local_repo.get_all() | ||
logger.info("Found %s plugins", len(plugins)) | ||
|
||
for plugin in local_repo.get_all(): | ||
schema = local_repo.schema(plugin.id) | ||
|
||
if schema: | ||
try: | ||
# This way we avoid the safeguard that updating static boefjes is not allowed | ||
instance = storage._db_boefje_instance_by_id(plugin.id) | ||
instance.schema = schema | ||
storage.session.add(instance) | ||
logger.info("Updated database entry for plugin %s", plugin.id) | ||
except PluginNotFound: | ||
logger.info("No database entry for plugin %s", plugin.id) | ||
continue | ||
else: | ||
logger.info("No schema present for plugin %s", plugin.id) | ||
|
||
session.close() | ||
# ### end Alembic commands ### | ||
|
||
|
||
def downgrade() -> None: | ||
# ### commands auto generated by Alembic - please adjust! ### | ||
op.drop_column("boefje", "schema") | ||
# ### end Alembic commands ### |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.