Skip to content
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
# This file is a part of IntelOwl https://github.com/intelowlproject/IntelOwl
# See the file 'LICENSE' for copying permission.


from django.db import migrations


def migrate(apps, schema_editor):
playbook_config = apps.get_model("playbooks_manager", "PlaybookConfig")
pc = playbook_config.objects.get(name="FREE_TO_USE_ANALYZERS")

# Update the YARAify URL to the new yarahub endpoint
if "analyzers" in pc.runtime_configuration:
if "Yara" in pc.runtime_configuration["analyzers"]:
Copy link
Member

Choose a reason for hiding this comment

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

please check deepsource failures, that suggest to optimize this code.

Copy link
Member

Choose a reason for hiding this comment

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

also, instead of a lot of if, you can just use .get() and have fewer lines

yara_config = pc.runtime_configuration["analyzers"]["Yara"]
if "repositories" in yara_config:
repositories = yara_config["repositories"]
# Replace old YARAify URL with new yarahub URL
old_url = "https://yaraify-api.abuse.ch/download/yaraify-rules.zip"
new_url = "https://yaraify.abuse.ch/yarahub/yaraify-rules.zip"

if old_url in repositories:
index = repositories.index(old_url)
repositories[index] = new_url

pc.full_clean()
pc.save()
Copy link
Member

Choose a reason for hiding this comment

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

please provide a screenshot of the plugin section showing the correct data in the GUI



def reverse_migrate(apps, schema_editor):
playbook_config = apps.get_model("playbooks_manager", "PlaybookConfig")
pc = playbook_config.objects.get(name="FREE_TO_USE_ANALYZERS")

# Revert to the old YARAify URL
if "analyzers" in pc.runtime_configuration:
if "Yara" in pc.runtime_configuration["analyzers"]:
yara_config = pc.runtime_configuration["analyzers"]["Yara"]
if "repositories" in yara_config:
repositories = yara_config["repositories"]
# Replace new yarahub URL with old YARAify URL
old_url = "https://yaraify-api.abuse.ch/download/yaraify-rules.zip"
new_url = "https://yaraify.abuse.ch/yarahub/yaraify-rules.zip"

if new_url in repositories:
index = repositories.index(new_url)
repositories[index] = old_url

pc.full_clean()
pc.save()


class Migration(migrations.Migration):
dependencies = [
("playbooks_manager", "0059_add_ipquery_analyzer_free_to_use"),
]

operations = [
migrations.RunPython(migrate, reverse_migrate),
]
Loading