fix: CLI tools ignoring -w flag for workspace routing (#963)

Several CLI commands silently routed requests to the default workspace
regardless of the -w flag: show-flows, show-flow-blueprints,
show-parameter-types, set-prompt --system, and load-structured-data.
The workspace was sent in the inner request body but not on the
WebSocket envelope or API client constructor, so the gateway always
dispatched to the default workspace queue.
This commit is contained in:
cybermaggedon 2026-06-01 09:53:21 +01:00 committed by GitHub
parent 8eac99c182
commit c460f62c87
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
5 changed files with 18 additions and 10 deletions

View file

@ -293,7 +293,7 @@ def load_structured_data(
# Send to TrustGraph # Send to TrustGraph
print(f"🚀 Importing {len(output_records)} records to TrustGraph...") print(f"🚀 Importing {len(output_records)} records to TrustGraph...")
imported_count = _send_to_trustgraph(output_records, api_url, flow, batch_size, token=token) imported_count = _send_to_trustgraph(output_records, api_url, flow, batch_size, token=token, workspace=workspace)
# Get summary info from descriptor # Get summary info from descriptor
format_info = descriptor.get('format', {}) format_info = descriptor.get('format', {})

View file

@ -119,7 +119,8 @@ def main():
raise RuntimeError("Can't use --system with other args") raise RuntimeError("Can't use --system with other args")
set_system( set_system(
url=args.api_url, system=args.system, token=args.token url=args.api_url, system=args.system, token=args.token,
workspace=args.workspace,
) )
else: else:

View file

@ -105,7 +105,7 @@ async def fetch_data(client, workspace):
return blueprint_names, blueprints, param_type_defs return blueprint_names, blueprints, param_type_defs
async def _show_flow_blueprints_async(url, token=None, workspace="default"): async def _show_flow_blueprints_async(url, token=None, workspace="default"):
async with AsyncSocketClient(url, timeout=60, token=token) as client: async with AsyncSocketClient(url, timeout=60, token=token, workspace=workspace) as client:
return await fetch_data(client, workspace) return await fetch_data(client, workspace)
def show_flow_blueprints(url, token=None, workspace="default"): def show_flow_blueprints(url, token=None, workspace="default"):

View file

@ -213,7 +213,7 @@ async def fetch_show_flows(client, workspace):
async def _show_flows_async(url, token=None, workspace="default"): async def _show_flows_async(url, token=None, workspace="default"):
async with AsyncSocketClient(url, timeout=60, token=token) as client: async with AsyncSocketClient(url, timeout=60, token=token, workspace=workspace) as client:
return await fetch_show_flows(client, workspace) return await fetch_show_flows(client, workspace)
def show_flows(url, token=None, workspace="default"): def show_flows(url, token=None, workspace="default"):

View file

@ -15,6 +15,7 @@ import json
default_url = os.getenv("TRUSTGRAPH_URL", 'http://localhost:8088/') default_url = os.getenv("TRUSTGRAPH_URL", 'http://localhost:8088/')
default_token = os.getenv("TRUSTGRAPH_TOKEN", None) default_token = os.getenv("TRUSTGRAPH_TOKEN", None)
default_workspace = os.getenv("TRUSTGRAPH_WORKSPACE", "default")
def format_enum_values(enum_list): def format_enum_values(enum_list):
""" """
@ -125,11 +126,11 @@ async def fetch_single_param_type(client, param_type_name):
return json.loads(values[0].get("value", "{}")) return json.loads(values[0].get("value", "{}"))
return None return None
def show_parameter_types(url, token=None): def show_parameter_types(url, token=None, workspace="default"):
"""Show all parameter type definitions.""" """Show all parameter type definitions."""
async def _fetch(): async def _fetch():
async with AsyncSocketClient(url, timeout=60, token=token) as client: async with AsyncSocketClient(url, timeout=60, token=token, workspace=workspace) as client:
return await fetch_all_param_types(client) return await fetch_all_param_types(client)
param_type_names, param_type_defs = asyncio.run(_fetch()) param_type_names, param_type_defs = asyncio.run(_fetch())
@ -153,11 +154,11 @@ def show_parameter_types(url, token=None):
)) ))
print() print()
def show_specific_parameter_type(url, param_type_name, token=None): def show_specific_parameter_type(url, param_type_name, token=None, workspace="default"):
"""Show a specific parameter type definition.""" """Show a specific parameter type definition."""
async def _fetch(): async def _fetch():
async with AsyncSocketClient(url, timeout=60, token=token) as client: async with AsyncSocketClient(url, timeout=60, token=token, workspace=workspace) as client:
return await fetch_single_param_type(client, param_type_name) return await fetch_single_param_type(client, param_type_name)
param_type_def = asyncio.run(_fetch()) param_type_def = asyncio.run(_fetch())
@ -193,6 +194,12 @@ def main():
help='Authentication token (default: $TRUSTGRAPH_TOKEN)', help='Authentication token (default: $TRUSTGRAPH_TOKEN)',
) )
parser.add_argument(
'-w', '--workspace',
default=default_workspace,
help=f'Workspace (default: {default_workspace})',
)
parser.add_argument( parser.add_argument(
'-t', '--type', '-t', '--type',
help='Show only the specified parameter type', help='Show only the specified parameter type',
@ -202,9 +209,9 @@ def main():
try: try:
if args.type: if args.type:
show_specific_parameter_type(args.api_url, args.type, args.token) show_specific_parameter_type(args.api_url, args.type, args.token, workspace=args.workspace)
else: else:
show_parameter_types(args.api_url, args.token) show_parameter_types(args.api_url, args.token, workspace=args.workspace)
except Exception as e: except Exception as e:
print("Exception:", e, flush=True) print("Exception:", e, flush=True)