Flow class / flow blueprint

This commit is contained in:
Cyber MacGeddon 2026-01-14 11:20:47 +00:00
parent 95fd60b7bd
commit 7672815349
2 changed files with 22 additions and 22 deletions

View file

@ -70,13 +70,13 @@ def get_enum_description(param_value, param_type_def):
# If not found in enum, return original value # If not found in enum, return original value
return param_value return param_value
def format_parameters(flow_params, class_params_metadata, config_api): def format_parameters(flow_params, blueprint_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 blueprint_params_metadata: The parameter metadata from the flow blueprint definition
config_api: API client to retrieve parameter type definitions config_api: API client to retrieve parameter type definitions
Returns: Returns:
@ -89,7 +89,7 @@ def format_parameters(flow_params, class_params_metadata, config_api):
# Sort parameters by order if available # Sort parameters by order if available
sorted_params = sorted( sorted_params = sorted(
class_params_metadata.items(), blueprint_params_metadata.items(),
key=lambda x: x[1].get("order", 999) key=lambda x: x[1].get("order", 999)
) )
@ -122,9 +122,9 @@ def format_parameters(flow_params, class_params_metadata, config_api):
param_list.append(line) param_list.append(line)
# Add any parameters that aren't in the class metadata (shouldn't happen normally) # Add any parameters that aren't in the blueprint metadata (shouldn't happen normally)
for param_name, value in flow_params.items(): for param_name, value in flow_params.items():
if param_name not in class_params_metadata: if param_name not in blueprint_params_metadata:
param_list.append(f"{param_name}: {value} (undefined)") param_list.append(f"{param_name}: {value} (undefined)")
return "\n".join(param_list) if param_list else "None" return "\n".join(param_list) if param_list else "None"
@ -156,24 +156,24 @@ def show_flows(url, token=None):
table = [] table = []
table.append(("id", id)) table.append(("id", id))
table.append(("class", flow.get("class-name", ""))) table.append(("blueprint", flow.get("blueprint-name", "")))
table.append(("desc", flow.get("description", ""))) table.append(("desc", flow.get("description", "")))
# Display parameters with human-readable descriptions # Display parameters with human-readable descriptions
parameters = flow.get("parameters", {}) parameters = flow.get("parameters", {})
if parameters: if parameters:
# Try to get the flow class definition for parameter metadata # Try to get the flow blueprint definition for parameter metadata
class_name = flow.get("class-name", "") blueprint_name = flow.get("blueprint-name", "")
if class_name: if blueprint_name:
try: try:
flow_class = flow_api.get_class(class_name) flow_blueprint = flow_api.get_blueprint(blueprint_name)
class_params_metadata = flow_class.get("parameters", {}) blueprint_params_metadata = flow_blueprint.get("parameters", {})
param_str = format_parameters(parameters, class_params_metadata, config_api) param_str = format_parameters(parameters, blueprint_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 blueprint definition
param_str = json.dumps(parameters, indent=2) param_str = json.dumps(parameters, indent=2)
else: else:
# No class name, fallback to JSON # No blueprint name, fallback to JSON
param_str = json.dumps(parameters, indent=2) param_str = json.dumps(parameters, indent=2)
table.append(("parameters", param_str)) table.append(("parameters", param_str))

View file

@ -148,7 +148,7 @@ class FlowConfig:
async def handle_list_flows(self, msg): async def handle_list_flows(self, msg):
names = list(await self.config.get("flows").keys()) names = list(await self.config.get("flow").keys())
return FlowResponse( return FlowResponse(
error = None, error = None,
@ -157,7 +157,7 @@ class FlowConfig:
async def handle_get_flow(self, msg): async def handle_get_flow(self, msg):
flow_data = await self.config.get("flows").get(msg.flow_id) flow_data = await self.config.get("flow").get(msg.flow_id)
flow = json.loads(flow_data) flow = json.loads(flow_data)
return FlowResponse( return FlowResponse(
@ -175,7 +175,7 @@ class FlowConfig:
if msg.flow_id is None: if msg.flow_id is None:
raise RuntimeError("No flow ID") raise RuntimeError("No flow ID")
if msg.flow_id in await self.config.get("flows").keys(): if msg.flow_id in await self.config.get("flow").keys():
raise RuntimeError("Flow already exists") raise RuntimeError("Flow already exists")
if msg.description is None: if msg.description is None:
@ -258,7 +258,7 @@ class FlowConfig:
else: else:
interfaces = {} interfaces = {}
await self.config.get("flows").put( await self.config.get("flow").put(
msg.flow_id, msg.flow_id,
json.dumps({ json.dumps({
"description": msg.description, "description": msg.description,
@ -281,10 +281,10 @@ class FlowConfig:
if msg.flow_id is None: if msg.flow_id is None:
raise RuntimeError("No flow ID") raise RuntimeError("No flow ID")
if msg.flow_id not in await self.config.get("flows").keys(): if msg.flow_id not in await self.config.get("flow").keys():
raise RuntimeError("Flow ID invalid") raise RuntimeError("Flow ID invalid")
flow = json.loads(await self.config.get("flows").get(msg.flow_id)) flow = json.loads(await self.config.get("flow").get(msg.flow_id))
if "blueprint-name" not in flow: if "blueprint-name" not in flow:
raise RuntimeError("Internal error: flow has no flow blueprint") raise RuntimeError("Internal error: flow has no flow blueprint")
@ -327,8 +327,8 @@ class FlowConfig:
processor, json.dumps(target) processor, json.dumps(target)
) )
if msg.flow_id in await self.config.get("flows").keys(): if msg.flow_id in await self.config.get("flow").keys():
await self.config.get("flows").delete(msg.flow_id) await self.config.get("flow").delete(msg.flow_id)
await self.config.inc_version() await self.config.inc_version()