-
Notifications
You must be signed in to change notification settings - Fork 26
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added dedicated function for rendering a jinja string value with a pr…
…ovider child. New functions for aggregating detect messages.
- Loading branch information
Showing
3 changed files
with
79 additions
and
27 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
from collections import defaultdict | ||
from typing import Type | ||
|
||
from iambic.core.models import ProviderChild, BaseTemplate | ||
from iambic.core.utils import evaluate_on_provider | ||
|
||
|
||
def group_detect_messages(group_by: str, messages: list) -> dict: | ||
"""Group messages by a key in the message dict. | ||
Args: | ||
group_by (str): The key to group by. | ||
messages (list): The messages to group. | ||
Returns: | ||
dict: The grouped messages. | ||
""" | ||
grouped_messages = defaultdict(list) | ||
for message in messages: | ||
grouped_messages[getattr(message, group_by)].append(message) | ||
|
||
return grouped_messages | ||
|
||
|
||
def generate_template_output( | ||
excluded_provider_ids: list[str], | ||
provider_child_map: dict[str, ProviderChild], | ||
template: Type[BaseTemplate] | ||
) -> dict[str, dict]: | ||
provider_children_value_map = dict() | ||
for provider_child_id, provider_child in provider_child_map.items(): | ||
if provider_child_id in excluded_provider_ids: | ||
continue | ||
elif not evaluate_on_provider(template, provider_child, exclude_import_only=False): | ||
continue | ||
|
||
if provider_child_value := template.apply_resource_dict(provider_child): | ||
provider_children_value_map[provider_child_id] = provider_child_value | ||
|
||
return provider_children_value_map |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters