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

chore: Refactor content pack insertion and processing #237

Merged
merged 2 commits into from
Jun 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
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
8 changes: 8 additions & 0 deletions backend/app/connectors/graylog/services/content_packs.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,14 @@ async def insert_content_pack(content_pack: ContentPack) -> bool:
return True
else:
raise HTTPException(status_code=500, detail="Content pack insertion unsuccessful")
except HTTPException as e:
if "Content pack" in e.detail and "already found" in e.detail and "PROCESSING_PIPELINE" in content_pack["name"]:
logger.info("Content pack with PROCESSING_PIPELINE already exists, skipping")
return False
else:
error_msg = f"Failed to insert content pack: {e}"
logger.error(error_msg)
raise HTTPException(status_code=500, detail=error_msg)
except KeyError as e:
error_msg = f"Failed to insert content pack key: {e}"
logger.error(error_msg)
Expand Down
9 changes: 6 additions & 3 deletions backend/app/stack_provisioning/graylog/services/provision.py
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ async def filter_content_packs(content_packs, protocol_type):


async def process_content_pack(content_pack, content_pack_request):
content_pack_exists = await does_content_pack_exist(content_pack)
content_pack_exists = await does_content_pack_exist(content_pack_request.keywords.customer_name)
if content_pack_exists is True:
return
content_pack = load_content_pack_json(f"{content_pack}.json")
Expand All @@ -202,10 +202,13 @@ async def process_content_pack(content_pack, content_pack_request):

async def insert_and_install_content_pack(content_pack):
logger.info(f"Inserting {content_pack} Content Pack...")
await insert_content_pack(content_pack)
content_pack_inserted = await insert_content_pack(content_pack)
id, rev = await get_id_and_rev(content_pack)
logger.info(f"Id: {id}, Rev: {rev}")
await install_content_pack(content_pack_id=id, revision=rev)
if content_pack_inserted is True:
await install_content_pack(content_pack_id=id, revision=rev)
else:
logger.info(f"Content pack {content_pack['name']} already inserted, skipping install...")


async def provision_content_pack_network_connector(content_pack_request: ProvisionNetworkContentPackRequest) -> ProvisionGraylogResponse:
Expand Down
Loading