dremio-cli 1.0.0__py3-none-any.whl
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.
- dremio_cli/__init__.py +5 -0
- dremio_cli/__main__.py +6 -0
- dremio_cli/cli.py +191 -0
- dremio_cli/client/__init__.py +1 -0
- dremio_cli/client/auth.py +100 -0
- dremio_cli/client/base.py +190 -0
- dremio_cli/client/cloud.py +305 -0
- dremio_cli/client/factory.py +122 -0
- dremio_cli/client/software.py +561 -0
- dremio_cli/commands/__init__.py +1 -0
- dremio_cli/commands/catalog.py +143 -0
- dremio_cli/commands/favorite.py +162 -0
- dremio_cli/commands/folder.py +290 -0
- dremio_cli/commands/grant.py +202 -0
- dremio_cli/commands/history.py +122 -0
- dremio_cli/commands/job.py +321 -0
- dremio_cli/commands/lineage.py +9 -0
- dremio_cli/commands/profile.py +165 -0
- dremio_cli/commands/role.py +319 -0
- dremio_cli/commands/source.py +375 -0
- dremio_cli/commands/space.py +226 -0
- dremio_cli/commands/sql.py +280 -0
- dremio_cli/commands/table.py +155 -0
- dremio_cli/commands/tag.py +145 -0
- dremio_cli/commands/udf.py +9 -0
- dremio_cli/commands/user.py +250 -0
- dremio_cli/commands/view.py +369 -0
- dremio_cli/commands/wiki.py +163 -0
- dremio_cli/config.py +193 -0
- dremio_cli/env.py +175 -0
- dremio_cli/formatters/__init__.py +1 -0
- dremio_cli/formatters/json.py +19 -0
- dremio_cli/formatters/table.py +45 -0
- dremio_cli/formatters/yaml.py +17 -0
- dremio_cli/history.py +198 -0
- dremio_cli/utils/__init__.py +1 -0
- dremio_cli/utils/exceptions.py +35 -0
- dremio_cli/utils/helpers.py +73 -0
- dremio_cli/utils/validators.py +147 -0
- dremio_cli-1.0.0.dist-info/METADATA +261 -0
- dremio_cli-1.0.0.dist-info/RECORD +45 -0
- dremio_cli-1.0.0.dist-info/WHEEL +5 -0
- dremio_cli-1.0.0.dist-info/entry_points.txt +2 -0
- dremio_cli-1.0.0.dist-info/licenses/LICENSE +21 -0
- dremio_cli-1.0.0.dist-info/top_level.txt +1 -0
|
@@ -0,0 +1,122 @@
|
|
|
1
|
+
"""History management commands."""
|
|
2
|
+
|
|
3
|
+
import click
|
|
4
|
+
from rich.console import Console
|
|
5
|
+
from rich.table import Table
|
|
6
|
+
|
|
7
|
+
from dremio_cli.history import HistoryManager
|
|
8
|
+
from dremio_cli.formatters.json import format_as_json
|
|
9
|
+
from dremio_cli.formatters.yaml import format_as_yaml
|
|
10
|
+
|
|
11
|
+
console = Console()
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
@click.group()
|
|
15
|
+
def history() -> None:
|
|
16
|
+
"""Query history management."""
|
|
17
|
+
pass
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
@history.command("list")
|
|
21
|
+
@click.option("--limit", default=50, help="Maximum number of entries")
|
|
22
|
+
@click.pass_context
|
|
23
|
+
def list_history(ctx, limit: int) -> None:
|
|
24
|
+
"""List recent query history.
|
|
25
|
+
|
|
26
|
+
Examples:
|
|
27
|
+
dremio history list
|
|
28
|
+
dremio history list --limit 10
|
|
29
|
+
"""
|
|
30
|
+
try:
|
|
31
|
+
manager = HistoryManager()
|
|
32
|
+
entries = manager.get_history(limit=limit)
|
|
33
|
+
|
|
34
|
+
output_format = ctx.obj.output_format
|
|
35
|
+
|
|
36
|
+
if output_format == "json":
|
|
37
|
+
console.print(format_as_json(entries))
|
|
38
|
+
elif output_format == "yaml":
|
|
39
|
+
console.print(format_as_yaml(entries))
|
|
40
|
+
else:
|
|
41
|
+
if entries:
|
|
42
|
+
table = Table(title=f"Query History (last {len(entries)})")
|
|
43
|
+
table.add_column("ID", style="cyan")
|
|
44
|
+
table.add_column("Command", style="green")
|
|
45
|
+
table.add_column("Query", style="yellow", max_width=50)
|
|
46
|
+
table.add_column("Profile", style="magenta")
|
|
47
|
+
table.add_column("Time", style="blue")
|
|
48
|
+
|
|
49
|
+
for entry in entries:
|
|
50
|
+
table.add_row(
|
|
51
|
+
str(entry["id"]),
|
|
52
|
+
entry["command"],
|
|
53
|
+
entry["query"][:47] + "..." if entry["query"] and len(entry["query"]) > 50 else (entry["query"] or ""),
|
|
54
|
+
entry["profile"] or "",
|
|
55
|
+
entry["timestamp"][:19]
|
|
56
|
+
)
|
|
57
|
+
|
|
58
|
+
console.print(table)
|
|
59
|
+
else:
|
|
60
|
+
console.print("[yellow]No history found[/yellow]")
|
|
61
|
+
|
|
62
|
+
except Exception as e:
|
|
63
|
+
console.print(f"[red]Error: {e}[/red]")
|
|
64
|
+
if ctx.obj.verbose:
|
|
65
|
+
import traceback
|
|
66
|
+
traceback.print_exc()
|
|
67
|
+
raise click.Abort()
|
|
68
|
+
|
|
69
|
+
|
|
70
|
+
@history.command("run")
|
|
71
|
+
@click.argument("history_id", type=int)
|
|
72
|
+
@click.pass_context
|
|
73
|
+
def run_history(ctx, history_id: int) -> None:
|
|
74
|
+
"""Re-run a command from history.
|
|
75
|
+
|
|
76
|
+
Examples:
|
|
77
|
+
dremio history run 5
|
|
78
|
+
"""
|
|
79
|
+
try:
|
|
80
|
+
manager = HistoryManager()
|
|
81
|
+
entry = manager.get_history_item(history_id)
|
|
82
|
+
|
|
83
|
+
if not entry:
|
|
84
|
+
console.print(f"[red]History entry {history_id} not found[/red]")
|
|
85
|
+
raise click.Abort()
|
|
86
|
+
|
|
87
|
+
console.print(f"[cyan]Re-running:[/cyan] {entry['command']}")
|
|
88
|
+
if entry['query']:
|
|
89
|
+
console.print(f"[yellow]Query:[/yellow] {entry['query']}")
|
|
90
|
+
|
|
91
|
+
# Re-execute the command
|
|
92
|
+
# Note: This is a simplified version - full implementation would parse and execute
|
|
93
|
+
console.print("[yellow]Note: Re-execution not yet implemented - use the command shown above[/yellow]")
|
|
94
|
+
|
|
95
|
+
except Exception as e:
|
|
96
|
+
console.print(f"[red]Error: {e}[/red]")
|
|
97
|
+
if ctx.obj.verbose:
|
|
98
|
+
import traceback
|
|
99
|
+
traceback.print_exc()
|
|
100
|
+
raise click.Abort()
|
|
101
|
+
|
|
102
|
+
|
|
103
|
+
@history.command("clear")
|
|
104
|
+
@click.confirmation_option(prompt="Are you sure you want to clear all history?")
|
|
105
|
+
@click.pass_context
|
|
106
|
+
def clear_history(ctx) -> None:
|
|
107
|
+
"""Clear all query history.
|
|
108
|
+
|
|
109
|
+
Examples:
|
|
110
|
+
dremio history clear
|
|
111
|
+
"""
|
|
112
|
+
try:
|
|
113
|
+
manager = HistoryManager()
|
|
114
|
+
manager.clear_history()
|
|
115
|
+
console.print("[green]✓[/green] History cleared")
|
|
116
|
+
|
|
117
|
+
except Exception as e:
|
|
118
|
+
console.print(f"[red]Error: {e}[/red]")
|
|
119
|
+
if ctx.obj.verbose:
|
|
120
|
+
import traceback
|
|
121
|
+
traceback.print_exc()
|
|
122
|
+
raise click.Abort()
|
|
@@ -0,0 +1,321 @@
|
|
|
1
|
+
"""Job management commands."""
|
|
2
|
+
|
|
3
|
+
import click
|
|
4
|
+
from rich.console import Console
|
|
5
|
+
from pathlib import Path
|
|
6
|
+
|
|
7
|
+
from dremio_cli.config import ProfileManager
|
|
8
|
+
from dremio_cli.client.factory import create_client
|
|
9
|
+
from dremio_cli.formatters.table import format_as_table
|
|
10
|
+
from dremio_cli.formatters.json import format_as_json
|
|
11
|
+
from dremio_cli.formatters.yaml import format_as_yaml
|
|
12
|
+
|
|
13
|
+
console = Console()
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
@click.group()
|
|
17
|
+
def job() -> None:
|
|
18
|
+
"""Job management operations."""
|
|
19
|
+
pass
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
@job.command("list")
|
|
23
|
+
@click.option("--max-results", type=int, help="Maximum number of results to return")
|
|
24
|
+
@click.option("--filter", "filter_expr", help="Filter expression (e.g., 'state=COMPLETED')")
|
|
25
|
+
@click.option("--sort", help="Sort field (prefix with - for descending, e.g., '-submittedAt')")
|
|
26
|
+
@click.pass_context
|
|
27
|
+
def list_jobs(ctx, max_results: int, filter_expr: str, sort: str) -> None:
|
|
28
|
+
"""List jobs.
|
|
29
|
+
|
|
30
|
+
Examples:
|
|
31
|
+
dremio job list
|
|
32
|
+
dremio job list --max-results 50
|
|
33
|
+
dremio job list --filter "state=COMPLETED"
|
|
34
|
+
dremio job list --sort "-submittedAt"
|
|
35
|
+
"""
|
|
36
|
+
try:
|
|
37
|
+
# Get profile
|
|
38
|
+
manager = ProfileManager()
|
|
39
|
+
profile_name = ctx.obj.profile_name
|
|
40
|
+
profile = manager.get_profile(profile_name)
|
|
41
|
+
|
|
42
|
+
if not profile:
|
|
43
|
+
console.print(f"[red]Profile '{profile_name}' not found[/red]")
|
|
44
|
+
raise click.Abort()
|
|
45
|
+
|
|
46
|
+
# Create client
|
|
47
|
+
client = create_client(profile)
|
|
48
|
+
|
|
49
|
+
# List jobs
|
|
50
|
+
if hasattr(client, 'list_jobs'):
|
|
51
|
+
with console.status(f"[bold green]Fetching jobs from {profile_name}..."):
|
|
52
|
+
data = client.list_jobs(
|
|
53
|
+
max_results=max_results,
|
|
54
|
+
filter_expr=filter_expr,
|
|
55
|
+
sort=sort
|
|
56
|
+
)
|
|
57
|
+
else:
|
|
58
|
+
console.print("[red]Job listing not supported for this profile type[/red]")
|
|
59
|
+
raise click.Abort()
|
|
60
|
+
|
|
61
|
+
# Format output
|
|
62
|
+
output_format = ctx.obj.output_format
|
|
63
|
+
|
|
64
|
+
if output_format == "json":
|
|
65
|
+
console.print(format_as_json(data))
|
|
66
|
+
elif output_format == "yaml":
|
|
67
|
+
console.print(format_as_yaml(data))
|
|
68
|
+
else:
|
|
69
|
+
# Display as table
|
|
70
|
+
jobs = data.get("jobs", [])
|
|
71
|
+
if jobs:
|
|
72
|
+
format_as_table(jobs, title=f"Jobs ({profile_name})")
|
|
73
|
+
else:
|
|
74
|
+
console.print("[yellow]No jobs found[/yellow]")
|
|
75
|
+
|
|
76
|
+
except Exception as e:
|
|
77
|
+
console.print(f"[red]Error: {e}[/red]")
|
|
78
|
+
if ctx.obj.verbose:
|
|
79
|
+
import traceback
|
|
80
|
+
traceback.print_exc()
|
|
81
|
+
raise click.Abort()
|
|
82
|
+
|
|
83
|
+
|
|
84
|
+
@job.command("get")
|
|
85
|
+
@click.argument("job_id")
|
|
86
|
+
@click.pass_context
|
|
87
|
+
def get_job(ctx, job_id: str) -> None:
|
|
88
|
+
"""Get job details by ID.
|
|
89
|
+
|
|
90
|
+
Examples:
|
|
91
|
+
dremio job get 2c8a1234-5678-90ab-cdef-1234567890ab
|
|
92
|
+
"""
|
|
93
|
+
try:
|
|
94
|
+
# Get profile
|
|
95
|
+
manager = ProfileManager()
|
|
96
|
+
profile_name = ctx.obj.profile_name
|
|
97
|
+
profile = manager.get_profile(profile_name)
|
|
98
|
+
|
|
99
|
+
if not profile:
|
|
100
|
+
console.print(f"[red]Profile '{profile_name}' not found[/red]")
|
|
101
|
+
raise click.Abort()
|
|
102
|
+
|
|
103
|
+
# Create client
|
|
104
|
+
client = create_client(profile)
|
|
105
|
+
|
|
106
|
+
# Get job
|
|
107
|
+
with console.status(f"[bold green]Fetching job {job_id}..."):
|
|
108
|
+
data = client.get_job(job_id)
|
|
109
|
+
|
|
110
|
+
# Format output
|
|
111
|
+
output_format = ctx.obj.output_format
|
|
112
|
+
|
|
113
|
+
if output_format == "json":
|
|
114
|
+
console.print(format_as_json(data))
|
|
115
|
+
elif output_format == "yaml":
|
|
116
|
+
console.print(format_as_yaml(data))
|
|
117
|
+
else:
|
|
118
|
+
format_as_table(data, title=f"Job: {job_id}")
|
|
119
|
+
|
|
120
|
+
except Exception as e:
|
|
121
|
+
console.print(f"[red]Error: {e}[/red]")
|
|
122
|
+
if ctx.obj.verbose:
|
|
123
|
+
import traceback
|
|
124
|
+
traceback.print_exc()
|
|
125
|
+
raise click.Abort()
|
|
126
|
+
|
|
127
|
+
|
|
128
|
+
@job.command("results")
|
|
129
|
+
@click.argument("job_id")
|
|
130
|
+
@click.option("--limit", type=int, help="Maximum number of rows to return")
|
|
131
|
+
@click.option("--offset", type=int, help="Offset for pagination")
|
|
132
|
+
@click.pass_context
|
|
133
|
+
def get_job_results(ctx, job_id: str, limit: int, offset: int) -> None:
|
|
134
|
+
"""Get job results.
|
|
135
|
+
|
|
136
|
+
Examples:
|
|
137
|
+
dremio job results 2c8a1234-5678-90ab-cdef-1234567890ab
|
|
138
|
+
dremio job results 2c8a1234-5678-90ab-cdef-1234567890ab --limit 100
|
|
139
|
+
dremio job results 2c8a1234-5678-90ab-cdef-1234567890ab --limit 100 --offset 100
|
|
140
|
+
"""
|
|
141
|
+
try:
|
|
142
|
+
# Get profile
|
|
143
|
+
manager = ProfileManager()
|
|
144
|
+
profile_name = ctx.obj.profile_name
|
|
145
|
+
profile = manager.get_profile(profile_name)
|
|
146
|
+
|
|
147
|
+
if not profile:
|
|
148
|
+
console.print(f"[red]Profile '{profile_name}' not found[/red]")
|
|
149
|
+
raise click.Abort()
|
|
150
|
+
|
|
151
|
+
# Create client
|
|
152
|
+
client = create_client(profile)
|
|
153
|
+
|
|
154
|
+
# Get job results
|
|
155
|
+
with console.status(f"[bold green]Fetching results for job {job_id}..."):
|
|
156
|
+
data = client.get_job_results(job_id, limit=limit, offset=offset)
|
|
157
|
+
|
|
158
|
+
# Format output
|
|
159
|
+
output_format = ctx.obj.output_format
|
|
160
|
+
|
|
161
|
+
if output_format == "json":
|
|
162
|
+
console.print(format_as_json(data))
|
|
163
|
+
elif output_format == "yaml":
|
|
164
|
+
console.print(format_as_yaml(data))
|
|
165
|
+
else:
|
|
166
|
+
# Display rows as table
|
|
167
|
+
rows = data.get("rows", [])
|
|
168
|
+
if rows:
|
|
169
|
+
format_as_table(rows, title=f"Job Results: {job_id}")
|
|
170
|
+
|
|
171
|
+
# Show pagination info
|
|
172
|
+
row_count = data.get("rowCount", len(rows))
|
|
173
|
+
console.print(f"\n[dim]Showing {len(rows)} of {row_count} rows[/dim]")
|
|
174
|
+
else:
|
|
175
|
+
console.print("[yellow]No results found[/yellow]")
|
|
176
|
+
|
|
177
|
+
except Exception as e:
|
|
178
|
+
console.print(f"[red]Error: {e}[/red]")
|
|
179
|
+
if ctx.obj.verbose:
|
|
180
|
+
import traceback
|
|
181
|
+
traceback.print_exc()
|
|
182
|
+
raise click.Abort()
|
|
183
|
+
|
|
184
|
+
|
|
185
|
+
@job.command("cancel")
|
|
186
|
+
@click.argument("job_id")
|
|
187
|
+
@click.confirmation_option(prompt="Are you sure you want to cancel this job?")
|
|
188
|
+
@click.pass_context
|
|
189
|
+
def cancel_job(ctx, job_id: str) -> None:
|
|
190
|
+
"""Cancel a running job.
|
|
191
|
+
|
|
192
|
+
Examples:
|
|
193
|
+
dremio job cancel 2c8a1234-5678-90ab-cdef-1234567890ab
|
|
194
|
+
"""
|
|
195
|
+
try:
|
|
196
|
+
# Get profile
|
|
197
|
+
manager = ProfileManager()
|
|
198
|
+
profile_name = ctx.obj.profile_name
|
|
199
|
+
profile = manager.get_profile(profile_name)
|
|
200
|
+
|
|
201
|
+
if not profile:
|
|
202
|
+
console.print(f"[red]Profile '{profile_name}' not found[/red]")
|
|
203
|
+
raise click.Abort()
|
|
204
|
+
|
|
205
|
+
# Create client
|
|
206
|
+
client = create_client(profile)
|
|
207
|
+
|
|
208
|
+
# Cancel job
|
|
209
|
+
with console.status(f"[bold yellow]Canceling job {job_id}..."):
|
|
210
|
+
client.cancel_job(job_id)
|
|
211
|
+
|
|
212
|
+
console.print(f"[green]✓[/green] Job {job_id} canceled successfully")
|
|
213
|
+
|
|
214
|
+
except Exception as e:
|
|
215
|
+
console.print(f"[red]Error: {e}[/red]")
|
|
216
|
+
if ctx.obj.verbose:
|
|
217
|
+
import traceback
|
|
218
|
+
traceback.print_exc()
|
|
219
|
+
raise click.Abort()
|
|
220
|
+
|
|
221
|
+
|
|
222
|
+
@job.command("profile")
|
|
223
|
+
@click.argument("job_id")
|
|
224
|
+
@click.option("--download", type=click.Path(), help="Download profile to file")
|
|
225
|
+
@click.pass_context
|
|
226
|
+
def get_job_profile(ctx, job_id: str, download: str) -> None:
|
|
227
|
+
"""Get job profile for performance analysis.
|
|
228
|
+
|
|
229
|
+
Examples:
|
|
230
|
+
dremio job profile 2c8a1234-5678-90ab-cdef-1234567890ab
|
|
231
|
+
dremio job profile 2c8a1234-5678-90ab-cdef-1234567890ab --download profile.zip
|
|
232
|
+
"""
|
|
233
|
+
try:
|
|
234
|
+
# Get profile
|
|
235
|
+
manager = ProfileManager()
|
|
236
|
+
profile_name = ctx.obj.profile_name
|
|
237
|
+
profile = manager.get_profile(profile_name)
|
|
238
|
+
|
|
239
|
+
if not profile:
|
|
240
|
+
console.print(f"[red]Profile '{profile_name}' not found[/red]")
|
|
241
|
+
raise click.Abort()
|
|
242
|
+
|
|
243
|
+
# Create client
|
|
244
|
+
client = create_client(profile)
|
|
245
|
+
|
|
246
|
+
# Get job profile
|
|
247
|
+
if hasattr(client, 'get_job_profile'):
|
|
248
|
+
with console.status(f"[bold green]Fetching profile for job {job_id}..."):
|
|
249
|
+
data = client.get_job_profile(job_id)
|
|
250
|
+
|
|
251
|
+
if download:
|
|
252
|
+
# Save to file
|
|
253
|
+
Path(download).write_bytes(data if isinstance(data, bytes) else data.encode())
|
|
254
|
+
console.print(f"[green]✓[/green] Profile saved to {download}")
|
|
255
|
+
else:
|
|
256
|
+
# Display profile info
|
|
257
|
+
output_format = ctx.obj.output_format
|
|
258
|
+
if output_format == "json":
|
|
259
|
+
console.print(format_as_json(data))
|
|
260
|
+
elif output_format == "yaml":
|
|
261
|
+
console.print(format_as_yaml(data))
|
|
262
|
+
else:
|
|
263
|
+
console.print(data)
|
|
264
|
+
else:
|
|
265
|
+
console.print("[red]Job profile not supported for this profile type[/red]")
|
|
266
|
+
raise click.Abort()
|
|
267
|
+
|
|
268
|
+
except Exception as e:
|
|
269
|
+
console.print(f"[red]Error: {e}[/red]")
|
|
270
|
+
if ctx.obj.verbose:
|
|
271
|
+
import traceback
|
|
272
|
+
traceback.print_exc()
|
|
273
|
+
raise click.Abort()
|
|
274
|
+
|
|
275
|
+
|
|
276
|
+
@job.command("reflections")
|
|
277
|
+
@click.argument("job_id")
|
|
278
|
+
@click.pass_context
|
|
279
|
+
def get_job_reflections(ctx, job_id: str) -> None:
|
|
280
|
+
"""Get reflection information for a job.
|
|
281
|
+
|
|
282
|
+
Examples:
|
|
283
|
+
dremio job reflections 2c8a1234-5678-90ab-cdef-1234567890ab
|
|
284
|
+
"""
|
|
285
|
+
try:
|
|
286
|
+
# Get profile
|
|
287
|
+
manager = ProfileManager()
|
|
288
|
+
profile_name = ctx.obj.profile_name
|
|
289
|
+
profile = manager.get_profile(profile_name)
|
|
290
|
+
|
|
291
|
+
if not profile:
|
|
292
|
+
console.print(f"[red]Profile '{profile_name}' not found[/red]")
|
|
293
|
+
raise click.Abort()
|
|
294
|
+
|
|
295
|
+
# Create client
|
|
296
|
+
client = create_client(profile)
|
|
297
|
+
|
|
298
|
+
# Get job reflections
|
|
299
|
+
if hasattr(client, 'get_job_reflections'):
|
|
300
|
+
with console.status(f"[bold green]Fetching reflections for job {job_id}..."):
|
|
301
|
+
data = client.get_job_reflections(job_id)
|
|
302
|
+
|
|
303
|
+
# Format output
|
|
304
|
+
output_format = ctx.obj.output_format
|
|
305
|
+
|
|
306
|
+
if output_format == "json":
|
|
307
|
+
console.print(format_as_json(data))
|
|
308
|
+
elif output_format == "yaml":
|
|
309
|
+
console.print(format_as_yaml(data))
|
|
310
|
+
else:
|
|
311
|
+
format_as_table(data, title=f"Job Reflections: {job_id}")
|
|
312
|
+
else:
|
|
313
|
+
console.print("[red]Job reflections not supported for this profile type[/red]")
|
|
314
|
+
raise click.Abort()
|
|
315
|
+
|
|
316
|
+
except Exception as e:
|
|
317
|
+
console.print(f"[red]Error: {e}[/red]")
|
|
318
|
+
if ctx.obj.verbose:
|
|
319
|
+
import traceback
|
|
320
|
+
traceback.print_exc()
|
|
321
|
+
raise click.Abort()
|
|
@@ -0,0 +1,165 @@
|
|
|
1
|
+
"""Profile management commands."""
|
|
2
|
+
|
|
3
|
+
import click
|
|
4
|
+
from rich.console import Console
|
|
5
|
+
from rich.table import Table
|
|
6
|
+
|
|
7
|
+
from dremio_cli.config import ProfileManager
|
|
8
|
+
from dremio_cli.utils.exceptions import DremioCliError
|
|
9
|
+
from dremio_cli.utils.validators import validate_profile_type, validate_auth_type, validate_url
|
|
10
|
+
|
|
11
|
+
console = Console()
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
@click.group()
|
|
15
|
+
def profile() -> None:
|
|
16
|
+
"""Manage Dremio CLI profiles."""
|
|
17
|
+
pass
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
@profile.command("list")
|
|
21
|
+
def list_profiles() -> None:
|
|
22
|
+
"""List all profiles."""
|
|
23
|
+
try:
|
|
24
|
+
manager = ProfileManager()
|
|
25
|
+
profiles = manager.list_profiles()
|
|
26
|
+
default = manager.get_default_profile()
|
|
27
|
+
|
|
28
|
+
if not profiles:
|
|
29
|
+
console.print("[yellow]No profiles configured.[/yellow]")
|
|
30
|
+
console.print("\nCreate a profile with: [cyan]dremio profile create <name>[/cyan]")
|
|
31
|
+
return
|
|
32
|
+
|
|
33
|
+
table = Table(title="Dremio Profiles")
|
|
34
|
+
table.add_column("Name", style="cyan")
|
|
35
|
+
table.add_column("Type", style="green")
|
|
36
|
+
table.add_column("Base URL", style="blue")
|
|
37
|
+
table.add_column("Auth Type", style="magenta")
|
|
38
|
+
table.add_column("Default", style="yellow")
|
|
39
|
+
|
|
40
|
+
for name, profile in profiles.items():
|
|
41
|
+
is_default = "✓" if name == default else ""
|
|
42
|
+
table.add_row(
|
|
43
|
+
name,
|
|
44
|
+
profile.get("type", "N/A"),
|
|
45
|
+
profile.get("base_url", "N/A"),
|
|
46
|
+
profile.get("auth", {}).get("type", "N/A"),
|
|
47
|
+
is_default,
|
|
48
|
+
)
|
|
49
|
+
|
|
50
|
+
console.print(table)
|
|
51
|
+
|
|
52
|
+
except Exception as e:
|
|
53
|
+
console.print(f"[red]Error: {e}[/red]")
|
|
54
|
+
raise click.Abort()
|
|
55
|
+
|
|
56
|
+
|
|
57
|
+
@profile.command("current")
|
|
58
|
+
def current_profile() -> None:
|
|
59
|
+
"""Show current default profile."""
|
|
60
|
+
try:
|
|
61
|
+
manager = ProfileManager()
|
|
62
|
+
default = manager.get_default_profile()
|
|
63
|
+
|
|
64
|
+
if not default:
|
|
65
|
+
console.print("[yellow]No default profile set.[/yellow]")
|
|
66
|
+
return
|
|
67
|
+
|
|
68
|
+
profile_data = manager.get_profile(default)
|
|
69
|
+
|
|
70
|
+
console.print(f"\n[bold]Current Profile:[/bold] [cyan]{default}[/cyan]\n")
|
|
71
|
+
console.print(f" Type: {profile_data.get('type')}")
|
|
72
|
+
console.print(f" Base URL: {profile_data.get('base_url')}")
|
|
73
|
+
console.print(f" Auth Type: {profile_data.get('auth', {}).get('type')}")
|
|
74
|
+
|
|
75
|
+
if "project_id" in profile_data:
|
|
76
|
+
console.print(f" Project ID: {profile_data['project_id']}")
|
|
77
|
+
|
|
78
|
+
except Exception as e:
|
|
79
|
+
console.print(f"[red]Error: {e}[/red]")
|
|
80
|
+
raise click.Abort()
|
|
81
|
+
|
|
82
|
+
|
|
83
|
+
@profile.command("create")
|
|
84
|
+
@click.argument("name")
|
|
85
|
+
@click.option("--type", "profile_type", required=True, type=click.Choice(["cloud", "software"]))
|
|
86
|
+
@click.option("--base-url", required=True, help="Base URL for Dremio API")
|
|
87
|
+
@click.option("--project-id", help="Project ID (required for cloud)")
|
|
88
|
+
@click.option("--auth-type", required=True, type=click.Choice(["pat", "oauth", "username_password"]))
|
|
89
|
+
@click.option("--token", help="Authentication token")
|
|
90
|
+
@click.option("--username", help="Username (for username_password auth)")
|
|
91
|
+
@click.option("--password", help="Password (for username_password auth)")
|
|
92
|
+
def create_profile(
|
|
93
|
+
name: str,
|
|
94
|
+
profile_type: str,
|
|
95
|
+
base_url: str,
|
|
96
|
+
project_id: str,
|
|
97
|
+
auth_type: str,
|
|
98
|
+
token: str,
|
|
99
|
+
username: str,
|
|
100
|
+
password: str,
|
|
101
|
+
) -> None:
|
|
102
|
+
"""Create a new profile."""
|
|
103
|
+
try:
|
|
104
|
+
# Validate inputs
|
|
105
|
+
validate_profile_type(profile_type)
|
|
106
|
+
validate_auth_type(auth_type)
|
|
107
|
+
validate_url(base_url)
|
|
108
|
+
|
|
109
|
+
# Validate cloud-specific requirements
|
|
110
|
+
if profile_type == "cloud" and not project_id:
|
|
111
|
+
raise DremioCliError("--project-id is required for cloud profiles")
|
|
112
|
+
|
|
113
|
+
# Validate auth requirements
|
|
114
|
+
if auth_type == "pat" and not token:
|
|
115
|
+
raise DremioCliError("--token is required for PAT authentication")
|
|
116
|
+
|
|
117
|
+
if auth_type == "username_password" and (not username or not password):
|
|
118
|
+
raise DremioCliError("--username and --password are required for username_password authentication")
|
|
119
|
+
|
|
120
|
+
manager = ProfileManager()
|
|
121
|
+
manager.create_profile(
|
|
122
|
+
name=name,
|
|
123
|
+
profile_type=profile_type,
|
|
124
|
+
base_url=base_url,
|
|
125
|
+
auth_type=auth_type,
|
|
126
|
+
project_id=project_id,
|
|
127
|
+
token=token,
|
|
128
|
+
username=username,
|
|
129
|
+
password=password,
|
|
130
|
+
)
|
|
131
|
+
|
|
132
|
+
console.print(f"[green]✓[/green] Profile '[cyan]{name}[/cyan]' created successfully")
|
|
133
|
+
|
|
134
|
+
except Exception as e:
|
|
135
|
+
console.print(f"[red]Error: {e}[/red]")
|
|
136
|
+
raise click.Abort()
|
|
137
|
+
|
|
138
|
+
|
|
139
|
+
@profile.command("delete")
|
|
140
|
+
@click.argument("name")
|
|
141
|
+
@click.confirmation_option(prompt="Are you sure you want to delete this profile?")
|
|
142
|
+
def delete_profile(name: str) -> None:
|
|
143
|
+
"""Delete a profile."""
|
|
144
|
+
try:
|
|
145
|
+
manager = ProfileManager()
|
|
146
|
+
manager.delete_profile(name)
|
|
147
|
+
console.print(f"[green]✓[/green] Profile '[cyan]{name}[/cyan]' deleted")
|
|
148
|
+
|
|
149
|
+
except Exception as e:
|
|
150
|
+
console.print(f"[red]Error: {e}[/red]")
|
|
151
|
+
raise click.Abort()
|
|
152
|
+
|
|
153
|
+
|
|
154
|
+
@profile.command("set-default")
|
|
155
|
+
@click.argument("name")
|
|
156
|
+
def set_default(name: str) -> None:
|
|
157
|
+
"""Set the default profile."""
|
|
158
|
+
try:
|
|
159
|
+
manager = ProfileManager()
|
|
160
|
+
manager.set_default_profile(name)
|
|
161
|
+
console.print(f"[green]✓[/green] Default profile set to '[cyan]{name}[/cyan]'")
|
|
162
|
+
|
|
163
|
+
except Exception as e:
|
|
164
|
+
console.print(f"[red]Error: {e}[/red]")
|
|
165
|
+
raise click.Abort()
|