From 83f4539f8326f490b88dbfb0269251753426f16e Mon Sep 17 00:00:00 2001 From: Sophia Wang Date: Fri, 27 Dec 2024 16:29:43 +0800 Subject: [PATCH] Move the ssg connections from utils to cac transformer Signed-off-by: Sophia Wang --- trestlebot/cli/commands/sync_cac_content.py | 3 ++- trestlebot/cli/utils.py | 15 --------------- trestlebot/transformers/cac_transformer.py | 19 +++++++++++++++++++ 3 files changed, 21 insertions(+), 16 deletions(-) create mode 100644 trestlebot/transformers/cac_transformer.py diff --git a/trestlebot/cli/commands/sync_cac_content.py b/trestlebot/cli/commands/sync_cac_content.py index e77a321e..196db641 100644 --- a/trestlebot/cli/commands/sync_cac_content.py +++ b/trestlebot/cli/commands/sync_cac_content.py @@ -9,7 +9,7 @@ from trestlebot import const from trestlebot.cli.options.common import common_options, git_options, handle_exceptions -from trestlebot.cli.utils import get_component_title, run_bot +from trestlebot.cli.utils import run_bot from trestlebot.tasks.authored.compdef import ( AuthoredComponentDefinition, FilterByProfile, @@ -17,6 +17,7 @@ from trestlebot.tasks.base_task import ModelFilter, TaskBase from trestlebot.tasks.regenerate_task import RegenerateTask from trestlebot.tasks.rule_transform_task import RuleTransformTask +from trestlebot.transformers.cac_transformer import get_component_title from trestlebot.transformers.yaml_transformer import ToRulesYAMLTransformer diff --git a/trestlebot/cli/utils.py b/trestlebot/cli/utils.py index 54ab56e7..e8f086fe 100644 --- a/trestlebot/cli/utils.py +++ b/trestlebot/cli/utils.py @@ -4,8 +4,6 @@ import logging from typing import Any, Dict, List -from ssg.products import load_product_yaml, product_yaml_path - from trestlebot.bot import TrestleBot from trestlebot.reporter import BotResults from trestlebot.tasks.base_task import TaskBase @@ -41,16 +39,3 @@ def run_bot(pre_tasks: List[TaskBase], kwargs: Dict[Any, Any]) -> BotResults: ), dry_run=kwargs.get("dry_run", False), ) - - -def get_component_title(product_name: str, cac_path: str) -> str: - """Get the product name from product yml file via the SSG library.""" - if product_name and cac_path: - # Get the product yaml file path - product_yml_path = product_yaml_path(cac_path, product_name) - # Load the product data - product = load_product_yaml(product_yml_path) - # Return product name from product yml file - return product._primary_data.get("product") - else: - raise ValueError("component_title is empty or None") diff --git a/trestlebot/transformers/cac_transformer.py b/trestlebot/transformers/cac_transformer.py new file mode 100644 index 00000000..4c3b2a25 --- /dev/null +++ b/trestlebot/transformers/cac_transformer.py @@ -0,0 +1,19 @@ +# SPDX-License-Identifier: Apache-2.0 +# Copyright (c) 2024 Red Hat, Inc. + +"""Cac content Transformer for rule authoring. """ + +from ssg.products import load_product_yaml, product_yaml_path + + +def get_component_title(product_name: str, cac_path: str) -> str: + """Get the product name from product yml file via the SSG library.""" + if product_name and cac_path: + # Get the product yaml file path + product_yml_path = product_yaml_path(cac_path, product_name) + # Load the product data + product = load_product_yaml(product_yml_path) + # Return product name from product yml file + return product._primary_data.get("product") + else: + raise ValueError("component_title is empty or None")