Update tg-show-flows CLI

This commit is contained in:
Cyber MacGeddon 2025-09-26 10:21:28 +01:00
parent d0b9a18b74
commit 9a7d1f29fb

View file

@ -45,13 +45,38 @@ def describe_interfaces(intdefs, flow):
return "\n".join(lst) return "\n".join(lst)
def format_parameters(flow_params, class_params_metadata): def get_enum_description(param_value, param_type_def):
"""
Get the human-readable description for an enum value
Args:
param_value: The actual parameter value (e.g., "gpt-4")
param_type_def: The parameter type definition containing enum objects
Returns:
Human-readable description or the original value if not found
"""
enum_list = param_type_def.get("enum", [])
# Handle both old format (strings) and new format (objects with id/description)
for enum_item in enum_list:
if isinstance(enum_item, dict):
if enum_item.get("id") == param_value:
return enum_item.get("description", param_value)
elif enum_item == param_value:
return param_value
# If not found in enum, return original value
return param_value
def format_parameters(flow_params, class_params_metadata, config_api):
""" """
Format flow parameters with their human-readable descriptions Format flow parameters with their human-readable descriptions
Args: Args:
flow_params: The actual parameter values used in the flow flow_params: The actual parameter values used in the flow
class_params_metadata: The parameter metadata from the flow class definition class_params_metadata: The parameter metadata from the flow class definition
config_api: API client to retrieve parameter type definitions
Returns: Returns:
Formatted string of parameters with descriptions Formatted string of parameters with descriptions
@ -72,21 +97,27 @@ def format_parameters(flow_params, class_params_metadata):
value = flow_params[param_name] value = flow_params[param_name]
description = param_meta.get("description", param_name) description = param_meta.get("description", param_name)
param_type = param_meta.get("type", "") param_type = param_meta.get("type", "")
advanced = param_meta.get("advanced", False)
controlled_by = param_meta.get("controlled-by", None) controlled_by = param_meta.get("controlled-by", None)
# Try to get enum description if this parameter has a type definition
display_value = value
if param_type and config_api:
try:
from trustgraph.api import ConfigKey
key = ConfigKey("parameter-types", param_type)
type_def_value = config_api.get([key])[0].value
param_type_def = json.loads(type_def_value)
display_value = get_enum_description(value, param_type_def)
except:
# If we can't get the type definition, just use the original value
display_value = value
# Format the parameter line # Format the parameter line
line = f"{description}: {value}" line = f"{description}: {display_value}"
# Add metadata indicators # Add controlled-by indicator if present
indicators = []
if advanced:
indicators.append("advanced")
if controlled_by: if controlled_by:
indicators.append(f"controlled by {controlled_by}") line += f" (controlled by {controlled_by})"
if indicators:
line += f" ({', '.join(indicators)})"
param_list.append(line) param_list.append(line)
@ -136,7 +167,7 @@ def show_flows(url):
try: try:
flow_class = flow_api.get_class(class_name) flow_class = flow_api.get_class(class_name)
class_params_metadata = flow_class.get("parameters", {}) class_params_metadata = flow_class.get("parameters", {})
param_str = format_parameters(parameters, class_params_metadata) param_str = format_parameters(parameters, class_params_metadata, config_api)
except Exception as e: except Exception as e:
# Fallback to JSON if we can't get the class definition # Fallback to JSON if we can't get the class definition
param_str = json.dumps(parameters, indent=2) param_str = json.dumps(parameters, indent=2)