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,319 @@
|
|
|
1
|
+
"""Role management commands."""
|
|
2
|
+
|
|
3
|
+
import json
|
|
4
|
+
import click
|
|
5
|
+
from rich.console import Console
|
|
6
|
+
from pathlib import Path
|
|
7
|
+
|
|
8
|
+
from dremio_cli.config import ProfileManager
|
|
9
|
+
from dremio_cli.client.factory import create_client
|
|
10
|
+
from dremio_cli.formatters.table import format_as_table
|
|
11
|
+
from dremio_cli.formatters.json import format_as_json
|
|
12
|
+
from dremio_cli.formatters.yaml import format_as_yaml
|
|
13
|
+
|
|
14
|
+
console = Console()
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
@click.group()
|
|
18
|
+
def role() -> None:
|
|
19
|
+
"""Role management operations."""
|
|
20
|
+
pass
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
@role.command("list")
|
|
24
|
+
@click.pass_context
|
|
25
|
+
def list_roles(ctx) -> None:
|
|
26
|
+
"""List all roles.
|
|
27
|
+
|
|
28
|
+
Examples:
|
|
29
|
+
dremio role list
|
|
30
|
+
"""
|
|
31
|
+
try:
|
|
32
|
+
# Get profile
|
|
33
|
+
manager = ProfileManager()
|
|
34
|
+
profile_name = ctx.obj.profile_name
|
|
35
|
+
profile = manager.get_profile(profile_name)
|
|
36
|
+
|
|
37
|
+
if not profile:
|
|
38
|
+
console.print(f"[red]Profile '{profile_name}' not found[/red]")
|
|
39
|
+
raise click.Abort()
|
|
40
|
+
|
|
41
|
+
# Create client
|
|
42
|
+
client = create_client(profile)
|
|
43
|
+
|
|
44
|
+
# List roles
|
|
45
|
+
with console.status(f"[bold green]Fetching roles..."):
|
|
46
|
+
data = client.list_roles()
|
|
47
|
+
|
|
48
|
+
roles = data.get("roles", data.get("data", []))
|
|
49
|
+
|
|
50
|
+
# Format output
|
|
51
|
+
output_format = ctx.obj.output_format
|
|
52
|
+
|
|
53
|
+
if output_format == "json":
|
|
54
|
+
console.print(format_as_json(roles))
|
|
55
|
+
elif output_format == "yaml":
|
|
56
|
+
console.print(format_as_yaml(roles))
|
|
57
|
+
else:
|
|
58
|
+
if roles:
|
|
59
|
+
format_as_table(roles, title=f"Roles ({profile_name})")
|
|
60
|
+
else:
|
|
61
|
+
console.print("[yellow]No roles found[/yellow]")
|
|
62
|
+
|
|
63
|
+
except Exception as e:
|
|
64
|
+
console.print(f"[red]Error: {e}[/red]")
|
|
65
|
+
if ctx.obj.verbose:
|
|
66
|
+
import traceback
|
|
67
|
+
traceback.print_exc()
|
|
68
|
+
raise click.Abort()
|
|
69
|
+
|
|
70
|
+
|
|
71
|
+
@role.command("get")
|
|
72
|
+
@click.argument("role_id")
|
|
73
|
+
@click.pass_context
|
|
74
|
+
def get_role(ctx, role_id: str) -> None:
|
|
75
|
+
"""Get role by ID.
|
|
76
|
+
|
|
77
|
+
Examples:
|
|
78
|
+
dremio role get role-123-456
|
|
79
|
+
"""
|
|
80
|
+
try:
|
|
81
|
+
# Get profile
|
|
82
|
+
manager = ProfileManager()
|
|
83
|
+
profile_name = ctx.obj.profile_name
|
|
84
|
+
profile = manager.get_profile(profile_name)
|
|
85
|
+
|
|
86
|
+
if not profile:
|
|
87
|
+
console.print(f"[red]Profile '{profile_name}' not found[/red]")
|
|
88
|
+
raise click.Abort()
|
|
89
|
+
|
|
90
|
+
# Create client
|
|
91
|
+
client = create_client(profile)
|
|
92
|
+
|
|
93
|
+
# Get role
|
|
94
|
+
with console.status(f"[bold green]Fetching role {role_id}..."):
|
|
95
|
+
data = client.get_role(role_id)
|
|
96
|
+
|
|
97
|
+
# Format output
|
|
98
|
+
output_format = ctx.obj.output_format
|
|
99
|
+
|
|
100
|
+
if output_format == "json":
|
|
101
|
+
console.print(format_as_json(data))
|
|
102
|
+
elif output_format == "yaml":
|
|
103
|
+
console.print(format_as_yaml(data))
|
|
104
|
+
else:
|
|
105
|
+
format_as_table(data, title=f"Role: {role_id}")
|
|
106
|
+
|
|
107
|
+
except Exception as e:
|
|
108
|
+
console.print(f"[red]Error: {e}[/red]")
|
|
109
|
+
if ctx.obj.verbose:
|
|
110
|
+
import traceback
|
|
111
|
+
traceback.print_exc()
|
|
112
|
+
raise click.Abort()
|
|
113
|
+
|
|
114
|
+
|
|
115
|
+
@role.command("create")
|
|
116
|
+
@click.option("--name", required=True, help="Role name")
|
|
117
|
+
@click.option("--from-file", "role_file", type=click.Path(exists=True), help="Load role from JSON file")
|
|
118
|
+
@click.pass_context
|
|
119
|
+
def create_role(ctx, name: str, role_file: str) -> None:
|
|
120
|
+
"""Create a new role.
|
|
121
|
+
|
|
122
|
+
Examples:
|
|
123
|
+
dremio role create --name "Analyst"
|
|
124
|
+
dremio role create --from-file role.json
|
|
125
|
+
"""
|
|
126
|
+
try:
|
|
127
|
+
# Get profile
|
|
128
|
+
manager = ProfileManager()
|
|
129
|
+
profile_name = ctx.obj.profile_name
|
|
130
|
+
profile = manager.get_profile(profile_name)
|
|
131
|
+
|
|
132
|
+
if not profile:
|
|
133
|
+
console.print(f"[red]Profile '{profile_name}' not found[/red]")
|
|
134
|
+
raise click.Abort()
|
|
135
|
+
|
|
136
|
+
# Create client
|
|
137
|
+
client = create_client(profile)
|
|
138
|
+
|
|
139
|
+
# Build role data
|
|
140
|
+
if role_file:
|
|
141
|
+
with open(role_file, 'r') as f:
|
|
142
|
+
role_data = json.load(f)
|
|
143
|
+
else:
|
|
144
|
+
role_data = {
|
|
145
|
+
"name": name
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
# Create role
|
|
149
|
+
with console.status(f"[bold green]Creating role..."):
|
|
150
|
+
result = client.create_role(role_data)
|
|
151
|
+
|
|
152
|
+
role_id = result.get("id")
|
|
153
|
+
|
|
154
|
+
console.print(f"[green]✓[/green] Role created successfully")
|
|
155
|
+
console.print(f" ID: {role_id}")
|
|
156
|
+
console.print(f" Name: {result.get('name', name)}")
|
|
157
|
+
|
|
158
|
+
except Exception as e:
|
|
159
|
+
console.print(f"[red]Error: {e}[/red]")
|
|
160
|
+
if ctx.obj.verbose:
|
|
161
|
+
import traceback
|
|
162
|
+
traceback.print_exc()
|
|
163
|
+
raise click.Abort()
|
|
164
|
+
|
|
165
|
+
|
|
166
|
+
@role.command("update")
|
|
167
|
+
@click.argument("role_id")
|
|
168
|
+
@click.option("--from-file", "role_file", type=click.Path(exists=True), required=True, help="Updated role JSON file")
|
|
169
|
+
@click.pass_context
|
|
170
|
+
def update_role(ctx, role_id: str, role_file: str) -> None:
|
|
171
|
+
"""Update an existing role.
|
|
172
|
+
|
|
173
|
+
Examples:
|
|
174
|
+
dremio role update role-123 --from-file updated_role.json
|
|
175
|
+
"""
|
|
176
|
+
try:
|
|
177
|
+
# Get profile
|
|
178
|
+
manager = ProfileManager()
|
|
179
|
+
profile_name = ctx.obj.profile_name
|
|
180
|
+
profile = manager.get_profile(profile_name)
|
|
181
|
+
|
|
182
|
+
if not profile:
|
|
183
|
+
console.print(f"[red]Profile '{profile_name}' not found[/red]")
|
|
184
|
+
raise click.Abort()
|
|
185
|
+
|
|
186
|
+
# Create client
|
|
187
|
+
client = create_client(profile)
|
|
188
|
+
|
|
189
|
+
# Load role data
|
|
190
|
+
with open(role_file, 'r') as f:
|
|
191
|
+
role_data = json.load(f)
|
|
192
|
+
|
|
193
|
+
# Update role
|
|
194
|
+
with console.status(f"[bold green]Updating role {role_id}..."):
|
|
195
|
+
result = client.update_role(role_id, role_data)
|
|
196
|
+
|
|
197
|
+
console.print(f"[green]✓[/green] Role updated successfully")
|
|
198
|
+
console.print(f" ID: {role_id}")
|
|
199
|
+
|
|
200
|
+
except Exception as e:
|
|
201
|
+
console.print(f"[red]Error: {e}[/red]")
|
|
202
|
+
if ctx.obj.verbose:
|
|
203
|
+
import traceback
|
|
204
|
+
traceback.print_exc()
|
|
205
|
+
raise click.Abort()
|
|
206
|
+
|
|
207
|
+
|
|
208
|
+
@role.command("delete")
|
|
209
|
+
@click.argument("role_id")
|
|
210
|
+
@click.confirmation_option(prompt="Are you sure you want to delete this role?")
|
|
211
|
+
@click.pass_context
|
|
212
|
+
def delete_role(ctx, role_id: str) -> None:
|
|
213
|
+
"""Delete a role.
|
|
214
|
+
|
|
215
|
+
Examples:
|
|
216
|
+
dremio role delete role-123-456
|
|
217
|
+
"""
|
|
218
|
+
try:
|
|
219
|
+
# Get profile
|
|
220
|
+
manager = ProfileManager()
|
|
221
|
+
profile_name = ctx.obj.profile_name
|
|
222
|
+
profile = manager.get_profile(profile_name)
|
|
223
|
+
|
|
224
|
+
if not profile:
|
|
225
|
+
console.print(f"[red]Profile '{profile_name}' not found[/red]")
|
|
226
|
+
raise click.Abort()
|
|
227
|
+
|
|
228
|
+
# Create client
|
|
229
|
+
client = create_client(profile)
|
|
230
|
+
|
|
231
|
+
# Delete role
|
|
232
|
+
with console.status(f"[bold yellow]Deleting role {role_id}..."):
|
|
233
|
+
client.delete_role(role_id)
|
|
234
|
+
|
|
235
|
+
console.print(f"[green]✓[/green] Role deleted successfully")
|
|
236
|
+
|
|
237
|
+
except Exception as e:
|
|
238
|
+
console.print(f"[red]Error: {e}[/red]")
|
|
239
|
+
if ctx.obj.verbose:
|
|
240
|
+
import traceback
|
|
241
|
+
traceback.print_exc()
|
|
242
|
+
raise click.Abort()
|
|
243
|
+
|
|
244
|
+
|
|
245
|
+
@role.command("add-member")
|
|
246
|
+
@click.argument("role_id")
|
|
247
|
+
@click.option("--user", "user_id", required=True, help="User ID to add")
|
|
248
|
+
@click.pass_context
|
|
249
|
+
def add_member(ctx, role_id: str, user_id: str) -> None:
|
|
250
|
+
"""Add a user to a role.
|
|
251
|
+
|
|
252
|
+
Examples:
|
|
253
|
+
dremio role add-member role-123 --user user-456
|
|
254
|
+
"""
|
|
255
|
+
try:
|
|
256
|
+
# Get profile
|
|
257
|
+
manager = ProfileManager()
|
|
258
|
+
profile_name = ctx.obj.profile_name
|
|
259
|
+
profile = manager.get_profile(profile_name)
|
|
260
|
+
|
|
261
|
+
if not profile:
|
|
262
|
+
console.print(f"[red]Profile '{profile_name}' not found[/red]")
|
|
263
|
+
raise click.Abort()
|
|
264
|
+
|
|
265
|
+
# Create client
|
|
266
|
+
client = create_client(profile)
|
|
267
|
+
|
|
268
|
+
# Add member
|
|
269
|
+
with console.status(f"[bold green]Adding user to role..."):
|
|
270
|
+
client.add_role_member(role_id, user_id)
|
|
271
|
+
|
|
272
|
+
console.print(f"[green]✓[/green] User added to role successfully")
|
|
273
|
+
console.print(f" Role: {role_id}")
|
|
274
|
+
console.print(f" User: {user_id}")
|
|
275
|
+
|
|
276
|
+
except Exception as e:
|
|
277
|
+
console.print(f"[red]Error: {e}[/red]")
|
|
278
|
+
if ctx.obj.verbose:
|
|
279
|
+
import traceback
|
|
280
|
+
traceback.print_exc()
|
|
281
|
+
raise click.Abort()
|
|
282
|
+
|
|
283
|
+
|
|
284
|
+
@role.command("remove-member")
|
|
285
|
+
@click.argument("role_id")
|
|
286
|
+
@click.option("--user", "user_id", required=True, help="User ID to remove")
|
|
287
|
+
@click.confirmation_option(prompt="Are you sure you want to remove this user from the role?")
|
|
288
|
+
@click.pass_context
|
|
289
|
+
def remove_member(ctx, role_id: str, user_id: str) -> None:
|
|
290
|
+
"""Remove a user from a role.
|
|
291
|
+
|
|
292
|
+
Examples:
|
|
293
|
+
dremio role remove-member role-123 --user user-456
|
|
294
|
+
"""
|
|
295
|
+
try:
|
|
296
|
+
# Get profile
|
|
297
|
+
manager = ProfileManager()
|
|
298
|
+
profile_name = ctx.obj.profile_name
|
|
299
|
+
profile = manager.get_profile(profile_name)
|
|
300
|
+
|
|
301
|
+
if not profile:
|
|
302
|
+
console.print(f"[red]Profile '{profile_name}' not found[/red]")
|
|
303
|
+
raise click.Abort()
|
|
304
|
+
|
|
305
|
+
# Create client
|
|
306
|
+
client = create_client(profile)
|
|
307
|
+
|
|
308
|
+
# Remove member
|
|
309
|
+
with console.status(f"[bold yellow]Removing user from role..."):
|
|
310
|
+
client.remove_role_member(role_id, user_id)
|
|
311
|
+
|
|
312
|
+
console.print(f"[green]✓[/green] User removed from role successfully")
|
|
313
|
+
|
|
314
|
+
except Exception as e:
|
|
315
|
+
console.print(f"[red]Error: {e}[/red]")
|
|
316
|
+
if ctx.obj.verbose:
|
|
317
|
+
import traceback
|
|
318
|
+
traceback.print_exc()
|
|
319
|
+
raise click.Abort()
|
|
@@ -0,0 +1,375 @@
|
|
|
1
|
+
"""Source management commands."""
|
|
2
|
+
|
|
3
|
+
import json
|
|
4
|
+
import click
|
|
5
|
+
from rich.console import Console
|
|
6
|
+
from pathlib import Path
|
|
7
|
+
|
|
8
|
+
from dremio_cli.config import ProfileManager
|
|
9
|
+
from dremio_cli.client.factory import create_client
|
|
10
|
+
from dremio_cli.formatters.table import format_as_table
|
|
11
|
+
from dremio_cli.formatters.json import format_as_json
|
|
12
|
+
from dremio_cli.formatters.yaml import format_as_yaml
|
|
13
|
+
|
|
14
|
+
console = Console()
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
@click.group()
|
|
18
|
+
def source() -> None:
|
|
19
|
+
"""Source management operations."""
|
|
20
|
+
pass
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
@source.command("list")
|
|
24
|
+
@click.pass_context
|
|
25
|
+
def list_sources(ctx) -> None:
|
|
26
|
+
"""List all sources.
|
|
27
|
+
|
|
28
|
+
Examples:
|
|
29
|
+
dremio source list
|
|
30
|
+
"""
|
|
31
|
+
try:
|
|
32
|
+
# Get profile
|
|
33
|
+
manager = ProfileManager()
|
|
34
|
+
profile_name = ctx.obj.profile_name
|
|
35
|
+
profile = manager.get_profile(profile_name)
|
|
36
|
+
|
|
37
|
+
if not profile:
|
|
38
|
+
console.print(f"[red]Profile '{profile_name}' not found[/red]")
|
|
39
|
+
raise click.Abort()
|
|
40
|
+
|
|
41
|
+
# Create client
|
|
42
|
+
client = create_client(profile)
|
|
43
|
+
|
|
44
|
+
# Get catalog
|
|
45
|
+
with console.status(f"[bold green]Fetching sources..."):
|
|
46
|
+
data = client.get_catalog()
|
|
47
|
+
|
|
48
|
+
items = data.get("data", [])
|
|
49
|
+
|
|
50
|
+
# Filter for sources
|
|
51
|
+
sources = [
|
|
52
|
+
item for item in items
|
|
53
|
+
if item.get("containerType") == "SOURCE"
|
|
54
|
+
]
|
|
55
|
+
|
|
56
|
+
# Format output
|
|
57
|
+
output_format = ctx.obj.output_format
|
|
58
|
+
|
|
59
|
+
if output_format == "json":
|
|
60
|
+
console.print(format_as_json(sources))
|
|
61
|
+
elif output_format == "yaml":
|
|
62
|
+
console.print(format_as_yaml(sources))
|
|
63
|
+
else:
|
|
64
|
+
if sources:
|
|
65
|
+
format_as_table(sources, title=f"Sources ({profile_name})")
|
|
66
|
+
else:
|
|
67
|
+
console.print("[yellow]No sources found[/yellow]")
|
|
68
|
+
|
|
69
|
+
except Exception as e:
|
|
70
|
+
console.print(f"[red]Error: {e}[/red]")
|
|
71
|
+
if ctx.obj.verbose:
|
|
72
|
+
import traceback
|
|
73
|
+
traceback.print_exc()
|
|
74
|
+
raise click.Abort()
|
|
75
|
+
|
|
76
|
+
|
|
77
|
+
@source.command("get")
|
|
78
|
+
@click.argument("source_id")
|
|
79
|
+
@click.pass_context
|
|
80
|
+
def get_source(ctx, source_id: str) -> None:
|
|
81
|
+
"""Get source by ID.
|
|
82
|
+
|
|
83
|
+
Examples:
|
|
84
|
+
dremio source get abc-123-def-456
|
|
85
|
+
"""
|
|
86
|
+
try:
|
|
87
|
+
# Get profile
|
|
88
|
+
manager = ProfileManager()
|
|
89
|
+
profile_name = ctx.obj.profile_name
|
|
90
|
+
profile = manager.get_profile(profile_name)
|
|
91
|
+
|
|
92
|
+
if not profile:
|
|
93
|
+
console.print(f"[red]Profile '{profile_name}' not found[/red]")
|
|
94
|
+
raise click.Abort()
|
|
95
|
+
|
|
96
|
+
# Create client
|
|
97
|
+
client = create_client(profile)
|
|
98
|
+
|
|
99
|
+
# Get source
|
|
100
|
+
with console.status(f"[bold green]Fetching source {source_id}..."):
|
|
101
|
+
data = client.get_catalog_item(source_id)
|
|
102
|
+
|
|
103
|
+
# Format output
|
|
104
|
+
output_format = ctx.obj.output_format
|
|
105
|
+
|
|
106
|
+
if output_format == "json":
|
|
107
|
+
console.print(format_as_json(data))
|
|
108
|
+
elif output_format == "yaml":
|
|
109
|
+
console.print(format_as_yaml(data))
|
|
110
|
+
else:
|
|
111
|
+
format_as_table(data, title=f"Source: {source_id}")
|
|
112
|
+
|
|
113
|
+
except Exception as e:
|
|
114
|
+
console.print(f"[red]Error: {e}[/red]")
|
|
115
|
+
if ctx.obj.verbose:
|
|
116
|
+
import traceback
|
|
117
|
+
traceback.print_exc()
|
|
118
|
+
raise click.Abort()
|
|
119
|
+
|
|
120
|
+
|
|
121
|
+
@source.command("create")
|
|
122
|
+
@click.option("--name", required=True, help="Source name")
|
|
123
|
+
@click.option("--type", "source_type", required=True, help="Source type (e.g., POSTGRES, S3, MONGO)")
|
|
124
|
+
@click.option("--config-file", type=click.Path(exists=True), required=True, help="Source configuration JSON file")
|
|
125
|
+
@click.pass_context
|
|
126
|
+
def create_source(ctx, name: str, source_type: str, config_file: str) -> None:
|
|
127
|
+
"""Create a new source.
|
|
128
|
+
|
|
129
|
+
Examples:
|
|
130
|
+
dremio source create --name MyPostgres --type POSTGRES --config-file postgres.json
|
|
131
|
+
dremio source create --name MyS3 --type S3 --config-file s3.json
|
|
132
|
+
"""
|
|
133
|
+
try:
|
|
134
|
+
# Get profile
|
|
135
|
+
manager = ProfileManager()
|
|
136
|
+
profile_name = ctx.obj.profile_name
|
|
137
|
+
profile = manager.get_profile(profile_name)
|
|
138
|
+
|
|
139
|
+
if not profile:
|
|
140
|
+
console.print(f"[red]Profile '{profile_name}' not found[/red]")
|
|
141
|
+
raise click.Abort()
|
|
142
|
+
|
|
143
|
+
# Load config
|
|
144
|
+
with open(config_file, 'r') as f:
|
|
145
|
+
config = json.load(f)
|
|
146
|
+
|
|
147
|
+
# Create client
|
|
148
|
+
client = create_client(profile)
|
|
149
|
+
|
|
150
|
+
# Create source data
|
|
151
|
+
source_data = {
|
|
152
|
+
"entityType": "source",
|
|
153
|
+
"name": name,
|
|
154
|
+
"type": source_type,
|
|
155
|
+
"config": config
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
with console.status(f"[bold green]Creating source '{name}'..."):
|
|
159
|
+
result = client.create_source(source_data)
|
|
160
|
+
|
|
161
|
+
source_id = result.get("id")
|
|
162
|
+
|
|
163
|
+
console.print(f"[green]✓[/green] Source created successfully")
|
|
164
|
+
console.print(f" ID: {source_id}")
|
|
165
|
+
console.print(f" Name: {name}")
|
|
166
|
+
console.print(f" Type: {source_type}")
|
|
167
|
+
|
|
168
|
+
# Display full result if verbose
|
|
169
|
+
if ctx.obj.verbose:
|
|
170
|
+
output_format = ctx.obj.output_format
|
|
171
|
+
if output_format == "json":
|
|
172
|
+
console.print(format_as_json(result))
|
|
173
|
+
elif output_format == "yaml":
|
|
174
|
+
console.print(format_as_yaml(result))
|
|
175
|
+
|
|
176
|
+
except Exception as e:
|
|
177
|
+
console.print(f"[red]Error: {e}[/red]")
|
|
178
|
+
if ctx.obj.verbose:
|
|
179
|
+
import traceback
|
|
180
|
+
traceback.print_exc()
|
|
181
|
+
raise click.Abort()
|
|
182
|
+
|
|
183
|
+
|
|
184
|
+
@source.command("update")
|
|
185
|
+
@click.argument("source_id")
|
|
186
|
+
@click.option("--config-file", type=click.Path(exists=True), required=True, help="Updated source configuration JSON file")
|
|
187
|
+
@click.pass_context
|
|
188
|
+
def update_source(ctx, source_id: str, config_file: str) -> None:
|
|
189
|
+
"""Update an existing source.
|
|
190
|
+
|
|
191
|
+
Examples:
|
|
192
|
+
dremio source update abc-123 --config-file updated_config.json
|
|
193
|
+
"""
|
|
194
|
+
try:
|
|
195
|
+
# Get profile
|
|
196
|
+
manager = ProfileManager()
|
|
197
|
+
profile_name = ctx.obj.profile_name
|
|
198
|
+
profile = manager.get_profile(profile_name)
|
|
199
|
+
|
|
200
|
+
if not profile:
|
|
201
|
+
console.print(f"[red]Profile '{profile_name}' not found[/red]")
|
|
202
|
+
raise click.Abort()
|
|
203
|
+
|
|
204
|
+
# Create client
|
|
205
|
+
client = create_client(profile)
|
|
206
|
+
|
|
207
|
+
# Get current source for tag
|
|
208
|
+
current_source = client.get_catalog_item(source_id)
|
|
209
|
+
|
|
210
|
+
# Load new config
|
|
211
|
+
with open(config_file, 'r') as f:
|
|
212
|
+
new_config = json.load(f)
|
|
213
|
+
|
|
214
|
+
# Update source data
|
|
215
|
+
source_data = {
|
|
216
|
+
"entityType": "source",
|
|
217
|
+
"id": source_id,
|
|
218
|
+
"name": current_source.get("name"),
|
|
219
|
+
"type": current_source.get("type"),
|
|
220
|
+
"tag": current_source.get("tag"),
|
|
221
|
+
"config": new_config
|
|
222
|
+
}
|
|
223
|
+
|
|
224
|
+
with console.status(f"[bold green]Updating source {source_id}..."):
|
|
225
|
+
result = client.update_source(source_id, source_data)
|
|
226
|
+
|
|
227
|
+
console.print(f"[green]✓[/green] Source updated successfully")
|
|
228
|
+
console.print(f" ID: {source_id}")
|
|
229
|
+
|
|
230
|
+
# Display full result if verbose
|
|
231
|
+
if ctx.obj.verbose:
|
|
232
|
+
output_format = ctx.obj.output_format
|
|
233
|
+
if output_format == "json":
|
|
234
|
+
console.print(format_as_json(result))
|
|
235
|
+
elif output_format == "yaml":
|
|
236
|
+
console.print(format_as_yaml(result))
|
|
237
|
+
|
|
238
|
+
except Exception as e:
|
|
239
|
+
console.print(f"[red]Error: {e}[/red]")
|
|
240
|
+
if ctx.obj.verbose:
|
|
241
|
+
import traceback
|
|
242
|
+
traceback.print_exc()
|
|
243
|
+
raise click.Abort()
|
|
244
|
+
|
|
245
|
+
|
|
246
|
+
@source.command("refresh")
|
|
247
|
+
@click.argument("source_id")
|
|
248
|
+
@click.pass_context
|
|
249
|
+
def refresh_source(ctx, source_id: str) -> None:
|
|
250
|
+
"""Refresh source metadata.
|
|
251
|
+
|
|
252
|
+
Examples:
|
|
253
|
+
dremio source refresh abc-123-def-456
|
|
254
|
+
"""
|
|
255
|
+
try:
|
|
256
|
+
# Get profile
|
|
257
|
+
manager = ProfileManager()
|
|
258
|
+
profile_name = ctx.obj.profile_name
|
|
259
|
+
profile = manager.get_profile(profile_name)
|
|
260
|
+
|
|
261
|
+
if not profile:
|
|
262
|
+
console.print(f"[red]Profile '{profile_name}' not found[/red]")
|
|
263
|
+
raise click.Abort()
|
|
264
|
+
|
|
265
|
+
# Create client
|
|
266
|
+
client = create_client(profile)
|
|
267
|
+
|
|
268
|
+
# Refresh source
|
|
269
|
+
with console.status(f"[bold green]Refreshing source {source_id}..."):
|
|
270
|
+
result = client.refresh_source(source_id)
|
|
271
|
+
|
|
272
|
+
console.print(f"[green]✓[/green] Source refresh initiated")
|
|
273
|
+
console.print(f" Source ID: {source_id}")
|
|
274
|
+
|
|
275
|
+
if result:
|
|
276
|
+
job_id = result.get("id")
|
|
277
|
+
if job_id:
|
|
278
|
+
console.print(f" Job ID: {job_id}")
|
|
279
|
+
|
|
280
|
+
except Exception as e:
|
|
281
|
+
console.print(f"[red]Error: {e}[/red]")
|
|
282
|
+
if ctx.obj.verbose:
|
|
283
|
+
import traceback
|
|
284
|
+
traceback.print_exc()
|
|
285
|
+
raise click.Abort()
|
|
286
|
+
|
|
287
|
+
|
|
288
|
+
@source.command("delete")
|
|
289
|
+
@click.argument("source_id")
|
|
290
|
+
@click.option("--tag", help="Version tag for optimistic concurrency control")
|
|
291
|
+
@click.confirmation_option(prompt="Are you sure you want to delete this source?")
|
|
292
|
+
@click.pass_context
|
|
293
|
+
def delete_source(ctx, source_id: str, tag: str) -> None:
|
|
294
|
+
"""Delete a source.
|
|
295
|
+
|
|
296
|
+
Examples:
|
|
297
|
+
dremio source delete abc-123-def-456
|
|
298
|
+
"""
|
|
299
|
+
try:
|
|
300
|
+
# Get profile
|
|
301
|
+
manager = ProfileManager()
|
|
302
|
+
profile_name = ctx.obj.profile_name
|
|
303
|
+
profile = manager.get_profile(profile_name)
|
|
304
|
+
|
|
305
|
+
if not profile:
|
|
306
|
+
console.print(f"[red]Profile '{profile_name}' not found[/red]")
|
|
307
|
+
raise click.Abort()
|
|
308
|
+
|
|
309
|
+
# Create client
|
|
310
|
+
client = create_client(profile)
|
|
311
|
+
|
|
312
|
+
# Get tag if not provided
|
|
313
|
+
if not tag:
|
|
314
|
+
source = client.get_catalog_item(source_id)
|
|
315
|
+
tag = source.get("tag")
|
|
316
|
+
|
|
317
|
+
# Delete source
|
|
318
|
+
with console.status(f"[bold yellow]Deleting source {source_id}..."):
|
|
319
|
+
client.delete_source(source_id, tag)
|
|
320
|
+
|
|
321
|
+
console.print(f"[green]✓[/green] Source deleted successfully")
|
|
322
|
+
|
|
323
|
+
except Exception as e:
|
|
324
|
+
console.print(f"[red]Error: {e}[/red]")
|
|
325
|
+
if ctx.obj.verbose:
|
|
326
|
+
import traceback
|
|
327
|
+
traceback.print_exc()
|
|
328
|
+
raise click.Abort()
|
|
329
|
+
|
|
330
|
+
|
|
331
|
+
@source.command("test-connection")
|
|
332
|
+
@click.option("--config-file", type=click.Path(exists=True), required=True, help="Source configuration JSON file to test")
|
|
333
|
+
@click.pass_context
|
|
334
|
+
def test_connection(ctx, config_file: str) -> None:
|
|
335
|
+
"""Test source connection configuration.
|
|
336
|
+
|
|
337
|
+
Examples:
|
|
338
|
+
dremio source test-connection --config-file postgres.json
|
|
339
|
+
"""
|
|
340
|
+
try:
|
|
341
|
+
# Get profile
|
|
342
|
+
manager = ProfileManager()
|
|
343
|
+
profile_name = ctx.obj.profile_name
|
|
344
|
+
profile = manager.get_profile(profile_name)
|
|
345
|
+
|
|
346
|
+
if not profile:
|
|
347
|
+
console.print(f"[red]Profile '{profile_name}' not found[/red]")
|
|
348
|
+
raise click.Abort()
|
|
349
|
+
|
|
350
|
+
# Load config
|
|
351
|
+
with open(config_file, 'r') as f:
|
|
352
|
+
config = json.load(f)
|
|
353
|
+
|
|
354
|
+
# Create client
|
|
355
|
+
client = create_client(profile)
|
|
356
|
+
|
|
357
|
+
# Test connection
|
|
358
|
+
with console.status(f"[bold green]Testing connection..."):
|
|
359
|
+
result = client.test_source_connection(config)
|
|
360
|
+
|
|
361
|
+
success = result.get("success", False)
|
|
362
|
+
|
|
363
|
+
if success:
|
|
364
|
+
console.print(f"[green]✓[/green] Connection test successful")
|
|
365
|
+
else:
|
|
366
|
+
console.print(f"[red]✗[/red] Connection test failed")
|
|
367
|
+
error = result.get("error", "Unknown error")
|
|
368
|
+
console.print(f" Error: {error}")
|
|
369
|
+
|
|
370
|
+
except Exception as e:
|
|
371
|
+
console.print(f"[red]Error: {e}[/red]")
|
|
372
|
+
if ctx.obj.verbose:
|
|
373
|
+
import traceback
|
|
374
|
+
traceback.print_exc()
|
|
375
|
+
raise click.Abort()
|