๐Ÿ” Overview

This Celery task is designed to block domains received from the Mail Tracker. It takes a list of root domains that were blocked as a result of incoming email analysis and blocks all Links associated with these domains, redirecting them to backup links.


๐Ÿ“ Task Definitions

@celery.task
def block_links_from_mail_tracker_domains_task(root_domains: list[str]):
    logger.info("Blocking links from Mail Tracker domains...")
 
    if not root_domains:
        logger.info("No root domains provided to block!")
        return
    logger.info(f"Received {len(root_domains)} root domains to block: {root_domains}")
 
    root_domain_map = Link.get_root_domains_map()
    total = len(root_domain_map)
    if total == 0:
        logger.info("No active root domains found! Skipped blocking.")
        return
    # count unique root domains
    logger.info(f"Found {total} active root domains...")
 
    logger.info("Loading Voluum data...")
    VoluumController.load_data()
 
    for root_domain in root_domains:
        if root_domain not in root_domain_map:
            logger.info(f"No active links found for root domain {root_domain}, skipping...")
            continue
        for obj in root_domain_map[root_domain]:
            logger.info(f"Blocking link {obj.link} from Mail Tracker domain {root_domain}.")
            block_link_task.delay(link_id=obj.id, reason=BlockReasons.SOCIAL_ENGINEERING.value, action_by="system")
 
    logger.info("Finished blocking links from Mail Tracker domains.")

โš™๏ธ Task Behavior & Flow

  1. The task block_links_from_mail_tracker_domains_task is triggered with a list of root domains that have been identified as blocked by the Mail Tracker.
  2. It retrieves all active root domains from the database and checks if any of the provided root domains match the active ones.
  3. For each matching root domain, it finds all associated links and invokes the block_link_task (see Block Links Task) to block each link, providing a reason for the block (in this case, โ€œSocial Engineeringโ€).
  4. The block_link_task handles the actual blocking of the link and switching it to a backup link in Voluum.
  5. Notifications about the blocked links and the switch to backup links are sent via the Telegram bot (see Telegram Messages).