testzeus-cli 0.0.26__tar.gz → 0.0.28__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (41) hide show
  1. {testzeus_cli-0.0.26 → testzeus_cli-0.0.28}/PKG-INFO +2 -2
  2. {testzeus_cli-0.0.26 → testzeus_cli-0.0.28}/pyproject.toml +2 -2
  3. {testzeus_cli-0.0.26 → testzeus_cli-0.0.28}/testzeus_cli/commands/agent_harness.py +150 -21
  4. testzeus_cli-0.0.28/testzeus_cli/commands/connected_environments.py +123 -0
  5. testzeus_cli-0.0.26/testzeus_cli/commands/connected_environments.py +0 -447
  6. {testzeus_cli-0.0.26 → testzeus_cli-0.0.28}/LICENSE +0 -0
  7. {testzeus_cli-0.0.26 → testzeus_cli-0.0.28}/README.md +0 -0
  8. {testzeus_cli-0.0.26 → testzeus_cli-0.0.28}/testzeus_cli/__init__.py +0 -0
  9. {testzeus_cli-0.0.26 → testzeus_cli-0.0.28}/testzeus_cli/auth.py +0 -0
  10. {testzeus_cli-0.0.26 → testzeus_cli-0.0.28}/testzeus_cli/cli.py +0 -0
  11. {testzeus_cli-0.0.26 → testzeus_cli-0.0.28}/testzeus_cli/commands/__init__.py +0 -0
  12. {testzeus_cli-0.0.26 → testzeus_cli-0.0.28}/testzeus_cli/commands/daemon.py +0 -0
  13. {testzeus_cli-0.0.26 → testzeus_cli-0.0.28}/testzeus_cli/commands/device_pool.py +0 -0
  14. {testzeus_cli-0.0.26 → testzeus_cli-0.0.28}/testzeus_cli/commands/environments.py +0 -0
  15. {testzeus_cli-0.0.26 → testzeus_cli-0.0.28}/testzeus_cli/commands/extensions.py +0 -0
  16. {testzeus_cli-0.0.26 → testzeus_cli-0.0.28}/testzeus_cli/commands/hypermind_code_blocks.py +0 -0
  17. {testzeus_cli-0.0.26 → testzeus_cli-0.0.28}/testzeus_cli/commands/knowledge_bases.py +0 -0
  18. {testzeus_cli-0.0.26 → testzeus_cli-0.0.28}/testzeus_cli/commands/notification_channels.py +0 -0
  19. {testzeus_cli-0.0.26 → testzeus_cli-0.0.28}/testzeus_cli/commands/tags.py +0 -0
  20. {testzeus_cli-0.0.26 → testzeus_cli-0.0.28}/testzeus_cli/commands/test_data.py +0 -0
  21. {testzeus_cli-0.0.26 → testzeus_cli-0.0.28}/testzeus_cli/commands/test_report_runs.py +0 -0
  22. {testzeus_cli-0.0.26 → testzeus_cli-0.0.28}/testzeus_cli/commands/test_report_schedules.py +0 -0
  23. {testzeus_cli-0.0.26 → testzeus_cli-0.0.28}/testzeus_cli/commands/test_run_groups.py +0 -0
  24. {testzeus_cli-0.0.26 → testzeus_cli-0.0.28}/testzeus_cli/commands/test_runs.py +0 -0
  25. {testzeus_cli-0.0.26 → testzeus_cli-0.0.28}/testzeus_cli/commands/test_suite_node_runs.py +0 -0
  26. {testzeus_cli-0.0.26 → testzeus_cli-0.0.28}/testzeus_cli/commands/test_suite_runs.py +0 -0
  27. {testzeus_cli-0.0.26 → testzeus_cli-0.0.28}/testzeus_cli/commands/test_suite_schedules.py +0 -0
  28. {testzeus_cli-0.0.26 → testzeus_cli-0.0.28}/testzeus_cli/commands/test_suites.py +0 -0
  29. {testzeus_cli-0.0.26 → testzeus_cli-0.0.28}/testzeus_cli/commands/tests.py +0 -0
  30. {testzeus_cli-0.0.26 → testzeus_cli-0.0.28}/testzeus_cli/commands/tests_ai_generator.py +0 -0
  31. {testzeus_cli-0.0.26 → testzeus_cli-0.0.28}/testzeus_cli/commands/tests_authoring.py +0 -0
  32. {testzeus_cli-0.0.26 → testzeus_cli-0.0.28}/testzeus_cli/commands/user_integrations.py +0 -0
  33. {testzeus_cli-0.0.26 → testzeus_cli-0.0.28}/testzeus_cli/config.py +0 -0
  34. {testzeus_cli-0.0.26 → testzeus_cli-0.0.28}/testzeus_cli/utils/__init__.py +0 -0
  35. {testzeus_cli-0.0.26 → testzeus_cli-0.0.28}/testzeus_cli/utils/auth.py +0 -0
  36. {testzeus_cli-0.0.26 → testzeus_cli-0.0.28}/testzeus_cli/utils/client.py +0 -0
  37. {testzeus_cli-0.0.26 → testzeus_cli-0.0.28}/testzeus_cli/utils/files.py +0 -0
  38. {testzeus_cli-0.0.26 → testzeus_cli-0.0.28}/testzeus_cli/utils/formatters.py +0 -0
  39. {testzeus_cli-0.0.26 → testzeus_cli-0.0.28}/testzeus_cli/utils/links.py +0 -0
  40. {testzeus_cli-0.0.26 → testzeus_cli-0.0.28}/testzeus_cli/utils/profile.py +0 -0
  41. {testzeus_cli-0.0.26 → testzeus_cli-0.0.28}/testzeus_cli/utils/validators.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: testzeus-cli
3
- Version: 0.0.26
3
+ Version: 0.0.28
4
4
  Summary: Command-line interface for TestZeus testing platform
5
5
  License-File: LICENSE
6
6
  Author: Shriyansh Agnihotri
@@ -22,7 +22,7 @@ Requires-Dist: pocketbase (>=0.15.0,<0.16.0)
22
22
  Requires-Dist: pydantic (>=2.0.0,<3.0.0)
23
23
  Requires-Dist: pyyaml (>=6.0,<7.0)
24
24
  Requires-Dist: rich (>=13.3.1,<14.0.0)
25
- Requires-Dist: testzeus-sdk (>=0.0.24,<0.1.0)
25
+ Requires-Dist: testzeus-sdk (>=0.0.25,<0.1.0)
26
26
  Requires-Dist: toml (>=0.10.2,<0.11.0)
27
27
  Project-URL: Repository, https://github.com/test-zeus-ai/testzeus-cli
28
28
  Description-Content-Type: text/markdown
@@ -4,7 +4,7 @@ build-backend = "poetry.core.masonry.api"
4
4
 
5
5
  [tool.poetry]
6
6
  name = "testzeus-cli"
7
- version = "0.0.26"
7
+ version = "0.0.28"
8
8
  description = "Command-line interface for TestZeus testing platform"
9
9
  authors = ["Shriyansh Agnihotri <shriyansh@testzeus.com>"]
10
10
  readme = "README.md"
@@ -22,7 +22,7 @@ pydantic = "^2.0.0"
22
22
  pyyaml = "^6.0"
23
23
  keyring = "^24.0.0"
24
24
  ipdb = "^0.13.13"
25
- testzeus-sdk = ">=0.0.24,<0.1.0"
25
+ testzeus-sdk = ">=0.0.25,<0.1.0"
26
26
  pocketbase = "^0.15.0"
27
27
  toml = "^0.10.2"
28
28
  aiohttp = "^3.14.1"
@@ -6,6 +6,8 @@ generate adversarial pathways, run simulations, and monitor / cancel them.
6
6
  """
7
7
 
8
8
  import asyncio
9
+ from typing import Any, Dict
10
+
9
11
  import click
10
12
  from rich.console import Console
11
13
  from testzeus_sdk import TestZeusClient
@@ -18,15 +20,57 @@ from testzeus_cli.utils.links import print_platform_link
18
20
  console = Console()
19
21
 
20
22
 
23
+ def _pathway_row(data: Dict[str, Any]) -> Dict[str, Any]:
24
+ """Trim a pathway record to the columns worth showing in a list.
25
+
26
+ Dumping the raw record lets the generic 6-column table fill up with noise
27
+ (tenant/created_by/modified_by) and hide the useful fields, so project to
28
+ risk_level/objective/status explicitly. `name` is skipped: the generation
29
+ workflow only fills `objective`, so generated pathways all have name=null
30
+ and the column renders as a useless "None" for every row.
31
+ """
32
+ objective = data.get("objective") or ""
33
+ if len(objective) > 80:
34
+ objective = objective[:77] + "..."
35
+ return {
36
+ "id": data.get("id"),
37
+ "risk_level": data.get("risk_level"),
38
+ "objective": objective,
39
+ "status": data.get("status"),
40
+ }
41
+
42
+
43
+ def _simulation_row(data: Dict[str, Any]) -> Dict[str, Any]:
44
+ """Trim a simulation record to the columns worth showing in a list.
45
+
46
+ Same idea as ``_pathway_row``: the generic 6-column table picker would bury
47
+ verdict/simulation_score under base fields, so project explicitly. Names are
48
+ workflow-generated and long, so truncate them.
49
+ """
50
+ name = data.get("name") or ""
51
+ if len(name) > 40:
52
+ name = name[:37] + "..."
53
+ return {
54
+ "id": data.get("id"),
55
+ "name": name,
56
+ "status": data.get("status"),
57
+ "verdict": data.get("verdict"),
58
+ "simulation_score": data.get("simulation_score"),
59
+ }
60
+
61
+
21
62
  def _client(ctx):
22
63
  """Build the config + client tuple used by every command."""
23
64
  config, token, tenant_id, user_id = get_client_config(ctx.obj["PROFILE"], api_url=ctx.obj.get("API_URL"))
24
65
  return TestZeusClient(**config), token, tenant_id, user_id
25
66
 
26
67
 
27
- async def _auth(client, token):
68
+ async def _auth(client, token, tenant_id=None):
28
69
  if token:
29
- initialize_client_with_token(client, token)
70
+ # Thread the profile tenant so tenant injection works even when the token
71
+ # has no tenant claim; otherwise create/run fails deep in the SDK with
72
+ # "No tenant ID available when adding tenant ID".
73
+ initialize_client_with_token(client, token, profile_tenant_id=tenant_id)
30
74
  else:
31
75
  await client.ensure_authenticated()
32
76
  if not hasattr(client, "agent_harness"):
@@ -49,9 +93,9 @@ def list_agents(ctx, page, per_page, status, search):
49
93
  """List available agents"""
50
94
 
51
95
  async def _run():
52
- client, token, _, _ = _client(ctx)
96
+ client, token, tenant_id, _ = _client(ctx)
53
97
  async with client:
54
- await _auth(client, token)
98
+ await _auth(client, token, tenant_id)
55
99
  return await client.agent_harness.list_agents(page=page, per_page=per_page, status=status, search=search)
56
100
 
57
101
  try:
@@ -75,13 +119,19 @@ def list_pathways(ctx, agent_id, page, per_page):
75
119
  # argument instead. The SDK builds the agent_id filter via the shared filter
76
120
  # builder; add --filters/--sort here if the manager grows to support them.
77
121
  async def _run():
78
- client, token, _, _ = _client(ctx)
122
+ client, token, tenant_id, _ = _client(ctx)
79
123
  async with client:
80
- await _auth(client, token)
124
+ await _auth(client, token, tenant_id)
81
125
  agent = validate_id(agent_id, "agent")
82
126
  res = await client.agent_harness.list_pathways(agent_id=agent, page=page, per_page=per_page)
83
- # get_list returns AdversaryPathways models; unwrap to dicts for output.
84
- res["items"] = [p.data for p in res.get("items", [])]
127
+ # get_list returns AdversaryPathways models. For the table, project to
128
+ # the useful columns (risk/objective/status) so they aren't crowded
129
+ # out; keep full records for json/yaml so machine-readable output
130
+ # stays lossless.
131
+ items = [p.data for p in res.get("items", [])]
132
+ if ctx.obj["FORMAT"] == "table":
133
+ items = [_pathway_row(d) for d in items]
134
+ res["items"] = items
85
135
  return res
86
136
 
87
137
  try:
@@ -104,9 +154,9 @@ def generate_pathways(ctx, agent_profile, prompt, name, agent_name, num, allow_d
104
154
  """Start an AI pathway-generation job for a Salesforce agent profile"""
105
155
 
106
156
  async def _run():
107
- client, token, _, _ = _client(ctx)
157
+ client, token, tenant_id, _ = _client(ctx)
108
158
  async with client:
109
- await _auth(client, token)
159
+ await _auth(client, token, tenant_id)
110
160
  # tenant/created_by/modified_by are auto-filled by the SDK manager.
111
161
  return await client.agent_harness.generate_pathways(
112
162
  agent_profile=agent_profile,
@@ -140,9 +190,9 @@ def run(ctx, agent_id, pathways, name, agent_name, run_as_profile, wait, timeout
140
190
  """Run adversarial simulations for the given pathways"""
141
191
 
142
192
  async def _run():
143
- client, token, _, _ = _client(ctx)
193
+ client, token, tenant_id, _ = _client(ctx)
144
194
  async with client:
145
- await _auth(client, token)
195
+ await _auth(client, token, tenant_id)
146
196
  agent = validate_id(agent_id, "agent")
147
197
  # tenant/created_by/modified_by are auto-filled by the SDK manager.
148
198
  if wait:
@@ -187,9 +237,9 @@ def status(ctx, group_id):
187
237
  """Get the status/results of a simulation run group"""
188
238
 
189
239
  async def _run():
190
- client, token, _, _ = _client(ctx)
240
+ client, token, tenant_id, _ = _client(ctx)
191
241
  async with client:
192
- await _auth(client, token)
242
+ await _auth(client, token, tenant_id)
193
243
  return await client.agent_harness.get_status(validate_id(group_id, "group"))
194
244
 
195
245
  try:
@@ -206,9 +256,9 @@ def cancel(ctx, group_id):
206
256
  """Cancel a running simulation group"""
207
257
 
208
258
  async def _run():
209
- client, token, _, _ = _client(ctx)
259
+ client, token, tenant_id, _ = _client(ctx)
210
260
  async with client:
211
- await _auth(client, token)
261
+ await _auth(client, token, tenant_id)
212
262
  return await client.agent_harness.cancel(validate_id(group_id, "group"))
213
263
 
214
264
  try:
@@ -226,19 +276,98 @@ def get_agent(ctx, agent_id):
226
276
  """Get full detail for a single agent"""
227
277
 
228
278
  async def _run():
229
- client, token, _, _ = _client(ctx)
279
+ client, token, tenant_id, _ = _client(ctx)
230
280
  async with client:
231
- await _auth(client, token)
281
+ await _auth(client, token, tenant_id)
232
282
  return await client.agent_harness.get_agent(validate_id(agent_id, "agent"))
233
283
 
234
284
  try:
235
285
  print_platform_link(ctx, "agent-harness")
236
- format_output(asyncio.run(_run()), ctx.obj["FORMAT"])
286
+ result = asyncio.run(_run())
287
+ # The gateway wraps the agent under "item"; unwrap it so the full record
288
+ # renders as a field table instead of collapsing to one "name (id)" line.
289
+ if isinstance(result, dict) and isinstance(result.get("item"), dict):
290
+ result = result["item"]
291
+ format_output(result, ctx.obj["FORMAT"])
237
292
  except Exception as e:
238
293
  print_message(f"[red]Error getting agent: {str(e)}[/red]", ctx.obj["FORMAT"])
239
294
  raise click.Abort()
240
295
 
241
296
 
297
+ @agent_harness_group.command(name="get-pathway")
298
+ @click.argument("pathway_id")
299
+ @click.pass_context
300
+ def get_pathway(ctx, pathway_id):
301
+ """Get full detail for a single adversarial pathway"""
302
+
303
+ async def _run():
304
+ client, token, tenant_id, _ = _client(ctx)
305
+ async with client:
306
+ await _auth(client, token, tenant_id)
307
+ # The facade has no get_pathway method; adversary_pathways is a plain
308
+ # PocketBase collection, so go through the sub-manager's get_one.
309
+ return await client.agent_harness.pathways.get_one(validate_id(pathway_id, "pathway"))
310
+
311
+ try:
312
+ print_platform_link(ctx, "agent-harness")
313
+ result = asyncio.run(_run())
314
+ format_output(result.data, ctx.obj["FORMAT"])
315
+ except Exception as e:
316
+ print_message(f"[red]Error getting pathway: {str(e)}[/red]", ctx.obj["FORMAT"])
317
+ raise click.Abort()
318
+
319
+
320
+ @agent_harness_group.command(name="list-simulations")
321
+ @click.argument("group_id")
322
+ @click.option("--page", default=1, help="Page number")
323
+ @click.option("--per-page", default=50, help="Results per page")
324
+ @click.pass_context
325
+ def list_simulations(ctx, group_id, page, per_page):
326
+ """List the simulations of a run group"""
327
+
328
+ async def _run():
329
+ client, token, tenant_id, _ = _client(ctx)
330
+ async with client:
331
+ await _auth(client, token, tenant_id)
332
+ group = validate_id(group_id, "group")
333
+ res = await client.agent_harness.list_simulations(group_id=group, page=page, per_page=per_page)
334
+ # Same format-aware projection as list-pathways: useful columns for
335
+ # the table, full records for json/yaml.
336
+ items = [s.data for s in res.get("items", [])]
337
+ if ctx.obj["FORMAT"] == "table":
338
+ items = [_simulation_row(d) for d in items]
339
+ res["items"] = items
340
+ return res
341
+
342
+ try:
343
+ print_platform_link(ctx, "agent-harness")
344
+ format_output(asyncio.run(_run()), ctx.obj["FORMAT"])
345
+ except Exception as e:
346
+ print_message(f"[red]Error listing simulations: {str(e)}[/red]", ctx.obj["FORMAT"])
347
+ raise click.Abort()
348
+
349
+
350
+ @agent_harness_group.command(name="get-simulation")
351
+ @click.argument("simulation_id")
352
+ @click.pass_context
353
+ def get_simulation(ctx, simulation_id):
354
+ """Get full detail for a single simulation"""
355
+
356
+ async def _run():
357
+ client, token, tenant_id, _ = _client(ctx)
358
+ async with client:
359
+ await _auth(client, token, tenant_id)
360
+ return await client.agent_harness.get_simulation(validate_id(simulation_id, "simulation"))
361
+
362
+ try:
363
+ print_platform_link(ctx, "agent-harness")
364
+ result = asyncio.run(_run())
365
+ format_output(result.data, ctx.obj["FORMAT"])
366
+ except Exception as e:
367
+ print_message(f"[red]Error getting simulation: {str(e)}[/red]", ctx.obj["FORMAT"])
368
+ raise click.Abort()
369
+
370
+
242
371
  @agent_harness_group.command(name="delete-pathway")
243
372
  @click.argument("pathway_id")
244
373
  @click.pass_context
@@ -246,9 +375,9 @@ def delete_pathway(ctx, pathway_id):
246
375
  """Soft-delete an adversarial pathway"""
247
376
 
248
377
  async def _run():
249
- client, token, _, _ = _client(ctx)
378
+ client, token, tenant_id, _ = _client(ctx)
250
379
  async with client:
251
- await _auth(client, token)
380
+ await _auth(client, token, tenant_id)
252
381
  return await client.agent_harness.delete_pathway(validate_id(pathway_id, "pathway"))
253
382
 
254
383
  try:
@@ -0,0 +1,123 @@
1
+ """
2
+ Connected environment management commands for TestZeus CLI.
3
+
4
+ Scoped to read + rename only: connected environments are created and their code /
5
+ metadata files are managed from the web UI, so the CLI exposes just ``list``,
6
+ ``get`` and a name-only ``update``.
7
+ """
8
+
9
+ import asyncio
10
+ import click
11
+ from rich.console import Console
12
+ from testzeus_sdk import TestZeusClient
13
+ from testzeus_cli.config import get_client_config
14
+ from testzeus_cli.utils.formatters import format_output, print_message
15
+ from testzeus_cli.utils.auth import initialize_client_with_token
16
+ from testzeus_cli.utils.validators import parse_key_value_pairs, validate_tenant_ownership
17
+
18
+ console = Console()
19
+
20
+
21
+ @click.group()
22
+ def connected_environments_group():
23
+ """Manage connected environments in TestZeus"""
24
+ pass
25
+
26
+
27
+ @connected_environments_group.command(name="list")
28
+ @click.option("--filters", "-f", multiple=True, help="Filter results (format: key=value)")
29
+ @click.option("--sort", help="Sort by field")
30
+ @click.option("--expand", help="Expand related entities")
31
+ @click.pass_context
32
+ def list(ctx, filters, sort, expand):
33
+ """List all connected environments"""
34
+
35
+ async def _run():
36
+ config, token, _, _ = get_client_config(ctx.obj["PROFILE"], api_url=ctx.obj.get("API_URL"))
37
+ client = TestZeusClient(**config)
38
+ filter_dict = parse_key_value_pairs(filters) if filters else {}
39
+ async with client:
40
+ if token:
41
+ initialize_client_with_token(client, token)
42
+ else:
43
+ await client.ensure_authenticated()
44
+ result = await client.connected_environments.get_list(expand=expand, sort=sort, filters=filter_dict)
45
+ return result
46
+
47
+ try:
48
+ result = asyncio.run(_run())
49
+ format_output(result, ctx.obj["FORMAT"])
50
+ except Exception as e:
51
+ print_message(
52
+ f"[red]Error listing connected environments: {str(e)}[/red]",
53
+ ctx.obj["FORMAT"],
54
+ )
55
+ raise click.Abort()
56
+
57
+
58
+ @connected_environments_group.command(name="get")
59
+ @click.argument("conn_env_id")
60
+ @click.option("--expand", help="Expand related entities")
61
+ @click.pass_context
62
+ def get(ctx, conn_env_id, expand):
63
+ """Get a connected environment by ID"""
64
+
65
+ async def _run():
66
+ config, token, _, _ = get_client_config(ctx.obj["PROFILE"], api_url=ctx.obj.get("API_URL"))
67
+ client = TestZeusClient(**config)
68
+ async with client:
69
+ if token:
70
+ initialize_client_with_token(client, token)
71
+ else:
72
+ await client.ensure_authenticated()
73
+ conn_env = await client.connected_environments.get_one(conn_env_id, expand=expand)
74
+ return conn_env.data
75
+
76
+ try:
77
+ result = asyncio.run(_run())
78
+ format_output(result, ctx.obj["FORMAT"])
79
+ except Exception as e:
80
+ print_message(
81
+ f"[red]Error getting connected environment: {str(e)}[/red]",
82
+ ctx.obj["FORMAT"],
83
+ )
84
+ raise click.Abort()
85
+
86
+
87
+ @connected_environments_group.command(name="update")
88
+ @click.argument("conn_env_id")
89
+ @click.option("--name", required=True, help="New connected environment name")
90
+ @click.pass_context
91
+ def update(ctx, conn_env_id, name):
92
+ """Update a connected environment's name"""
93
+
94
+ async def _run():
95
+ config, token, tenant_id, user_id = get_client_config(ctx.obj["PROFILE"], api_url=ctx.obj.get("API_URL"))
96
+ client = TestZeusClient(**config)
97
+ async with client:
98
+ if token:
99
+ initialize_client_with_token(client, token)
100
+ else:
101
+ await client.ensure_authenticated()
102
+
103
+ # Validate tenant ownership before updating.
104
+ conn_env = await client.connected_environments.get_one(conn_env_id)
105
+ validate_tenant_ownership(conn_env.data, tenant_id, "connected environment")
106
+
107
+ updates = {"tenant": tenant_id, "modified_by": user_id, "name": name}
108
+ updated = await client.connected_environments.update(conn_env_id, updates)
109
+ return updated.data
110
+
111
+ try:
112
+ result = asyncio.run(_run())
113
+ print_message(
114
+ "[green]Connected environment updated successfully[/green]",
115
+ ctx.obj["FORMAT"],
116
+ )
117
+ format_output(result, ctx.obj["FORMAT"])
118
+ except Exception as e:
119
+ print_message(
120
+ f"[red]Error updating connected environment: {str(e)}[/red]",
121
+ ctx.obj["FORMAT"],
122
+ )
123
+ raise click.Abort()
@@ -1,447 +0,0 @@
1
- """
2
- Connected environment management commands for TestZeus CLI.
3
- """
4
-
5
- import asyncio
6
- import click
7
- from rich.console import Console
8
- from testzeus_sdk import TestZeusClient
9
- from testzeus_cli.config import get_client_config
10
- from testzeus_cli.utils.formatters import format_output, print_message
11
- from testzeus_cli.utils.auth import initialize_client_with_token
12
- from testzeus_cli.utils.validators import parse_key_value_pairs, validate_tenant_ownership
13
-
14
- console = Console()
15
-
16
-
17
- @click.group()
18
- def connected_environments_group():
19
- """Manage connected environments in TestZeus"""
20
- pass
21
-
22
-
23
- @connected_environments_group.command(name="create")
24
- @click.option("--name", required=True, help="Connected environment name")
25
- @click.option("--connection", help="Connection ID or name to link with")
26
- @click.option("--tags", help="Comma-separated list of tags")
27
- @click.option(
28
- "--metadata",
29
- "-m",
30
- multiple=True,
31
- help="Metadata entries (format: key=value)",
32
- )
33
- @click.option(
34
- "--skip-process",
35
- is_flag=True,
36
- default=False,
37
- help="Skip processing on create",
38
- )
39
- @click.pass_context
40
- def create(ctx, name, connection, tags, metadata, skip_process):
41
- """Create a new connected environment"""
42
-
43
- async def _run():
44
- config, token, stored_tenant_id, stored_user_id = get_client_config(ctx.obj["PROFILE"], api_url=ctx.obj.get("API_URL"))
45
- client = TestZeusClient(**config)
46
-
47
- async with client:
48
- if token:
49
- initialize_client_with_token(client, token)
50
- else:
51
- await client.ensure_authenticated()
52
-
53
- params = {
54
- "name": name,
55
- "tenant": stored_tenant_id,
56
- "modified_by": stored_user_id,
57
- "skip_process": skip_process,
58
- "metadata": parse_key_value_pairs(metadata) if metadata else {},
59
- }
60
-
61
- if connection:
62
- params["connection"] = connection
63
-
64
- if tags:
65
- params["tags"] = tags.split(",")
66
-
67
- conn_env = await client.connected_environments.create(params)
68
- return conn_env.data
69
-
70
- try:
71
- result = asyncio.run(_run())
72
- print_message(
73
- f"[green]Connected environment created successfully with ID: " f"{result['id']}[/green]",
74
- ctx.obj["FORMAT"],
75
- )
76
- format_output(result, ctx.obj["FORMAT"])
77
- except Exception as e:
78
- print_message(
79
- f"[red]Error creating connected environment: {str(e)}[/red]",
80
- ctx.obj["FORMAT"],
81
- )
82
- raise click.Abort()
83
-
84
-
85
- @connected_environments_group.command(name="list")
86
- @click.option("--filters", "-f", multiple=True, help="Filter results (format: key=value)")
87
- @click.option("--sort", help="Sort by field")
88
- @click.option("--expand", help="Expand related entities")
89
- @click.pass_context
90
- def list(ctx, filters, sort, expand):
91
- """List all connected environments"""
92
-
93
- async def _run():
94
- config, token, _, _ = get_client_config(ctx.obj["PROFILE"], api_url=ctx.obj.get("API_URL"))
95
- client = TestZeusClient(**config)
96
- filter_dict = parse_key_value_pairs(filters) if filters else {}
97
- async with client:
98
- if token:
99
- initialize_client_with_token(client, token)
100
- else:
101
- await client.ensure_authenticated()
102
- result = await client.connected_environments.get_list(expand=expand, sort=sort, filters=filter_dict)
103
- return result
104
-
105
- try:
106
- result = asyncio.run(_run())
107
- format_output(result, ctx.obj["FORMAT"])
108
- except Exception as e:
109
- print_message(
110
- f"[red]Error listing connected environments: {str(e)}[/red]",
111
- ctx.obj["FORMAT"],
112
- )
113
- raise click.Abort()
114
-
115
-
116
- @connected_environments_group.command(name="get")
117
- @click.argument("conn_env_id")
118
- @click.option("--expand", help="Expand related entities")
119
- @click.pass_context
120
- def get(ctx, conn_env_id, expand):
121
- """Get a connected environment by ID"""
122
-
123
- async def _run():
124
- config, token, _, _ = get_client_config(ctx.obj["PROFILE"], api_url=ctx.obj.get("API_URL"))
125
- client = TestZeusClient(**config)
126
- async with client:
127
- if token:
128
- initialize_client_with_token(client, token)
129
- else:
130
- await client.ensure_authenticated()
131
- conn_env = await client.connected_environments.get_one(conn_env_id, expand=expand)
132
- return conn_env.data
133
-
134
- try:
135
- result = asyncio.run(_run())
136
- format_output(result, ctx.obj["FORMAT"])
137
- except Exception as e:
138
- print_message(
139
- f"[red]Error getting connected environment: {str(e)}[/red]",
140
- ctx.obj["FORMAT"],
141
- )
142
- raise click.Abort()
143
-
144
-
145
- @connected_environments_group.command(name="update")
146
- @click.argument("conn_env_id")
147
- @click.option("--name", help="New connected environment name")
148
- @click.option("--connection", help="Connection ID or name to link with")
149
- @click.option("--tags", help="Comma-separated list of tags")
150
- @click.option(
151
- "--metadata",
152
- "-m",
153
- multiple=True,
154
- help="Metadata entries (format: key=value)",
155
- )
156
- @click.option(
157
- "--skip-process/--no-skip-process",
158
- default=None,
159
- help="Toggle processing skip",
160
- )
161
- @click.pass_context
162
- def update(ctx, conn_env_id, name, connection, tags, metadata, skip_process):
163
- """Update a connected environment"""
164
-
165
- async def _run():
166
- config, token, tenant_id, user_id = get_client_config(ctx.obj["PROFILE"], api_url=ctx.obj.get("API_URL"))
167
- client = TestZeusClient(**config)
168
- async with client:
169
- if token:
170
- initialize_client_with_token(client, token)
171
- else:
172
- await client.ensure_authenticated()
173
-
174
- # Validate tenant ownership before updating
175
- conn_env = await client.connected_environments.get_one(conn_env_id)
176
- validate_tenant_ownership(conn_env.data, tenant_id, "connected environment")
177
-
178
- updates = {"tenant": tenant_id, "modified_by": user_id}
179
- has_updates = False
180
-
181
- if name:
182
- updates["name"] = name
183
- has_updates = True
184
-
185
- if connection:
186
- updates["connection"] = connection
187
- has_updates = True
188
-
189
- if tags and tags != "none":
190
- updates["tags"] = tags.split(",")
191
- has_updates = True
192
-
193
- if tags == "none":
194
- updates["tags"] = None
195
- has_updates = True
196
-
197
- if metadata:
198
- updates["metadata"] = parse_key_value_pairs(metadata)
199
- has_updates = True
200
-
201
- if skip_process is not None:
202
- updates["skip_process"] = skip_process
203
- has_updates = True
204
-
205
- if has_updates:
206
- updated = await client.connected_environments.update(conn_env_id, updates)
207
- return updated.data
208
- else:
209
- print_message("[yellow]No updates provided[/yellow]", ctx.obj["FORMAT"])
210
- return None
211
-
212
- try:
213
- result = asyncio.run(_run())
214
- print_message(
215
- "[green]Connected environment updated successfully[/green]",
216
- ctx.obj["FORMAT"],
217
- )
218
- format_output(result, ctx.obj["FORMAT"])
219
- except Exception as e:
220
- print_message(
221
- f"[red]Error updating connected environment: {str(e)}[/red]",
222
- ctx.obj["FORMAT"],
223
- )
224
- raise click.Abort()
225
-
226
-
227
- @connected_environments_group.command(name="delete")
228
- @click.argument("conn_env_id")
229
- @click.pass_context
230
- def delete(ctx, conn_env_id):
231
- """Delete a connected environment"""
232
-
233
- async def _run():
234
- config, token, stored_tenant_id, _ = get_client_config(ctx.obj["PROFILE"], api_url=ctx.obj.get("API_URL"))
235
- client = TestZeusClient(**config)
236
- async with client:
237
- if token:
238
- initialize_client_with_token(client, token)
239
- else:
240
- await client.ensure_authenticated()
241
-
242
- # Validate tenant ownership before deleting
243
- conn_env = await client.connected_environments.get_one(conn_env_id)
244
- validate_tenant_ownership(conn_env.data, stored_tenant_id, "connected environment")
245
-
246
- await client.connected_environments.delete(conn_env_id)
247
- return {"id": conn_env_id}
248
-
249
- try:
250
- result = asyncio.run(_run())
251
- print_message(
252
- f"[green]Connected environment {result['id']} deleted successfully[/green]",
253
- ctx.obj["FORMAT"],
254
- )
255
- except Exception as e:
256
- print_message(
257
- f"[red]Error deleting connected environment: {str(e)}[/red]",
258
- ctx.obj["FORMAT"],
259
- )
260
- raise click.Abort()
261
-
262
-
263
- @connected_environments_group.command(name="add-code-file", help="Add a code file to a connected environment")
264
- @click.argument("conn_env_id")
265
- @click.argument("file_path", type=click.Path(exists=True))
266
- @click.pass_context
267
- def add_code_file(ctx, conn_env_id, file_path):
268
- """Add a code file to a connected environment"""
269
-
270
- async def _run():
271
- config, token, _, _ = get_client_config(ctx.obj["PROFILE"], api_url=ctx.obj.get("API_URL"))
272
- client = TestZeusClient(**config)
273
- async with client:
274
- if token:
275
- initialize_client_with_token(client, token)
276
- else:
277
- await client.ensure_authenticated()
278
- conn_env = await client.connected_environments.add_code_file(conn_env_id, file_path)
279
- return conn_env.data
280
-
281
- try:
282
- result = asyncio.run(_run())
283
- print_message(
284
- f"[green]Code file added to connected environment {conn_env_id}[/green]",
285
- ctx.obj["FORMAT"],
286
- )
287
- format_output(result, ctx.obj["FORMAT"])
288
- except Exception as e:
289
- print_message(f"[red]Error adding code file: {str(e)}[/red]", ctx.obj["FORMAT"])
290
- raise click.Abort()
291
-
292
-
293
- @connected_environments_group.command(name="remove-code-file", help="Remove a code file from a connected environment")
294
- @click.argument("conn_env_id")
295
- @click.argument("file_name")
296
- @click.pass_context
297
- def remove_code_file(ctx, conn_env_id, file_name):
298
- """Remove a code file from a connected environment"""
299
-
300
- async def _run():
301
- config, token, _, _ = get_client_config(ctx.obj["PROFILE"], api_url=ctx.obj.get("API_URL"))
302
- client = TestZeusClient(**config)
303
- async with client:
304
- if token:
305
- initialize_client_with_token(client, token)
306
- else:
307
- await client.ensure_authenticated()
308
- conn_env = await client.connected_environments.remove_code_file(conn_env_id, file_name)
309
- return conn_env.data
310
-
311
- try:
312
- result = asyncio.run(_run())
313
- print_message(
314
- f"[green]Code file removed from connected environment {conn_env_id}[/green]",
315
- ctx.obj["FORMAT"],
316
- )
317
- format_output(result, ctx.obj["FORMAT"])
318
- except Exception as e:
319
- print_message(f"[red]Error removing code file: {str(e)}[/red]", ctx.obj["FORMAT"])
320
- raise click.Abort()
321
-
322
-
323
- @connected_environments_group.command(
324
- name="delete-all-code-files",
325
- help="Remove all code files from a connected environment",
326
- )
327
- @click.argument("conn_env_id")
328
- @click.pass_context
329
- def delete_all_code_files(ctx, conn_env_id):
330
- """Remove all code files from a connected environment"""
331
-
332
- async def _run():
333
- config, token, _, _ = get_client_config(ctx.obj["PROFILE"], api_url=ctx.obj.get("API_URL"))
334
- client = TestZeusClient(**config)
335
- async with client:
336
- if token:
337
- initialize_client_with_token(client, token)
338
- else:
339
- await client.ensure_authenticated()
340
- conn_env = await client.connected_environments.remove_all_code_files(conn_env_id)
341
- return conn_env.data
342
-
343
- try:
344
- result = asyncio.run(_run())
345
- print_message(
346
- f"[green]All code files removed from connected environment " f"{conn_env_id}[/green]",
347
- ctx.obj["FORMAT"],
348
- )
349
- format_output(result, ctx.obj["FORMAT"])
350
- except Exception as e:
351
- print_message(f"[red]Error removing code files: {str(e)}[/red]", ctx.obj["FORMAT"])
352
- raise click.Abort()
353
-
354
-
355
- @connected_environments_group.command(name="add-metadata-file", help="Add a metadata file to a connected environment")
356
- @click.argument("conn_env_id")
357
- @click.argument("file_path", type=click.Path(exists=True))
358
- @click.pass_context
359
- def add_metadata_file(ctx, conn_env_id, file_path):
360
- """Add a metadata file to a connected environment"""
361
-
362
- async def _run():
363
- config, token, _, _ = get_client_config(ctx.obj["PROFILE"], api_url=ctx.obj.get("API_URL"))
364
- client = TestZeusClient(**config)
365
- async with client:
366
- if token:
367
- initialize_client_with_token(client, token)
368
- else:
369
- await client.ensure_authenticated()
370
- conn_env = await client.connected_environments.add_metadata_file(conn_env_id, file_path)
371
- return conn_env.data
372
-
373
- try:
374
- result = asyncio.run(_run())
375
- print_message(
376
- f"[green]Metadata file added to connected environment {conn_env_id}[/green]",
377
- ctx.obj["FORMAT"],
378
- )
379
- format_output(result, ctx.obj["FORMAT"])
380
- except Exception as e:
381
- print_message(f"[red]Error adding metadata file: {str(e)}[/red]", ctx.obj["FORMAT"])
382
- raise click.Abort()
383
-
384
-
385
- @connected_environments_group.command(
386
- name="remove-metadata-file",
387
- help="Remove a metadata file from a connected environment",
388
- )
389
- @click.argument("conn_env_id")
390
- @click.argument("file_name")
391
- @click.pass_context
392
- def remove_metadata_file(ctx, conn_env_id, file_name):
393
- """Remove a metadata file from a connected environment"""
394
-
395
- async def _run():
396
- config, token, _, _ = get_client_config(ctx.obj["PROFILE"], api_url=ctx.obj.get("API_URL"))
397
- client = TestZeusClient(**config)
398
- async with client:
399
- if token:
400
- initialize_client_with_token(client, token)
401
- else:
402
- await client.ensure_authenticated()
403
- conn_env = await client.connected_environments.remove_metadata_file(conn_env_id, file_name)
404
- return conn_env.data
405
-
406
- try:
407
- result = asyncio.run(_run())
408
- print_message(
409
- f"[green]Metadata file removed from connected environment " f"{conn_env_id}[/green]",
410
- ctx.obj["FORMAT"],
411
- )
412
- format_output(result, ctx.obj["FORMAT"])
413
- except Exception as e:
414
- print_message(f"[red]Error removing metadata file: {str(e)}[/red]", ctx.obj["FORMAT"])
415
- raise click.Abort()
416
-
417
-
418
- @connected_environments_group.command(
419
- name="delete-all-metadata-files",
420
- help="Remove all metadata files from a connected environment",
421
- )
422
- @click.argument("conn_env_id")
423
- @click.pass_context
424
- def delete_all_metadata_files(ctx, conn_env_id):
425
- """Remove all metadata files from a connected environment"""
426
-
427
- async def _run():
428
- config, token, _, _ = get_client_config(ctx.obj["PROFILE"], api_url=ctx.obj.get("API_URL"))
429
- client = TestZeusClient(**config)
430
- async with client:
431
- if token:
432
- initialize_client_with_token(client, token)
433
- else:
434
- await client.ensure_authenticated()
435
- conn_env = await client.connected_environments.remove_all_metadata_files(conn_env_id)
436
- return conn_env.data
437
-
438
- try:
439
- result = asyncio.run(_run())
440
- print_message(
441
- f"[green]All metadata files removed from connected environment " f"{conn_env_id}[/green]",
442
- ctx.obj["FORMAT"],
443
- )
444
- format_output(result, ctx.obj["FORMAT"])
445
- except Exception as e:
446
- print_message(f"[red]Error removing metadata files: {str(e)}[/red]", ctx.obj["FORMAT"])
447
- raise click.Abort()
File without changes
File without changes