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,561 @@
|
|
|
1
|
+
"""Dremio Software API client."""
|
|
2
|
+
|
|
3
|
+
from typing import Any, Dict, Optional
|
|
4
|
+
|
|
5
|
+
from dremio_cli.client.base import BaseClient
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
class SoftwareClient(BaseClient):
|
|
9
|
+
"""Client for Dremio Software API."""
|
|
10
|
+
|
|
11
|
+
def __init__(
|
|
12
|
+
self,
|
|
13
|
+
base_url: str,
|
|
14
|
+
token: str,
|
|
15
|
+
timeout: int = 30,
|
|
16
|
+
):
|
|
17
|
+
"""Initialize Software client.
|
|
18
|
+
|
|
19
|
+
Args:
|
|
20
|
+
base_url: Base URL for Dremio Software API
|
|
21
|
+
token: Authentication token
|
|
22
|
+
timeout: Request timeout in seconds
|
|
23
|
+
"""
|
|
24
|
+
super().__init__(base_url, token, timeout)
|
|
25
|
+
|
|
26
|
+
# Catalog operations
|
|
27
|
+
def get_catalog(
|
|
28
|
+
self,
|
|
29
|
+
include: Optional[str] = None,
|
|
30
|
+
exclude: Optional[str] = None,
|
|
31
|
+
) -> Dict[str, Any]:
|
|
32
|
+
"""Get catalog."""
|
|
33
|
+
params = {}
|
|
34
|
+
if include:
|
|
35
|
+
params["include"] = include
|
|
36
|
+
if exclude:
|
|
37
|
+
params["exclude"] = exclude
|
|
38
|
+
return self.get("catalog", params=params if params else None)
|
|
39
|
+
|
|
40
|
+
def get_catalog_item(
|
|
41
|
+
self,
|
|
42
|
+
item_id: str,
|
|
43
|
+
include: Optional[str] = None,
|
|
44
|
+
exclude: Optional[str] = None,
|
|
45
|
+
max_children: Optional[int] = None,
|
|
46
|
+
) -> Dict[str, Any]:
|
|
47
|
+
"""Get catalog item by ID."""
|
|
48
|
+
params = {}
|
|
49
|
+
if include:
|
|
50
|
+
params["include"] = include
|
|
51
|
+
if exclude:
|
|
52
|
+
params["exclude"] = exclude
|
|
53
|
+
if max_children:
|
|
54
|
+
params["maxChildren"] = max_children
|
|
55
|
+
return self.get(f"catalog/{item_id}", params=params or None)
|
|
56
|
+
|
|
57
|
+
def get_catalog_item_by_path(
|
|
58
|
+
self,
|
|
59
|
+
path: str,
|
|
60
|
+
include: Optional[str] = None,
|
|
61
|
+
exclude: Optional[str] = None,
|
|
62
|
+
) -> Dict[str, Any]:
|
|
63
|
+
"""Get catalog item by path."""
|
|
64
|
+
params = {}
|
|
65
|
+
if include:
|
|
66
|
+
params["include"] = include
|
|
67
|
+
if exclude:
|
|
68
|
+
params["exclude"] = exclude
|
|
69
|
+
return self.get(f"catalog/by-path/{path}", params=params or None)
|
|
70
|
+
|
|
71
|
+
# Source operations
|
|
72
|
+
def create_source(self, source_data: Dict[str, Any]) -> Dict[str, Any]:
|
|
73
|
+
"""Create a source."""
|
|
74
|
+
return self.post("catalog", data=source_data)
|
|
75
|
+
|
|
76
|
+
def update_source(self, source_id: str, source_data: Dict[str, Any]) -> Dict[str, Any]:
|
|
77
|
+
"""Update a source."""
|
|
78
|
+
return self.put(f"catalog/{source_id}", data=source_data)
|
|
79
|
+
|
|
80
|
+
def delete_source(self, source_id: str) -> None:
|
|
81
|
+
"""Delete a source."""
|
|
82
|
+
return self.delete(f"catalog/{source_id}")
|
|
83
|
+
|
|
84
|
+
# SQL operations
|
|
85
|
+
def execute_sql(self, sql: str, context: Optional[list] = None) -> Dict[str, Any]:
|
|
86
|
+
"""Execute SQL query."""
|
|
87
|
+
data = {"sql": sql}
|
|
88
|
+
if context:
|
|
89
|
+
data["context"] = context
|
|
90
|
+
return self.post("sql", data=data)
|
|
91
|
+
|
|
92
|
+
# Job operations
|
|
93
|
+
def get_job(self, job_id: str) -> Dict[str, Any]:
|
|
94
|
+
"""Get job by ID."""
|
|
95
|
+
return self.get(f"job/{job_id}")
|
|
96
|
+
|
|
97
|
+
def get_job_results(
|
|
98
|
+
self,
|
|
99
|
+
job_id: str,
|
|
100
|
+
limit: Optional[int] = None,
|
|
101
|
+
offset: Optional[int] = None,
|
|
102
|
+
) -> Dict[str, Any]:
|
|
103
|
+
"""Get job results."""
|
|
104
|
+
params = {}
|
|
105
|
+
if limit:
|
|
106
|
+
params["limit"] = limit
|
|
107
|
+
if offset:
|
|
108
|
+
params["offset"] = offset
|
|
109
|
+
return self.get(f"job/{job_id}/results", params=params or None)
|
|
110
|
+
|
|
111
|
+
def cancel_job(self, job_id: str) -> None:
|
|
112
|
+
"""Cancel a job."""
|
|
113
|
+
return self.post(f"job/{job_id}/cancel")
|
|
114
|
+
|
|
115
|
+
# Job management operations
|
|
116
|
+
def list_jobs(
|
|
117
|
+
self,
|
|
118
|
+
max_results: Optional[int] = None,
|
|
119
|
+
filter_expr: Optional[str] = None,
|
|
120
|
+
sort: Optional[str] = None,
|
|
121
|
+
) -> Dict[str, Any]:
|
|
122
|
+
"""List jobs.
|
|
123
|
+
|
|
124
|
+
Args:
|
|
125
|
+
max_results: Maximum number of results
|
|
126
|
+
filter_expr: Filter expression (e.g., 'state=COMPLETED')
|
|
127
|
+
sort: Sort field (prefix with - for descending)
|
|
128
|
+
|
|
129
|
+
Returns:
|
|
130
|
+
Jobs list response
|
|
131
|
+
"""
|
|
132
|
+
params = {}
|
|
133
|
+
if max_results:
|
|
134
|
+
params["maxResults"] = max_results
|
|
135
|
+
if filter_expr:
|
|
136
|
+
params["filter"] = filter_expr
|
|
137
|
+
if sort:
|
|
138
|
+
params["sort"] = sort
|
|
139
|
+
return self.get("job", params=params if params else None)
|
|
140
|
+
|
|
141
|
+
def get_job_profile(self, job_id: str) -> Any:
|
|
142
|
+
"""Get job profile for performance analysis.
|
|
143
|
+
|
|
144
|
+
Args:
|
|
145
|
+
job_id: Job ID
|
|
146
|
+
|
|
147
|
+
Returns:
|
|
148
|
+
Job profile data
|
|
149
|
+
"""
|
|
150
|
+
return self.get(f"job/{job_id}/download")
|
|
151
|
+
|
|
152
|
+
def get_job_reflections(self, job_id: str) -> Dict[str, Any]:
|
|
153
|
+
"""Get reflection information for a job.
|
|
154
|
+
|
|
155
|
+
Args:
|
|
156
|
+
job_id: Job ID
|
|
157
|
+
|
|
158
|
+
Returns:
|
|
159
|
+
Job reflection information
|
|
160
|
+
"""
|
|
161
|
+
return self.get(f"job/{job_id}/reflection")
|
|
162
|
+
|
|
163
|
+
# View operations
|
|
164
|
+
def create_view(self, view_data: Dict[str, Any]) -> Dict[str, Any]:
|
|
165
|
+
"""Create a view.
|
|
166
|
+
|
|
167
|
+
Args:
|
|
168
|
+
view_data: View definition
|
|
169
|
+
|
|
170
|
+
Returns:
|
|
171
|
+
Created view
|
|
172
|
+
"""
|
|
173
|
+
return self.post("catalog", data=view_data)
|
|
174
|
+
|
|
175
|
+
def update_view(self, view_id: str, view_data: Dict[str, Any]) -> Dict[str, Any]:
|
|
176
|
+
"""Update a view.
|
|
177
|
+
|
|
178
|
+
Args:
|
|
179
|
+
view_id: View ID
|
|
180
|
+
view_data: Updated view definition
|
|
181
|
+
|
|
182
|
+
Returns:
|
|
183
|
+
Updated view
|
|
184
|
+
"""
|
|
185
|
+
return self.put(f"catalog/{view_id}", data=view_data)
|
|
186
|
+
|
|
187
|
+
def delete_view(self, view_id: str, tag: str) -> None:
|
|
188
|
+
"""Delete a view.
|
|
189
|
+
|
|
190
|
+
Args:
|
|
191
|
+
view_id: View ID
|
|
192
|
+
tag: Version tag for optimistic concurrency
|
|
193
|
+
"""
|
|
194
|
+
return self.delete(f"catalog/{view_id}?tag={tag}")
|
|
195
|
+
|
|
196
|
+
# Space operations
|
|
197
|
+
def create_space(self, space_data: Dict[str, Any]) -> Dict[str, Any]:
|
|
198
|
+
"""Create a space.
|
|
199
|
+
|
|
200
|
+
Args:
|
|
201
|
+
space_data: Space definition with 'name' and optional 'description'
|
|
202
|
+
|
|
203
|
+
Returns:
|
|
204
|
+
Created space
|
|
205
|
+
"""
|
|
206
|
+
# Create SPACE container
|
|
207
|
+
data = {
|
|
208
|
+
"entityType": "space",
|
|
209
|
+
"name": space_data["name"],
|
|
210
|
+
}
|
|
211
|
+
if "description" in space_data:
|
|
212
|
+
data["description"] = space_data["description"]
|
|
213
|
+
|
|
214
|
+
return self.post("catalog", data=data)
|
|
215
|
+
|
|
216
|
+
def delete_space(self, space_id: str, tag: str) -> None:
|
|
217
|
+
"""Delete a space.
|
|
218
|
+
|
|
219
|
+
Args:
|
|
220
|
+
space_id: Space ID
|
|
221
|
+
tag: Version tag for optimistic concurrency
|
|
222
|
+
"""
|
|
223
|
+
return self.delete(f"catalog/{space_id}?tag={tag}")
|
|
224
|
+
|
|
225
|
+
# Folder operations
|
|
226
|
+
def create_folder(self, folder_data: Dict[str, Any]) -> Dict[str, Any]:
|
|
227
|
+
"""Create a folder.
|
|
228
|
+
|
|
229
|
+
Args:
|
|
230
|
+
folder_data: Folder definition with 'path' and optional 'description'
|
|
231
|
+
|
|
232
|
+
Returns:
|
|
233
|
+
Created folder
|
|
234
|
+
"""
|
|
235
|
+
# Create FOLDER container
|
|
236
|
+
data = {
|
|
237
|
+
"entityType": "folder",
|
|
238
|
+
"path": folder_data["path"],
|
|
239
|
+
}
|
|
240
|
+
if "description" in folder_data:
|
|
241
|
+
data["description"] = folder_data["description"]
|
|
242
|
+
|
|
243
|
+
return self.post("catalog", data=data)
|
|
244
|
+
|
|
245
|
+
def delete_folder(self, folder_id: str, tag: str) -> None:
|
|
246
|
+
"""Delete a folder.
|
|
247
|
+
|
|
248
|
+
Args:
|
|
249
|
+
folder_id: Folder ID
|
|
250
|
+
tag: Version tag for optimistic concurrency
|
|
251
|
+
"""
|
|
252
|
+
return self.delete(f"catalog/{folder_id}?tag={tag}")
|
|
253
|
+
|
|
254
|
+
# Tag operations
|
|
255
|
+
def set_tags(self, catalog_id: str, tags: list) -> None:
|
|
256
|
+
"""Set tags on a catalog object.
|
|
257
|
+
|
|
258
|
+
Args:
|
|
259
|
+
catalog_id: Catalog object ID
|
|
260
|
+
tags: List of tag strings
|
|
261
|
+
"""
|
|
262
|
+
return self.post(f"catalog/{catalog_id}/collaboration/tag", data={"tags": tags})
|
|
263
|
+
|
|
264
|
+
def get_tags(self, catalog_id: str) -> dict:
|
|
265
|
+
"""Get tags from a catalog object.
|
|
266
|
+
|
|
267
|
+
Args:
|
|
268
|
+
catalog_id: Catalog object ID
|
|
269
|
+
|
|
270
|
+
Returns:
|
|
271
|
+
Tags data
|
|
272
|
+
"""
|
|
273
|
+
return self.get(f"catalog/{catalog_id}/collaboration/tag")
|
|
274
|
+
|
|
275
|
+
def delete_tags(self, catalog_id: str) -> None:
|
|
276
|
+
"""Delete tags from a catalog object.
|
|
277
|
+
|
|
278
|
+
Args:
|
|
279
|
+
catalog_id: Catalog object ID
|
|
280
|
+
"""
|
|
281
|
+
return self.delete(f"catalog/{catalog_id}/collaboration/tag")
|
|
282
|
+
|
|
283
|
+
# Wiki operations
|
|
284
|
+
def set_wiki(self, catalog_id: str, text: str) -> None:
|
|
285
|
+
"""Set wiki on a catalog object.
|
|
286
|
+
|
|
287
|
+
Args:
|
|
288
|
+
catalog_id: Catalog object ID
|
|
289
|
+
text: Wiki markdown text
|
|
290
|
+
"""
|
|
291
|
+
return self.post(f"catalog/{catalog_id}/collaboration/wiki", data={"text": text})
|
|
292
|
+
|
|
293
|
+
def get_wiki(self, catalog_id: str) -> dict:
|
|
294
|
+
"""Get wiki from a catalog object.
|
|
295
|
+
|
|
296
|
+
Args:
|
|
297
|
+
catalog_id: Catalog object ID
|
|
298
|
+
|
|
299
|
+
Returns:
|
|
300
|
+
Wiki data
|
|
301
|
+
"""
|
|
302
|
+
return self.get(f"catalog/{catalog_id}/collaboration/wiki")
|
|
303
|
+
|
|
304
|
+
def delete_wiki(self, catalog_id: str) -> None:
|
|
305
|
+
"""Delete wiki from a catalog object.
|
|
306
|
+
|
|
307
|
+
Args:
|
|
308
|
+
catalog_id: Catalog object ID
|
|
309
|
+
"""
|
|
310
|
+
return self.delete(f"catalog/{catalog_id}/collaboration/wiki")
|
|
311
|
+
|
|
312
|
+
# Source operations
|
|
313
|
+
def create_source(self, source_data: Dict[str, Any]) -> Dict[str, Any]:
|
|
314
|
+
"""Create a source.
|
|
315
|
+
|
|
316
|
+
Args:
|
|
317
|
+
source_data: Source definition with name, type, and config
|
|
318
|
+
|
|
319
|
+
Returns:
|
|
320
|
+
Created source
|
|
321
|
+
"""
|
|
322
|
+
return self.post("catalog", data=source_data)
|
|
323
|
+
|
|
324
|
+
def update_source(self, source_id: str, source_data: Dict[str, Any]) -> Dict[str, Any]:
|
|
325
|
+
"""Update a source.
|
|
326
|
+
|
|
327
|
+
Args:
|
|
328
|
+
source_id: Source ID
|
|
329
|
+
source_data: Updated source definition
|
|
330
|
+
|
|
331
|
+
Returns:
|
|
332
|
+
Updated source
|
|
333
|
+
"""
|
|
334
|
+
return self.put(f"catalog/{source_id}", data=source_data)
|
|
335
|
+
|
|
336
|
+
def delete_source(self, source_id: str, tag: str) -> None:
|
|
337
|
+
"""Delete a source.
|
|
338
|
+
|
|
339
|
+
Args:
|
|
340
|
+
source_id: Source ID
|
|
341
|
+
tag: Version tag for optimistic concurrency
|
|
342
|
+
"""
|
|
343
|
+
return self.delete(f"catalog/{source_id}?tag={tag}")
|
|
344
|
+
|
|
345
|
+
def refresh_source(self, source_id: str) -> Dict[str, Any]:
|
|
346
|
+
"""Refresh source metadata.
|
|
347
|
+
|
|
348
|
+
Args:
|
|
349
|
+
source_id: Source ID
|
|
350
|
+
|
|
351
|
+
Returns:
|
|
352
|
+
Refresh job information
|
|
353
|
+
"""
|
|
354
|
+
return self.post(f"source/{source_id}/refresh")
|
|
355
|
+
|
|
356
|
+
def test_source_connection(self, config: Dict[str, Any]) -> Dict[str, Any]:
|
|
357
|
+
"""Test source connection.
|
|
358
|
+
|
|
359
|
+
Args:
|
|
360
|
+
config: Source configuration
|
|
361
|
+
|
|
362
|
+
Returns:
|
|
363
|
+
Test result
|
|
364
|
+
"""
|
|
365
|
+
return self.post("source/test", data=config)
|
|
366
|
+
|
|
367
|
+
# Grant operations
|
|
368
|
+
def list_grants(self, catalog_id: str) -> Dict[str, Any]:
|
|
369
|
+
"""List grants for a catalog object.
|
|
370
|
+
|
|
371
|
+
Args:
|
|
372
|
+
catalog_id: Catalog object ID
|
|
373
|
+
|
|
374
|
+
Returns:
|
|
375
|
+
Grants data
|
|
376
|
+
"""
|
|
377
|
+
return self.get(f"catalog/{catalog_id}/grants")
|
|
378
|
+
|
|
379
|
+
def add_grant(self, catalog_id: str, grant_data: Dict[str, Any]) -> None:
|
|
380
|
+
"""Add a grant to a catalog object.
|
|
381
|
+
|
|
382
|
+
Args:
|
|
383
|
+
catalog_id: Catalog object ID
|
|
384
|
+
grant_data: Grant definition with granteeType, granteeId, and privileges
|
|
385
|
+
"""
|
|
386
|
+
return self.post(f"catalog/{catalog_id}/grants", data=grant_data)
|
|
387
|
+
|
|
388
|
+
def remove_grant(self, catalog_id: str, grantee_type: str, grantee_id: str) -> None:
|
|
389
|
+
"""Remove a grant from a catalog object.
|
|
390
|
+
|
|
391
|
+
Args:
|
|
392
|
+
catalog_id: Catalog object ID
|
|
393
|
+
grantee_type: USER or ROLE
|
|
394
|
+
grantee_id: User or role ID
|
|
395
|
+
"""
|
|
396
|
+
return self.delete(f"catalog/{catalog_id}/grants/{grantee_type}/{grantee_id}")
|
|
397
|
+
|
|
398
|
+
def set_grants(self, catalog_id: str, grants_data: Dict[str, Any]) -> None:
|
|
399
|
+
"""Set all grants for a catalog object (replaces existing).
|
|
400
|
+
|
|
401
|
+
Args:
|
|
402
|
+
catalog_id: Catalog object ID
|
|
403
|
+
grants_data: Complete grants definition
|
|
404
|
+
"""
|
|
405
|
+
return self.put(f"catalog/{catalog_id}/grants", data=grants_data)
|
|
406
|
+
|
|
407
|
+
# User operations
|
|
408
|
+
def list_users(self) -> Dict[str, Any]:
|
|
409
|
+
"""List all users.
|
|
410
|
+
|
|
411
|
+
Returns:
|
|
412
|
+
Users data
|
|
413
|
+
"""
|
|
414
|
+
return self.get("user")
|
|
415
|
+
|
|
416
|
+
def get_user(self, user_id: str) -> Dict[str, Any]:
|
|
417
|
+
"""Get user by ID.
|
|
418
|
+
|
|
419
|
+
Args:
|
|
420
|
+
user_id: User ID
|
|
421
|
+
|
|
422
|
+
Returns:
|
|
423
|
+
User data
|
|
424
|
+
"""
|
|
425
|
+
return self.get(f"user/{user_id}")
|
|
426
|
+
|
|
427
|
+
def create_user(self, user_data: Dict[str, Any]) -> Dict[str, Any]:
|
|
428
|
+
"""Create a user.
|
|
429
|
+
|
|
430
|
+
Args:
|
|
431
|
+
user_data: User definition with name, email, userName
|
|
432
|
+
|
|
433
|
+
Returns:
|
|
434
|
+
Created user
|
|
435
|
+
"""
|
|
436
|
+
return self.post("user", data=user_data)
|
|
437
|
+
|
|
438
|
+
def update_user(self, user_id: str, user_data: Dict[str, Any]) -> Dict[str, Any]:
|
|
439
|
+
"""Update a user.
|
|
440
|
+
|
|
441
|
+
Args:
|
|
442
|
+
user_id: User ID
|
|
443
|
+
user_data: Updated user definition
|
|
444
|
+
|
|
445
|
+
Returns:
|
|
446
|
+
Updated user
|
|
447
|
+
"""
|
|
448
|
+
return self.put(f"user/{user_id}", data=user_data)
|
|
449
|
+
|
|
450
|
+
def delete_user(self, user_id: str) -> None:
|
|
451
|
+
"""Delete a user.
|
|
452
|
+
|
|
453
|
+
Args:
|
|
454
|
+
user_id: User ID
|
|
455
|
+
"""
|
|
456
|
+
return self.delete(f"user/{user_id}")
|
|
457
|
+
|
|
458
|
+
# Role operations
|
|
459
|
+
def list_roles(self) -> Dict[str, Any]:
|
|
460
|
+
"""List all roles.
|
|
461
|
+
|
|
462
|
+
Returns:
|
|
463
|
+
Roles data
|
|
464
|
+
"""
|
|
465
|
+
return self.get("role")
|
|
466
|
+
|
|
467
|
+
def get_role(self, role_id: str) -> Dict[str, Any]:
|
|
468
|
+
"""Get role by ID.
|
|
469
|
+
|
|
470
|
+
Args:
|
|
471
|
+
role_id: Role ID
|
|
472
|
+
|
|
473
|
+
Returns:
|
|
474
|
+
Role data
|
|
475
|
+
"""
|
|
476
|
+
return self.get(f"role/{role_id}")
|
|
477
|
+
|
|
478
|
+
def create_role(self, role_data: Dict[str, Any]) -> Dict[str, Any]:
|
|
479
|
+
"""Create a role.
|
|
480
|
+
|
|
481
|
+
Args:
|
|
482
|
+
role_data: Role definition with name
|
|
483
|
+
|
|
484
|
+
Returns:
|
|
485
|
+
Created role
|
|
486
|
+
"""
|
|
487
|
+
return self.post("role", data=role_data)
|
|
488
|
+
|
|
489
|
+
def update_role(self, role_id: str, role_data: Dict[str, Any]) -> Dict[str, Any]:
|
|
490
|
+
"""Update a role.
|
|
491
|
+
|
|
492
|
+
Args:
|
|
493
|
+
role_id: Role ID
|
|
494
|
+
role_data: Updated role definition
|
|
495
|
+
|
|
496
|
+
Returns:
|
|
497
|
+
Updated role
|
|
498
|
+
"""
|
|
499
|
+
return self.put(f"role/{role_id}", data=role_data)
|
|
500
|
+
|
|
501
|
+
def delete_role(self, role_id: str) -> None:
|
|
502
|
+
"""Delete a role.
|
|
503
|
+
|
|
504
|
+
Args:
|
|
505
|
+
role_id: Role ID
|
|
506
|
+
"""
|
|
507
|
+
return self.delete(f"role/{role_id}")
|
|
508
|
+
|
|
509
|
+
def add_role_member(self, role_id: str, user_id: str) -> None:
|
|
510
|
+
"""Add a user to a role.
|
|
511
|
+
|
|
512
|
+
Args:
|
|
513
|
+
role_id: Role ID
|
|
514
|
+
user_id: User ID
|
|
515
|
+
"""
|
|
516
|
+
return self.post(f"role/{role_id}/members", data={"userId": user_id})
|
|
517
|
+
|
|
518
|
+
def remove_role_member(self, role_id: str, user_id: str) -> None:
|
|
519
|
+
"""Remove a user from a role.
|
|
520
|
+
|
|
521
|
+
Args:
|
|
522
|
+
role_id: Role ID
|
|
523
|
+
user_id: User ID
|
|
524
|
+
"""
|
|
525
|
+
return self.delete(f"role/{role_id}/members/{user_id}")
|
|
526
|
+
|
|
527
|
+
# Table operations
|
|
528
|
+
def promote_dataset(self, dataset_id: str) -> Dict[str, Any]:
|
|
529
|
+
"""Promote a dataset to a physical dataset.
|
|
530
|
+
|
|
531
|
+
Args:
|
|
532
|
+
dataset_id: Dataset ID
|
|
533
|
+
|
|
534
|
+
Returns:
|
|
535
|
+
Promoted dataset
|
|
536
|
+
"""
|
|
537
|
+
return self.post(f"catalog/{dataset_id}/promote")
|
|
538
|
+
|
|
539
|
+
def set_dataset_format(self, dataset_id: str, format_config: Dict[str, Any]) -> Dict[str, Any]:
|
|
540
|
+
"""Set format configuration for a dataset.
|
|
541
|
+
|
|
542
|
+
Args:
|
|
543
|
+
dataset_id: Dataset ID
|
|
544
|
+
format_config: Format configuration
|
|
545
|
+
|
|
546
|
+
Returns:
|
|
547
|
+
Updated dataset
|
|
548
|
+
"""
|
|
549
|
+
return self.post(f"catalog/{dataset_id}/format", data=format_config)
|
|
550
|
+
|
|
551
|
+
def update_dataset(self, dataset_id: str, dataset_data: Dict[str, Any]) -> Dict[str, Any]:
|
|
552
|
+
"""Update dataset metadata.
|
|
553
|
+
|
|
554
|
+
Args:
|
|
555
|
+
dataset_id: Dataset ID
|
|
556
|
+
dataset_data: Updated dataset definition
|
|
557
|
+
|
|
558
|
+
Returns:
|
|
559
|
+
Updated dataset
|
|
560
|
+
"""
|
|
561
|
+
return self.put(f"catalog/{dataset_id}", data=dataset_data)
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"""Command modules for Dremio CLI."""
|
|
@@ -0,0 +1,143 @@
|
|
|
1
|
+
"""Catalog commands implementation."""
|
|
2
|
+
|
|
3
|
+
import click
|
|
4
|
+
from rich.console import Console
|
|
5
|
+
|
|
6
|
+
from dremio_cli.config import ProfileManager
|
|
7
|
+
from dremio_cli.client.factory import create_client
|
|
8
|
+
from dremio_cli.formatters.table import format_as_table
|
|
9
|
+
from dremio_cli.formatters.json import format_as_json
|
|
10
|
+
from dremio_cli.formatters.yaml import format_as_yaml
|
|
11
|
+
|
|
12
|
+
console = Console()
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
@click.group()
|
|
16
|
+
def catalog() -> None:
|
|
17
|
+
"""Catalog operations."""
|
|
18
|
+
pass
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
@catalog.command("list")
|
|
22
|
+
@click.option("--include", help="Include additional fields (permissions, datasetCount)")
|
|
23
|
+
@click.pass_context
|
|
24
|
+
def list_catalog(ctx, include: str) -> None:
|
|
25
|
+
"""List catalog contents."""
|
|
26
|
+
try:
|
|
27
|
+
# Get profile
|
|
28
|
+
manager = ProfileManager()
|
|
29
|
+
profile_name = ctx.obj.profile_name
|
|
30
|
+
profile = manager.get_profile(profile_name)
|
|
31
|
+
|
|
32
|
+
if not profile:
|
|
33
|
+
console.print(f"[red]Profile '{profile_name}' not found[/red]")
|
|
34
|
+
raise click.Abort()
|
|
35
|
+
|
|
36
|
+
# Create client
|
|
37
|
+
client = create_client(profile)
|
|
38
|
+
|
|
39
|
+
# Make API call
|
|
40
|
+
if hasattr(client, 'get_catalog'):
|
|
41
|
+
data = client.get_catalog(include=include)
|
|
42
|
+
else:
|
|
43
|
+
console.print("[red]Client does not support catalog operations[/red]")
|
|
44
|
+
raise click.Abort()
|
|
45
|
+
|
|
46
|
+
# Format output
|
|
47
|
+
output_format = ctx.obj.output_format
|
|
48
|
+
if output_format == "json":
|
|
49
|
+
console.print(format_as_json(data))
|
|
50
|
+
elif output_format == "yaml":
|
|
51
|
+
console.print(format_as_yaml(data))
|
|
52
|
+
else:
|
|
53
|
+
# Display as table
|
|
54
|
+
items = data.get("data", [])
|
|
55
|
+
if items:
|
|
56
|
+
format_as_table(items, title=f"Catalog ({profile_name})")
|
|
57
|
+
else:
|
|
58
|
+
console.print("[yellow]No catalog items found[/yellow]")
|
|
59
|
+
|
|
60
|
+
except Exception as e:
|
|
61
|
+
console.print(f"[red]Error: {e}[/red]")
|
|
62
|
+
if ctx.obj.verbose:
|
|
63
|
+
import traceback
|
|
64
|
+
traceback.print_exc()
|
|
65
|
+
raise click.Abort()
|
|
66
|
+
|
|
67
|
+
|
|
68
|
+
@catalog.command("get")
|
|
69
|
+
@click.argument("item_id")
|
|
70
|
+
@click.option("--include", help="Include additional fields")
|
|
71
|
+
@click.pass_context
|
|
72
|
+
def get_catalog_item(ctx, item_id: str, include: str) -> None:
|
|
73
|
+
"""Get catalog item by ID."""
|
|
74
|
+
try:
|
|
75
|
+
# Get profile
|
|
76
|
+
manager = ProfileManager()
|
|
77
|
+
profile_name = ctx.obj.profile_name
|
|
78
|
+
profile = manager.get_profile(profile_name)
|
|
79
|
+
|
|
80
|
+
if not profile:
|
|
81
|
+
console.print(f"[red]Profile '{profile_name}' not found[/red]")
|
|
82
|
+
raise click.Abort()
|
|
83
|
+
|
|
84
|
+
# Create client
|
|
85
|
+
client = create_client(profile)
|
|
86
|
+
|
|
87
|
+
# Make API call
|
|
88
|
+
data = client.get_catalog_item(item_id, include=include)
|
|
89
|
+
|
|
90
|
+
# Format output
|
|
91
|
+
output_format = ctx.obj.output_format
|
|
92
|
+
if output_format == "json":
|
|
93
|
+
console.print(format_as_json(data))
|
|
94
|
+
elif output_format == "yaml":
|
|
95
|
+
console.print(format_as_yaml(data))
|
|
96
|
+
else:
|
|
97
|
+
format_as_table(data, title=f"Catalog Item: {item_id}")
|
|
98
|
+
|
|
99
|
+
except Exception as e:
|
|
100
|
+
console.print(f"[red]Error: {e}[/red]")
|
|
101
|
+
if ctx.obj.verbose:
|
|
102
|
+
import traceback
|
|
103
|
+
traceback.print_exc()
|
|
104
|
+
raise click.Abort()
|
|
105
|
+
|
|
106
|
+
|
|
107
|
+
@catalog.command("get-by-path")
|
|
108
|
+
@click.argument("path")
|
|
109
|
+
@click.option("--include", help="Include additional fields")
|
|
110
|
+
@click.pass_context
|
|
111
|
+
def get_catalog_item_by_path(ctx, path: str, include: str) -> None:
|
|
112
|
+
"""Get catalog item by path."""
|
|
113
|
+
try:
|
|
114
|
+
# Get profile
|
|
115
|
+
manager = ProfileManager()
|
|
116
|
+
profile_name = ctx.obj.profile_name
|
|
117
|
+
profile = manager.get_profile(profile_name)
|
|
118
|
+
|
|
119
|
+
if not profile:
|
|
120
|
+
console.print(f"[red]Profile '{profile_name}' not found[/red]")
|
|
121
|
+
raise click.Abort()
|
|
122
|
+
|
|
123
|
+
# Create client
|
|
124
|
+
client = create_client(profile)
|
|
125
|
+
|
|
126
|
+
# Make API call
|
|
127
|
+
data = client.get_catalog_item_by_path(path, include=include)
|
|
128
|
+
|
|
129
|
+
# Format output
|
|
130
|
+
output_format = ctx.obj.output_format
|
|
131
|
+
if output_format == "json":
|
|
132
|
+
console.print(format_as_json(data))
|
|
133
|
+
elif output_format == "yaml":
|
|
134
|
+
console.print(format_as_yaml(data))
|
|
135
|
+
else:
|
|
136
|
+
format_as_table(data, title=f"Catalog Item: {path}")
|
|
137
|
+
|
|
138
|
+
except Exception as e:
|
|
139
|
+
console.print(f"[red]Error: {e}[/red]")
|
|
140
|
+
if ctx.obj.verbose:
|
|
141
|
+
import traceback
|
|
142
|
+
traceback.print_exc()
|
|
143
|
+
raise click.Abort()
|