Skip to content

Commit

Permalink
Update the component description as the product full name
Browse files Browse the repository at this point in the history
Signed-off-by: Sophia Wang <huiwang@redhat.com>
  • Loading branch information
huiwangredhat committed Jan 6, 2025
1 parent 810483f commit cfa689d
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 11 deletions.
2 changes: 0 additions & 2 deletions trestlebot/cli/commands/sync_cac_content.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,15 +64,13 @@ def sync_cac_content_cmd(ctx: click.Context, **kwargs: Any) -> None:

product = kwargs["product"]
cac_content_root = kwargs["cac_content_root"]
component_description = kwargs["product"]
component_definition_type = kwargs.get("component_definition_type", "service")
working_dir = kwargs["repo_path"]

authored_comp: AuthoredComponentDefinition = AuthoredComponentDefinition(
trestle_root=working_dir,
)
authored_comp.create_update_cac_compdef(
comp_description=component_description,
comp_type=component_definition_type,
product=product,
cac_content_root=cac_content_root,
Expand Down
12 changes: 5 additions & 7 deletions trestlebot/tasks/authored/compdef.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
AuthoredObjectException,
)
from trestlebot.transformers.cac_transformer import (
get_component_title,
get_component_info,
update_component_definition,
)
from trestlebot.transformers.trestle_rule import (
Expand Down Expand Up @@ -171,7 +171,6 @@ def create_new_default(

def create_update_cac_compdef(
self,
comp_description: str,
comp_type: str,
product: str,
cac_content_root: str,
Expand All @@ -192,9 +191,10 @@ def create_update_cac_compdef(
component_definition.metadata.version = "1.0"
component_definition.components = list()
oscal_component = generate_sample_model(DefinedComponent)
oscal_component.title = get_component_title(product, cac_content_root)
product_name, full_name = get_component_info(product, cac_content_root)
oscal_component.title = product_name
oscal_component.description = full_name
oscal_component.type = comp_type
oscal_component.description = comp_description

# Create all of the component properties for rules
# This part will be updated in CPLYTM-218
Expand All @@ -212,9 +212,7 @@ def create_update_cac_compdef(
with open(ofile, "r", encoding="utf-8") as f:
data = json.load(f)
for component in data["component-definition"]["components"]:
if component.get("title") == get_component_title(
product, cac_content_root
):
if component.get("title") == oscal_component.title:
logger.info("Update the exsisting component definition.")
# Need to update props parts if the rules updated
# Update the version and last modify time
Expand Down
7 changes: 5 additions & 2 deletions trestlebot/transformers/cac_transformer.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,22 @@
import datetime
import json
from pathlib import Path
from typing import Tuple

from ssg.products import load_product_yaml, product_yaml_path


def get_component_title(product_name: str, cac_path: str) -> str:
def get_component_info(product_name: str, cac_path: str) -> Tuple[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")
component_title = product._primary_data.get("product")
component_description = product._primary_data.get("full_name")
return (component_title, component_description)
else:
raise ValueError("component_title is empty or None")

Expand Down

0 comments on commit cfa689d

Please sign in to comment.