def get_yara_bundle(httpreq: Request, request: YaraBundleRequest) -> YaraBundleResponse:
    """Generates a YARA bundle from a list of indicators."""
    yaras = []

    for yara_id in request.ids:
        db_yara = Yara.get(yara_id)
        if not db_yara:
            raise HTTPException(
                status_code=404,
                detail=f"YARA bundle request contained an unknown Yara: ID:{yara_id}",
            )
        if any(tag in request.exclude_tags for tag in db_yara.tags):
            continue
        yaras.append(db_yara)

    yara_from_tags, _ = Indicator.filter(
        query_args={"type": "yara", "tags": request.tags},
        user=httpreq.state.user,
    )

    for yara in yara_from_tags:
        if any(tag in request.exclude_tags for tag in yara.tags):
            continue
        yaras.append(yara)

    bundle = Yara.generate_yara_bundle(rules=yaras)

    if request.overlays:
        yara_map = {}
        for yara in yaras:
            yara_map[yara.name] = yara

        bundle = Yara.render_with_overlays(bundle, yara_map, request.overlays)

    return YaraBundleResponse(bundle=bundle)
Generates a YARA bundle from a list of indicators.
core/web/apiv2/indicators.py