@cryptotaxi247 / CoPilot / commits / 93900f17

chore: Update customer integration table for Crowdstrike deployment

Taylor committed May 10, 2024 at 10:25 UTC 93900f1759a0f8d85d5f90e4468aac38e45d6355
1 file changed +36
backend/app/integrations/crowdstrike/services/provision.py
+36
@@ -4,6 +4,9 @@ from datetime import datetime
4
5 import aiofiles
6 from fastapi import HTTPException
7 +from sqlalchemy import and_
8 +from sqlalchemy import update
9 +from app.integrations.schema import CustomerIntegrations
10 from loguru import logger
11 from sqlalchemy.ext.asyncio import AsyncSession
12
@@ -382,6 +385,11 @@ async def provision_crowdstrike(
385 )
386 await load_and_replace_falconhose_cfg(customer_details=customer_details, keys=keys, session=session)
387
388 + await update_customer_integration_table(
389 + customer_code=customer_details.customer_code,
390 + session=session,
391 + )
392 +
393 return ProvisionCrowdstrikeResponse(
394 message="Crowdstrike customer provisioned successfully",
395 success=True,
@@ -513,3 +521,31 @@ async def load_and_replace_falconhose_cfg(
521 async with aiofiles.open(os.path.join(customer_upload_folder, "cs.falconhoseclient.cfg"), "w") as f:
522 await f.write(data)
523 return os.path.join(customer_upload_folder, "cs.falconhoseclient.cfg")
524 +
525 +
526 +
527 +async def update_customer_integration_table(
528 + customer_code: str,
529 + session: AsyncSession,
530 +) -> None:
531 + """
532 + Updates the `customer_integrations` table to set the `deployed` column to True where the `customer_code`
533 + matches the given customer code and the `integration_service_name` is "Crowdstrike".
534 +
535 + Args:
536 + customer_code (str): The customer code.
537 + session (AsyncSession): The async session object for making HTTP requests.
538 + """
539 + await session.execute(
540 + update(CustomerIntegrations)
541 + .where(
542 + and_(
543 + CustomerIntegrations.customer_code == customer_code,
544 + CustomerIntegrations.integration_service_name == "Crowdstrike",
545 + ),
546 + )
547 + .values(deployed=True),
548 + )
549 + await session.commit()
550 +
551 + return None