testzeus-cli 0.0.5__tar.gz → 0.0.6__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.
- {testzeus_cli-0.0.5 → testzeus_cli-0.0.6}/PKG-INFO +2 -2
- {testzeus_cli-0.0.5 → testzeus_cli-0.0.6}/pyproject.toml +3 -2
- {testzeus_cli-0.0.5 → testzeus_cli-0.0.6}/testzeus_cli/auth.py +8 -6
- testzeus_cli-0.0.6/testzeus_cli/commands/environments.py +251 -0
- testzeus_cli-0.0.6/testzeus_cli/commands/tags.py +190 -0
- {testzeus_cli-0.0.5 → testzeus_cli-0.0.6}/testzeus_cli/commands/test_data.py +127 -84
- {testzeus_cli-0.0.5 → testzeus_cli-0.0.6}/testzeus_cli/commands/test_runs.py +18 -100
- {testzeus_cli-0.0.5 → testzeus_cli-0.0.6}/testzeus_cli/commands/tests.py +16 -98
- {testzeus_cli-0.0.5 → testzeus_cli-0.0.6}/testzeus_cli/config.py +22 -4
- {testzeus_cli-0.0.5 → testzeus_cli-0.0.6}/testzeus_cli/utils/auth.py +12 -7
- {testzeus_cli-0.0.5 → testzeus_cli-0.0.6}/testzeus_cli/utils/client.py +1 -1
- {testzeus_cli-0.0.5 → testzeus_cli-0.0.6}/testzeus_cli/utils/validators.py +3 -3
- testzeus_cli-0.0.5/testzeus_cli/commands/environments.py +0 -116
- testzeus_cli-0.0.5/testzeus_cli/commands/tags.py +0 -103
- {testzeus_cli-0.0.5 → testzeus_cli-0.0.6}/LICENSE +0 -0
- {testzeus_cli-0.0.5 → testzeus_cli-0.0.6}/README.md +0 -0
- {testzeus_cli-0.0.5 → testzeus_cli-0.0.6}/testzeus_cli/__init__.py +0 -0
- {testzeus_cli-0.0.5 → testzeus_cli-0.0.6}/testzeus_cli/cli.py +0 -0
- {testzeus_cli-0.0.5 → testzeus_cli-0.0.6}/testzeus_cli/commands/__init__.py +0 -0
- {testzeus_cli-0.0.5 → testzeus_cli-0.0.6}/testzeus_cli/utils/__init__.py +0 -0
- {testzeus_cli-0.0.5 → testzeus_cli-0.0.6}/testzeus_cli/utils/formatters.py +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.1
|
|
2
2
|
Name: testzeus-cli
|
|
3
|
-
Version: 0.0.
|
|
3
|
+
Version: 0.0.6
|
|
4
4
|
Summary: Command-line interface for TestZeus testing platform
|
|
5
5
|
Home-page: https://github.com/test-zeus-ai/testzeus-cli
|
|
6
6
|
Author: Shriyansh Agnihotri
|
|
@@ -15,7 +15,7 @@ Requires-Dist: keyring (>=24.0.0,<25.0.0)
|
|
|
15
15
|
Requires-Dist: pydantic (>=2.0.0,<3.0.0)
|
|
16
16
|
Requires-Dist: pyyaml (>=6.0,<7.0)
|
|
17
17
|
Requires-Dist: rich (>=13.3.1,<14.0.0)
|
|
18
|
-
Requires-Dist: testzeus-sdk (>=0.0.
|
|
18
|
+
Requires-Dist: testzeus-sdk (>=0.0.9,<0.0.10)
|
|
19
19
|
Project-URL: Repository, https://github.com/test-zeus-ai/testzeus-cli
|
|
20
20
|
Description-Content-Type: text/markdown
|
|
21
21
|
|
|
@@ -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.
|
|
7
|
+
version = "0.0.6"
|
|
8
8
|
description = "Command-line interface for TestZeus testing platform"
|
|
9
9
|
authors = ["Shriyansh Agnihotri <shriyansh@testzeus.com>"]
|
|
10
10
|
readme = "README.md"
|
|
@@ -22,12 +22,13 @@ 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.
|
|
25
|
+
testzeus-sdk = "^0.0.9"
|
|
26
26
|
|
|
27
27
|
[tool.poetry.group.dev.dependencies]
|
|
28
28
|
pytest = "^7.3.1"
|
|
29
29
|
black = "^23.3.0"
|
|
30
30
|
isort = "^5.12.0"
|
|
31
|
+
python-dotenv = "^1.0.0"
|
|
31
32
|
|
|
32
33
|
[tool.poetry.scripts]
|
|
33
34
|
testzeus = "testzeus_cli.cli:main"
|
|
@@ -34,7 +34,7 @@ def login_command(
|
|
|
34
34
|
password = getpass("Password: ")
|
|
35
35
|
|
|
36
36
|
async def _login() -> Dict[str, Any]:
|
|
37
|
-
config, _ = get_client_config(
|
|
37
|
+
config, _, _, _ = get_client_config(
|
|
38
38
|
ctx.obj["PROFILE"], api_url=ctx.obj.get("API_URL")
|
|
39
39
|
)
|
|
40
40
|
|
|
@@ -51,6 +51,7 @@ def login_command(
|
|
|
51
51
|
|
|
52
52
|
# Get tenant ID from the authenticated client
|
|
53
53
|
tenant_id = client.get_tenant_id()
|
|
54
|
+
user_id = client.get_user_id()
|
|
54
55
|
|
|
55
56
|
if save:
|
|
56
57
|
update_config(
|
|
@@ -60,6 +61,7 @@ def login_command(
|
|
|
60
61
|
"email": email,
|
|
61
62
|
"token": token,
|
|
62
63
|
"tenant_id": tenant_id,
|
|
64
|
+
"user_id": user_id,
|
|
63
65
|
},
|
|
64
66
|
)
|
|
65
67
|
|
|
@@ -68,7 +70,7 @@ def login_command(
|
|
|
68
70
|
"api_url": client.base_url,
|
|
69
71
|
"authenticated": client.is_authenticated(),
|
|
70
72
|
"tenant_id": tenant_id,
|
|
71
|
-
"user_id":
|
|
73
|
+
"user_id": user_id,
|
|
72
74
|
}
|
|
73
75
|
|
|
74
76
|
try:
|
|
@@ -97,9 +99,10 @@ def whoami_command(ctx: click.Context) -> None:
|
|
|
97
99
|
"""Show current user information"""
|
|
98
100
|
|
|
99
101
|
async def _whoami() -> Dict[str, Any]:
|
|
100
|
-
config, token = get_client_config(
|
|
102
|
+
config, token, stored_tenant_id, stored_user_id = get_client_config(
|
|
101
103
|
ctx.obj["PROFILE"], api_url=ctx.obj.get("API_URL")
|
|
102
104
|
)
|
|
105
|
+
|
|
103
106
|
client = TestZeusClient(**config)
|
|
104
107
|
|
|
105
108
|
try:
|
|
@@ -109,12 +112,11 @@ def whoami_command(ctx: click.Context) -> None:
|
|
|
109
112
|
initialize_client_with_token(client, token)
|
|
110
113
|
else:
|
|
111
114
|
await client.ensure_authenticated()
|
|
112
|
-
|
|
113
115
|
return {
|
|
114
116
|
"email": client.email,
|
|
115
117
|
"api_url": client.base_url,
|
|
116
|
-
"tenant_id":
|
|
117
|
-
"user_id":
|
|
118
|
+
"tenant_id": stored_tenant_id,
|
|
119
|
+
"user_id": stored_user_id,
|
|
118
120
|
}
|
|
119
121
|
except Exception as e:
|
|
120
122
|
console.print(f"[red]Not authenticated:[/red] {str(e)}")
|
|
@@ -0,0 +1,251 @@
|
|
|
1
|
+
"""
|
|
2
|
+
Environment management commands for TestZeus CLI.
|
|
3
|
+
"""
|
|
4
|
+
|
|
5
|
+
import asyncio
|
|
6
|
+
import click
|
|
7
|
+
from pathlib import Path
|
|
8
|
+
from rich.console import Console
|
|
9
|
+
from testzeus_sdk import TestZeusClient
|
|
10
|
+
from testzeus_cli.config import get_client_config
|
|
11
|
+
from testzeus_cli.utils.formatters import format_output
|
|
12
|
+
from testzeus_cli.utils.auth import initialize_client_with_token
|
|
13
|
+
from testzeus_cli.utils.validators import parse_key_value_pairs
|
|
14
|
+
|
|
15
|
+
console = Console()
|
|
16
|
+
|
|
17
|
+
def _read_data_file(file_path: str) -> str:
|
|
18
|
+
"""
|
|
19
|
+
Read data content from a file as plain text
|
|
20
|
+
Args:
|
|
21
|
+
file_path: Path to the data file
|
|
22
|
+
Returns:
|
|
23
|
+
The raw text content of the file
|
|
24
|
+
"""
|
|
25
|
+
data_path = Path(file_path)
|
|
26
|
+
if not data_path.exists():
|
|
27
|
+
raise click.BadParameter(f"Data file not found: {file_path}")
|
|
28
|
+
|
|
29
|
+
try:
|
|
30
|
+
with open(data_path, "r", encoding="utf-8") as f:
|
|
31
|
+
content = f.read().strip()
|
|
32
|
+
except Exception as e:
|
|
33
|
+
raise click.BadParameter(f"Failed to read data file: {str(e)}")
|
|
34
|
+
|
|
35
|
+
# Always return the raw text content
|
|
36
|
+
return content
|
|
37
|
+
|
|
38
|
+
@click.group()
|
|
39
|
+
def environments_group():
|
|
40
|
+
"""Manage environments in TestZeus"""
|
|
41
|
+
pass
|
|
42
|
+
|
|
43
|
+
|
|
44
|
+
@environments_group.command(name="create")
|
|
45
|
+
@click.option("--name", required=True, help="Environment name")
|
|
46
|
+
@click.option("--status", default="draft", help="Environment status (draft, ready, deleted)")
|
|
47
|
+
@click.option("--data", help="Environment data as text")
|
|
48
|
+
@click.option("--data-file", "-df", type=click.Path(exists=True), help="Path to text file with environment data")
|
|
49
|
+
@click.option("--tags", help="Comma-separated list of tags")
|
|
50
|
+
@click.pass_context
|
|
51
|
+
def create(ctx, name, status, data, data_file, tags):
|
|
52
|
+
"""Create a new environment"""
|
|
53
|
+
|
|
54
|
+
if data and data_file:
|
|
55
|
+
raise click.UsageError("Cannot use both --data and --data-file")
|
|
56
|
+
|
|
57
|
+
if not data and not data_file:
|
|
58
|
+
raise click.UsageError("Either --data or --data-file is required")
|
|
59
|
+
|
|
60
|
+
# Process the data content (from file or directly)
|
|
61
|
+
data_content = _read_data_file(data_file) if data_file else data
|
|
62
|
+
|
|
63
|
+
async def _run():
|
|
64
|
+
config, token, stored_tenant_id, stored_user_id = get_client_config(
|
|
65
|
+
ctx.obj["PROFILE"], api_url=ctx.obj.get("API_URL")
|
|
66
|
+
)
|
|
67
|
+
client = TestZeusClient(**config)
|
|
68
|
+
|
|
69
|
+
async with client:
|
|
70
|
+
if token:
|
|
71
|
+
initialize_client_with_token(client, token)
|
|
72
|
+
else:
|
|
73
|
+
await client.ensure_authenticated()
|
|
74
|
+
|
|
75
|
+
params = {"name": name, "status": status, "tenant": stored_tenant_id, "modified_by": stored_user_id}
|
|
76
|
+
|
|
77
|
+
if data_content:
|
|
78
|
+
params["data"] = data_content
|
|
79
|
+
|
|
80
|
+
if tags:
|
|
81
|
+
params["tags"] = tags.split(",")
|
|
82
|
+
|
|
83
|
+
env = await client.environments.create(params)
|
|
84
|
+
return env.data
|
|
85
|
+
|
|
86
|
+
try:
|
|
87
|
+
result = asyncio.run(_run())
|
|
88
|
+
console.print(
|
|
89
|
+
f"[green]Environment created successfully with ID: {result['id']}[/green]"
|
|
90
|
+
)
|
|
91
|
+
format_output(result, ctx.obj["FORMAT"])
|
|
92
|
+
except Exception as e:
|
|
93
|
+
console.print(f"[red]Error creating environment: {str(e)}[/red]")
|
|
94
|
+
raise click.Abort()
|
|
95
|
+
|
|
96
|
+
|
|
97
|
+
@environments_group.command(name="list")
|
|
98
|
+
@click.option("--filters", "-f", multiple=True, help="Filter results (format: key=value)")
|
|
99
|
+
@click.option("--sort", help="Sort by field")
|
|
100
|
+
@click.option("--expand", help="Expand related entities")
|
|
101
|
+
@click.pass_context
|
|
102
|
+
def list(ctx, filters, sort, expand):
|
|
103
|
+
"""List all environments"""
|
|
104
|
+
|
|
105
|
+
async def _run():
|
|
106
|
+
config, token, _, _ = get_client_config(
|
|
107
|
+
ctx.obj["PROFILE"], api_url=ctx.obj.get("API_URL")
|
|
108
|
+
)
|
|
109
|
+
client = TestZeusClient(**config)
|
|
110
|
+
filter_dict = parse_key_value_pairs(filters) if filters else {}
|
|
111
|
+
async with client:
|
|
112
|
+
if token:
|
|
113
|
+
initialize_client_with_token(client, token)
|
|
114
|
+
else:
|
|
115
|
+
await client.ensure_authenticated()
|
|
116
|
+
result = await client.environments.get_list(
|
|
117
|
+
expand=expand, sort=sort, filters=filter_dict
|
|
118
|
+
)
|
|
119
|
+
return result
|
|
120
|
+
|
|
121
|
+
try:
|
|
122
|
+
result = asyncio.run(_run())
|
|
123
|
+
format_output(result, ctx.obj["FORMAT"])
|
|
124
|
+
except Exception as e:
|
|
125
|
+
console.print(f"[red]Error listing environments: {str(e)}[/red]")
|
|
126
|
+
raise click.Abort()
|
|
127
|
+
|
|
128
|
+
|
|
129
|
+
@environments_group.command(name="delete")
|
|
130
|
+
@click.argument("env_id")
|
|
131
|
+
@click.pass_context
|
|
132
|
+
def delete(ctx, env_id):
|
|
133
|
+
"""Delete an environment"""
|
|
134
|
+
|
|
135
|
+
async def _run():
|
|
136
|
+
config, token, _, _ = get_client_config(
|
|
137
|
+
ctx.obj["PROFILE"], api_url=ctx.obj.get("API_URL")
|
|
138
|
+
)
|
|
139
|
+
client = TestZeusClient(**config)
|
|
140
|
+
async with client:
|
|
141
|
+
if token:
|
|
142
|
+
initialize_client_with_token(client, token)
|
|
143
|
+
else:
|
|
144
|
+
await client.ensure_authenticated()
|
|
145
|
+
await client.environments.delete(env_id)
|
|
146
|
+
return {"id": env_id}
|
|
147
|
+
|
|
148
|
+
try:
|
|
149
|
+
result = asyncio.run(_run())
|
|
150
|
+
console.print(f"[green]Environment {result['id']} deleted successfully[/green]")
|
|
151
|
+
except Exception as e:
|
|
152
|
+
console.print(f"[red]Error deleting environment: {str(e)}[/red]")
|
|
153
|
+
raise click.Abort()
|
|
154
|
+
|
|
155
|
+
@environments_group.command(name="get")
|
|
156
|
+
@click.argument("env_id")
|
|
157
|
+
@click.option("--expand", help="Expand related entities")
|
|
158
|
+
@click.pass_context
|
|
159
|
+
def get(ctx, env_id, expand):
|
|
160
|
+
"""Get an environment by ID"""
|
|
161
|
+
|
|
162
|
+
async def _run():
|
|
163
|
+
config, token, _, _ = get_client_config(
|
|
164
|
+
ctx.obj["PROFILE"], api_url=ctx.obj.get("API_URL")
|
|
165
|
+
)
|
|
166
|
+
client = TestZeusClient(**config)
|
|
167
|
+
async with client:
|
|
168
|
+
if token:
|
|
169
|
+
initialize_client_with_token(client, token)
|
|
170
|
+
else:
|
|
171
|
+
await client.ensure_authenticated()
|
|
172
|
+
env = await client.environments.get_one(env_id, expand=expand)
|
|
173
|
+
return env.data
|
|
174
|
+
|
|
175
|
+
try:
|
|
176
|
+
result = asyncio.run(_run())
|
|
177
|
+
format_output(result, ctx.obj["FORMAT"])
|
|
178
|
+
except Exception as e:
|
|
179
|
+
console.print(f"[red]Error getting environment: {str(e)}[/red]")
|
|
180
|
+
raise click.Abort()
|
|
181
|
+
|
|
182
|
+
|
|
183
|
+
@environments_group.command(name="update")
|
|
184
|
+
@click.argument("env_id")
|
|
185
|
+
@click.option("--name", help="New environment name")
|
|
186
|
+
@click.option("--status", help="New environment status (draft, ready, deleted)")
|
|
187
|
+
@click.option("--data", help="New environment data as text")
|
|
188
|
+
@click.option("--data-file", "-df", type=click.Path(exists=True), help="Path to text file with new environment data")
|
|
189
|
+
@click.option("--tags", help="Comma-separated list of tags")
|
|
190
|
+
@click.pass_context
|
|
191
|
+
def update(ctx, env_id, name, status, data, data_file, tags):
|
|
192
|
+
"""Update an environment"""
|
|
193
|
+
|
|
194
|
+
if data and data_file:
|
|
195
|
+
raise click.UsageError("Cannot use both --data and --data-file")
|
|
196
|
+
|
|
197
|
+
# Process the data content (from file or directly)
|
|
198
|
+
data_content = None
|
|
199
|
+
if data_file:
|
|
200
|
+
data_content = _read_data_file(data_file)
|
|
201
|
+
elif data:
|
|
202
|
+
data_content = data
|
|
203
|
+
|
|
204
|
+
|
|
205
|
+
async def _run():
|
|
206
|
+
config, token, tenant_id, user_id = get_client_config(
|
|
207
|
+
ctx.obj["PROFILE"], api_url=ctx.obj.get("API_URL")
|
|
208
|
+
)
|
|
209
|
+
client = TestZeusClient(**config)
|
|
210
|
+
async with client:
|
|
211
|
+
if token:
|
|
212
|
+
initialize_client_with_token(client, token)
|
|
213
|
+
else:
|
|
214
|
+
await client.ensure_authenticated()
|
|
215
|
+
updates = {"tenant": tenant_id, "modified_by": user_id}
|
|
216
|
+
has_updates = False
|
|
217
|
+
|
|
218
|
+
if name:
|
|
219
|
+
updates["name"] = name
|
|
220
|
+
has_updates = True
|
|
221
|
+
|
|
222
|
+
if status:
|
|
223
|
+
updates["status"] = status
|
|
224
|
+
has_updates = True
|
|
225
|
+
|
|
226
|
+
if data_content:
|
|
227
|
+
updates["data"] = data_content
|
|
228
|
+
has_updates = True
|
|
229
|
+
|
|
230
|
+
if tags and tags != "none":
|
|
231
|
+
updates["tags"] = tags.split(",")
|
|
232
|
+
has_updates = True
|
|
233
|
+
|
|
234
|
+
if tags == "none":
|
|
235
|
+
updates["tags"] = None
|
|
236
|
+
has_updates = True
|
|
237
|
+
|
|
238
|
+
if has_updates:
|
|
239
|
+
updated_env = await client.environments.update(env_id, updates)
|
|
240
|
+
return updated_env.data
|
|
241
|
+
else:
|
|
242
|
+
console.print("[yellow]No updates provided[/yellow]")
|
|
243
|
+
return None
|
|
244
|
+
|
|
245
|
+
try:
|
|
246
|
+
result = asyncio.run(_run())
|
|
247
|
+
console.print(f"[green]Environment updated successfully[/green]")
|
|
248
|
+
format_output(result, ctx.obj["FORMAT"])
|
|
249
|
+
except Exception as e:
|
|
250
|
+
console.print(f"[red]Error updating environment: {str(e)}[/red]")
|
|
251
|
+
raise click.Abort()
|
|
@@ -0,0 +1,190 @@
|
|
|
1
|
+
"""
|
|
2
|
+
Tag management commands for TestZeus CLI.
|
|
3
|
+
"""
|
|
4
|
+
|
|
5
|
+
import asyncio
|
|
6
|
+
import click
|
|
7
|
+
import json
|
|
8
|
+
from rich.console import Console
|
|
9
|
+
from testzeus_sdk import TestZeusClient
|
|
10
|
+
from testzeus_cli.config import get_client_config
|
|
11
|
+
from testzeus_cli.utils.formatters import format_output
|
|
12
|
+
from testzeus_cli.utils.auth import initialize_client_with_token
|
|
13
|
+
from testzeus_cli.utils.validators import parse_key_value_pairs, validate_id
|
|
14
|
+
|
|
15
|
+
console = Console()
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
@click.group()
|
|
19
|
+
def tags_group():
|
|
20
|
+
"""Manage tags in TestZeus"""
|
|
21
|
+
pass
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
@tags_group.command()
|
|
25
|
+
@click.option("--name", required=True, help="Tag name")
|
|
26
|
+
@click.option("--value", required=False, default=None, help="Tag value")
|
|
27
|
+
@click.pass_context
|
|
28
|
+
def create(ctx, name, value):
|
|
29
|
+
"""Create a new tag"""
|
|
30
|
+
|
|
31
|
+
async def _run():
|
|
32
|
+
config, token, stored_tenant_id, stored_user_id = get_client_config(
|
|
33
|
+
ctx.obj["PROFILE"], api_url=ctx.obj.get("API_URL")
|
|
34
|
+
)
|
|
35
|
+
client = TestZeusClient(**config)
|
|
36
|
+
async with client:
|
|
37
|
+
if token:
|
|
38
|
+
initialize_client_with_token(client, token)
|
|
39
|
+
else:
|
|
40
|
+
await client.ensure_authenticated()
|
|
41
|
+
params = {"name": name, "value": value, "tenant": stored_tenant_id, "modified_by": stored_user_id}
|
|
42
|
+
tag = await client.tags.create(params)
|
|
43
|
+
return tag.data
|
|
44
|
+
|
|
45
|
+
try:
|
|
46
|
+
result = asyncio.run(_run())
|
|
47
|
+
console.print(f"[green]Tag '{result['name']}' created successfully[/green]")
|
|
48
|
+
format_output(result, ctx.obj["FORMAT"])
|
|
49
|
+
except Exception as e:
|
|
50
|
+
console.print(f"[red]Error creating tag: {str(e)}[/red]")
|
|
51
|
+
raise click.Abort()
|
|
52
|
+
|
|
53
|
+
|
|
54
|
+
@tags_group.command(name="list")
|
|
55
|
+
@click.option(
|
|
56
|
+
"--filters", "-f", multiple=True, help="Filter results (format: key=value)"
|
|
57
|
+
)
|
|
58
|
+
@click.option("--sort", help="Sort by field")
|
|
59
|
+
@click.option("--expand", help="Expand related entities")
|
|
60
|
+
@click.pass_context
|
|
61
|
+
def list(ctx, filters, sort, expand):
|
|
62
|
+
"""List all tags"""
|
|
63
|
+
|
|
64
|
+
async def _run():
|
|
65
|
+
config, token, _, _ = get_client_config(
|
|
66
|
+
ctx.obj["PROFILE"], api_url=ctx.obj.get("API_URL")
|
|
67
|
+
)
|
|
68
|
+
client = TestZeusClient(**config)
|
|
69
|
+
# Parse filters
|
|
70
|
+
filter_dict = parse_key_value_pairs(filters) if filters else {}
|
|
71
|
+
|
|
72
|
+
async with client:
|
|
73
|
+
if token:
|
|
74
|
+
initialize_client_with_token(client, token)
|
|
75
|
+
else:
|
|
76
|
+
await client.ensure_authenticated()
|
|
77
|
+
result = await client.tags.get_list(
|
|
78
|
+
expand=expand, sort=sort, filters=filter_dict
|
|
79
|
+
)
|
|
80
|
+
|
|
81
|
+
return result
|
|
82
|
+
|
|
83
|
+
try:
|
|
84
|
+
result = asyncio.run(_run())
|
|
85
|
+
format_output(result, ctx.obj["FORMAT"])
|
|
86
|
+
except Exception as e:
|
|
87
|
+
console.print(f"[red]Error listing tags: {str(e)}[/red]")
|
|
88
|
+
raise click.Abort()
|
|
89
|
+
|
|
90
|
+
|
|
91
|
+
@tags_group.command(name="get")
|
|
92
|
+
@click.argument("tag_id")
|
|
93
|
+
@click.option("--expand", help="Expand related entities")
|
|
94
|
+
@click.pass_context
|
|
95
|
+
def get_tags(ctx, tag_id, expand):
|
|
96
|
+
"""Get a tag by id"""
|
|
97
|
+
|
|
98
|
+
async def _run():
|
|
99
|
+
config, token, _, _ = get_client_config(
|
|
100
|
+
ctx.obj["PROFILE"], api_url=ctx.obj.get("API_URL")
|
|
101
|
+
)
|
|
102
|
+
client = TestZeusClient(**config)
|
|
103
|
+
|
|
104
|
+
tag_id_validated = validate_id(tag_id, "tag")
|
|
105
|
+
async with client:
|
|
106
|
+
if token:
|
|
107
|
+
initialize_client_with_token(client, token)
|
|
108
|
+
else:
|
|
109
|
+
await client.ensure_authenticated()
|
|
110
|
+
tag = await client.tags.get_one(tag_id_validated, expand=expand)
|
|
111
|
+
return tag.data
|
|
112
|
+
|
|
113
|
+
try:
|
|
114
|
+
result = asyncio.run(_run())
|
|
115
|
+
format_output(result, ctx.obj["FORMAT"])
|
|
116
|
+
except Exception as e:
|
|
117
|
+
console.print(f"[red]Error getting tag: {str(e)}[/red]")
|
|
118
|
+
raise click.Abort()
|
|
119
|
+
|
|
120
|
+
@tags_group.command(name="update")
|
|
121
|
+
@click.argument("tags_id")
|
|
122
|
+
@click.option("--name", help="New tag name")
|
|
123
|
+
@click.option("--value", help="New tag value")
|
|
124
|
+
@click.pass_context
|
|
125
|
+
def update_tags(ctx, tags_id, name, value):
|
|
126
|
+
"""Update a tag"""
|
|
127
|
+
|
|
128
|
+
async def _run():
|
|
129
|
+
config, token, tenanat_id, user_id = get_client_config(
|
|
130
|
+
ctx.obj["PROFILE"], api_url=ctx.obj.get("API_URL")
|
|
131
|
+
)
|
|
132
|
+
client = TestZeusClient(**config)
|
|
133
|
+
tag_id_validated = validate_id(tags_id, "tag")
|
|
134
|
+
async with client:
|
|
135
|
+
if token:
|
|
136
|
+
initialize_client_with_token(client, token)
|
|
137
|
+
else:
|
|
138
|
+
await client.ensure_authenticated()
|
|
139
|
+
updates = {"tenant": tenanat_id, "modified_by": user_id}
|
|
140
|
+
has_updates = False
|
|
141
|
+
|
|
142
|
+
if name:
|
|
143
|
+
updates["name"] = name
|
|
144
|
+
has_updates = True
|
|
145
|
+
|
|
146
|
+
if value:
|
|
147
|
+
updates["value"] = value
|
|
148
|
+
has_updates = True
|
|
149
|
+
|
|
150
|
+
if has_updates:
|
|
151
|
+
update_tags = await client.tags.update(tag_id_validated, updates)
|
|
152
|
+
return update_tags.data
|
|
153
|
+
else:
|
|
154
|
+
console.print("[yellow]No updates provided[/yellow]")
|
|
155
|
+
return None
|
|
156
|
+
try:
|
|
157
|
+
result = asyncio.run(_run())
|
|
158
|
+
console.print(f"[green]Tag '{result['name']}' updated successfully[/green]")
|
|
159
|
+
format_output(result, ctx.obj["FORMAT"])
|
|
160
|
+
except Exception as e:
|
|
161
|
+
console.print(f"[red]Error updating tag: {str(e)}[/red]")
|
|
162
|
+
raise click.Abort()
|
|
163
|
+
|
|
164
|
+
|
|
165
|
+
@tags_group.command(name="delete")
|
|
166
|
+
@click.argument("name")
|
|
167
|
+
@click.confirmation_option(prompt="Are you sure you want to delete this tag?")
|
|
168
|
+
@click.pass_context
|
|
169
|
+
def delete(ctx, name):
|
|
170
|
+
"""Delete a tag"""
|
|
171
|
+
|
|
172
|
+
async def _run():
|
|
173
|
+
config, token, _, _ = get_client_config(
|
|
174
|
+
ctx.obj["PROFILE"], api_url=ctx.obj.get("API_URL")
|
|
175
|
+
)
|
|
176
|
+
client = TestZeusClient(**config)
|
|
177
|
+
async with client:
|
|
178
|
+
if token:
|
|
179
|
+
initialize_client_with_token(client, token)
|
|
180
|
+
else:
|
|
181
|
+
await client.ensure_authenticated()
|
|
182
|
+
await client.tags.delete(name)
|
|
183
|
+
return {"name": name}
|
|
184
|
+
|
|
185
|
+
try:
|
|
186
|
+
result = asyncio.run(_run())
|
|
187
|
+
console.print(f"[green]Tag '{result['name']}' deleted successfully[/green]")
|
|
188
|
+
except Exception as e:
|
|
189
|
+
console.print(f"[red]Error deleting tag: {str(e)}[/red]")
|
|
190
|
+
raise click.Abort()
|