Skip to content

Commit

Permalink
chore: Remove unused dfir-iris connector from the database since we a…
Browse files Browse the repository at this point in the history
…re now using built in incident management
  • Loading branch information
taylorwalton committed Aug 26, 2024
1 parent 06d015d commit a2a7f7a
Show file tree
Hide file tree
Showing 3 changed files with 63 additions and 3 deletions.
43 changes: 42 additions & 1 deletion backend/app/db/db_populate.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ def get_connectors_list():
),
("Graylog", "5.0.7", "username_password", "Connection to Graylog."),
("Shuffle", "1.1.0", "api_key", "Connection to Shuffle."),
("DFIR-IRIS", "2.0", "api_key", "Connection to DFIR-IRIS."),
#("DFIR-IRIS", "2.0", "api_key", "Connection to DFIR-IRIS."),
(
"Velociraptor",
"0.6.8",
Expand Down Expand Up @@ -148,6 +148,20 @@ def get_connectors_list():

return [load_connector_data(*connector) for connector in connectors]

def delete_connectors_list():
"""
Get a list of connectors with their respective versions and authentication methods.
Returns:
list: A list of connector data, where each item contains the connector name, version, and authentication method.
"""
connectors = [
"DFIR-IRIS",
]

return connectors



async def add_connectors_if_not_exist(session: AsyncSession):
"""
Expand Down Expand Up @@ -177,6 +191,33 @@ async def add_connectors_if_not_exist(session: AsyncSession):

await session.commit()

async def delete_connectors_if_exist(session: AsyncSession):
"""
Deletes connectors from the database if they already exist.
Args:
session (AsyncSession): The database session.
Returns:
None
"""
connector_list = delete_connectors_list()
logger.info("Checking for existence of connectors. This connector will be deleted.")

for connector_data in connector_list:
logger.info(f"Checking for existence of connector {connector_data}")
query = select(Connectors).where(
Connectors.connector_name == connector_data,
)
result = await session.execute(query)
existing_connector = result.scalars().first()

if existing_connector is not None:
await session.delete(existing_connector)
logger.info(f"Deleted connector: {connector_data}")

await session.commit()


async def add_roles_if_not_exist(session: AsyncSession) -> None:
"""
Expand Down
20 changes: 19 additions & 1 deletion backend/app/db/db_setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
from app.db.db_populate import add_available_integrations_if_not_exist
from app.db.db_populate import add_available_network_connectors_auth_keys_if_not_exist
from app.db.db_populate import add_available_network_connectors_if_not_exist
from app.db.db_populate import add_connectors_if_not_exist
from app.db.db_populate import add_connectors_if_not_exist, delete_connectors_if_exist
from app.db.db_populate import add_roles_if_not_exist
from app.db.db_session import SQLALCHEMY_DATABASE_URI
from app.db.db_session import db_password
Expand Down Expand Up @@ -124,6 +124,24 @@ async def add_connectors(async_engine):
await add_connectors_if_not_exist(session)
logger.info("Connectors added successfully")

async def delete_connectors(async_engine):
"""
Deletes connectors from the database.
Args:
async_engine (AsyncEngine): The async engine used to connect to the database.
Returns:
None
"""
logger.info("Deleting connectors")
async with AsyncSession(
async_engine,
) as session: # Create an AsyncSession, not just a connection
async with session.begin(): # Start a transaction
await delete_connectors_if_exist(session)
logger.info("Connectors deleted successfully")


async def create_tables(async_engine):
"""
Expand Down
3 changes: 2 additions & 1 deletion backend/copilot.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
from app.auth.utils import AuthHandler
from app.db.db_session import SQLALCHEMY_DATABASE_URI_NO_DB
from app.db.db_session import async_engine
from app.db.db_setup import add_connectors
from app.db.db_setup import add_connectors, delete_connectors
from app.db.db_setup import apply_migrations
from app.db.db_setup import create_available_integrations
from app.db.db_setup import create_available_network_connectors
Expand Down Expand Up @@ -165,6 +165,7 @@ async def init_db():
await create_copilot_user_if_not_exists(db_url=SQLALCHEMY_DATABASE_URI_NO_DB, db_user_name="copilot")
apply_migrations()
await add_connectors(async_engine)
await delete_connectors(async_engine)
await create_roles(async_engine)
await create_available_integrations(async_engine)
await create_available_network_connectors(async_engine)
Expand Down

0 comments on commit a2a7f7a

Please sign in to comment.