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.
Files changed (45) hide show
  1. dremio_cli/__init__.py +5 -0
  2. dremio_cli/__main__.py +6 -0
  3. dremio_cli/cli.py +191 -0
  4. dremio_cli/client/__init__.py +1 -0
  5. dremio_cli/client/auth.py +100 -0
  6. dremio_cli/client/base.py +190 -0
  7. dremio_cli/client/cloud.py +305 -0
  8. dremio_cli/client/factory.py +122 -0
  9. dremio_cli/client/software.py +561 -0
  10. dremio_cli/commands/__init__.py +1 -0
  11. dremio_cli/commands/catalog.py +143 -0
  12. dremio_cli/commands/favorite.py +162 -0
  13. dremio_cli/commands/folder.py +290 -0
  14. dremio_cli/commands/grant.py +202 -0
  15. dremio_cli/commands/history.py +122 -0
  16. dremio_cli/commands/job.py +321 -0
  17. dremio_cli/commands/lineage.py +9 -0
  18. dremio_cli/commands/profile.py +165 -0
  19. dremio_cli/commands/role.py +319 -0
  20. dremio_cli/commands/source.py +375 -0
  21. dremio_cli/commands/space.py +226 -0
  22. dremio_cli/commands/sql.py +280 -0
  23. dremio_cli/commands/table.py +155 -0
  24. dremio_cli/commands/tag.py +145 -0
  25. dremio_cli/commands/udf.py +9 -0
  26. dremio_cli/commands/user.py +250 -0
  27. dremio_cli/commands/view.py +369 -0
  28. dremio_cli/commands/wiki.py +163 -0
  29. dremio_cli/config.py +193 -0
  30. dremio_cli/env.py +175 -0
  31. dremio_cli/formatters/__init__.py +1 -0
  32. dremio_cli/formatters/json.py +19 -0
  33. dremio_cli/formatters/table.py +45 -0
  34. dremio_cli/formatters/yaml.py +17 -0
  35. dremio_cli/history.py +198 -0
  36. dremio_cli/utils/__init__.py +1 -0
  37. dremio_cli/utils/exceptions.py +35 -0
  38. dremio_cli/utils/helpers.py +73 -0
  39. dremio_cli/utils/validators.py +147 -0
  40. dremio_cli-1.0.0.dist-info/METADATA +261 -0
  41. dremio_cli-1.0.0.dist-info/RECORD +45 -0
  42. dremio_cli-1.0.0.dist-info/WHEEL +5 -0
  43. dremio_cli-1.0.0.dist-info/entry_points.txt +2 -0
  44. dremio_cli-1.0.0.dist-info/licenses/LICENSE +21 -0
  45. dremio_cli-1.0.0.dist-info/top_level.txt +1 -0
@@ -0,0 +1,305 @@
1
+ """Dremio Cloud API client."""
2
+
3
+ from typing import Any, Dict, Optional
4
+
5
+ from dremio_cli.client.base import BaseClient
6
+
7
+
8
+ class CloudClient(BaseClient):
9
+ """Client for Dremio Cloud API."""
10
+
11
+ def __init__(
12
+ self,
13
+ base_url: str,
14
+ project_id: str,
15
+ token: str,
16
+ timeout: int = 30,
17
+ ):
18
+ """Initialize Cloud client.
19
+
20
+ Args:
21
+ base_url: Base URL for Dremio Cloud API
22
+ project_id: Project ID
23
+ token: Authentication token
24
+ timeout: Request timeout in seconds
25
+ """
26
+ super().__init__(base_url, token, timeout)
27
+ self.project_id = project_id
28
+
29
+ def _project_endpoint(self, endpoint: str) -> str:
30
+ """Build project-scoped endpoint.
31
+
32
+ Args:
33
+ endpoint: Endpoint path
34
+
35
+ Returns:
36
+ Project-scoped endpoint
37
+ """
38
+ return f"/projects/{self.project_id}/{endpoint.lstrip('/')}"
39
+
40
+ # Catalog operations
41
+ def get_catalog(self, include: Optional[str] = None) -> Dict[str, Any]:
42
+ """Get catalog."""
43
+ params = {"include": include} if include else None
44
+ return self.get(self._project_endpoint("catalog"), params=params)
45
+
46
+ def get_catalog_item(self, item_id: str, include: Optional[str] = None) -> Dict[str, Any]:
47
+ """Get catalog item by ID."""
48
+ params = {"include": include} if include else None
49
+ return self.get(self._project_endpoint(f"catalog/{item_id}"), params=params)
50
+
51
+ def get_catalog_item_by_path(self, path: str, include: Optional[str] = None) -> Dict[str, Any]:
52
+ """Get catalog item by path."""
53
+ params = {"include": include} if include else None
54
+ return self.get(self._project_endpoint(f"catalog/by-path/{path}"), params=params)
55
+
56
+ # Source operations
57
+ def create_source(self, source_data: Dict[str, Any]) -> Dict[str, Any]:
58
+ """Create a source."""
59
+ return self.post(self._project_endpoint("catalog"), data=source_data)
60
+
61
+ def update_source(self, source_id: str, source_data: Dict[str, Any]) -> Dict[str, Any]:
62
+ """Update a source."""
63
+ return self.put(self._project_endpoint(f"catalog/{source_id}"), data=source_data)
64
+
65
+ def delete_source(self, source_id: str) -> None:
66
+ """Delete a source."""
67
+ return self.delete(self._project_endpoint(f"catalog/{source_id}"))
68
+
69
+ # Job operations
70
+ def list_jobs(
71
+ self,
72
+ max_results: Optional[int] = None,
73
+ filter_expr: Optional[str] = None,
74
+ sort: Optional[str] = None,
75
+ ) -> Dict[str, Any]:
76
+ """List jobs."""
77
+ params = {}
78
+ if max_results:
79
+ params["maxResults"] = max_results
80
+ if filter_expr:
81
+ params["filter"] = filter_expr
82
+ if sort:
83
+ params["sort"] = sort
84
+ return self.get(self._project_endpoint("job"), params=params if params else None)
85
+
86
+ def get_job(self, job_id: str) -> Dict[str, Any]:
87
+ """Get job by ID."""
88
+ return self.get(self._project_endpoint(f"job/{job_id}"))
89
+
90
+ def get_job_results(
91
+ self,
92
+ job_id: str,
93
+ limit: Optional[int] = None,
94
+ offset: Optional[int] = None,
95
+ ) -> Dict[str, Any]:
96
+ """Get job results."""
97
+ params = {}
98
+ if limit:
99
+ params["limit"] = limit
100
+ if offset:
101
+ params["offset"] = offset
102
+ return self.get(self._project_endpoint(f"job/{job_id}/results"), params=params if params else None)
103
+
104
+ def cancel_job(self, job_id: str) -> None:
105
+ """Cancel a job."""
106
+ return self.post(self._project_endpoint(f"job/{job_id}/cancel"))
107
+
108
+ # View operations
109
+ def create_view(self, view_data: Dict[str, Any]) -> Dict[str, Any]:
110
+ """Create a view."""
111
+ return self.post(self._project_endpoint("catalog"), data=view_data)
112
+
113
+ def update_view(self, view_id: str, view_data: Dict[str, Any]) -> Dict[str, Any]:
114
+ """Update a view."""
115
+ return self.put(self._project_endpoint(f"catalog/{view_id}"), data=view_data)
116
+
117
+ def delete_view(self, view_id: str, tag: str) -> None:
118
+ """Delete a view."""
119
+ return self.delete(self._project_endpoint(f"catalog/{view_id}?tag={tag}"))
120
+
121
+ # Space operations (Cloud: creates top-level folders)
122
+ def create_space(self, space_data: Dict[str, Any]) -> Dict[str, Any]:
123
+ """Create a space (top-level folder in Cloud).
124
+
125
+ In Cloud, spaces are represented as top-level folders in the project catalog.
126
+
127
+ Args:
128
+ space_data: Space definition with 'name' and optional 'description'
129
+
130
+ Returns:
131
+ Created folder
132
+ """
133
+ # In Cloud, create a top-level folder
134
+ data = {
135
+ "entityType": "folder",
136
+ "path": [space_data["name"]],
137
+ }
138
+ if "description" in space_data:
139
+ data["description"] = space_data["description"]
140
+
141
+ return self.post(self._project_endpoint("catalog"), data=data)
142
+
143
+ def delete_space(self, space_id: str, tag: str) -> None:
144
+ """Delete a space (folder in Cloud).
145
+
146
+ Args:
147
+ space_id: Space/folder ID
148
+ tag: Version tag for optimistic concurrency
149
+ """
150
+ return self.delete(self._project_endpoint(f"catalog/{space_id}?tag={tag}"))
151
+
152
+ # Folder operations
153
+ def create_folder(self, folder_data: Dict[str, Any]) -> Dict[str, Any]:
154
+ """Create a folder.
155
+
156
+ Args:
157
+ folder_data: Folder definition with 'path' and optional 'description'
158
+
159
+ Returns:
160
+ Created folder
161
+ """
162
+ data = {
163
+ "entityType": "folder",
164
+ "path": folder_data["path"],
165
+ }
166
+ if "description" in folder_data:
167
+ data["description"] = folder_data["description"]
168
+
169
+ return self.post(self._project_endpoint("catalog"), data=data)
170
+
171
+ def delete_folder(self, folder_id: str, tag: str) -> None:
172
+ """Delete a folder.
173
+
174
+ Args:
175
+ folder_id: Folder ID
176
+ tag: Version tag for optimistic concurrency
177
+ """
178
+ return self.delete(self._project_endpoint(f"catalog/{folder_id}?tag={tag}"))
179
+
180
+ # Tag operations
181
+ def set_tags(self, catalog_id: str, tags: list) -> None:
182
+ """Set tags on a catalog object."""
183
+ return self.post(self._project_endpoint(f"catalog/{catalog_id}/collaboration/tag"), data={"tags": tags})
184
+
185
+ def get_tags(self, catalog_id: str) -> dict:
186
+ """Get tags from a catalog object."""
187
+ return self.get(self._project_endpoint(f"catalog/{catalog_id}/collaboration/tag"))
188
+
189
+ def delete_tags(self, catalog_id: str) -> None:
190
+ """Delete tags from a catalog object."""
191
+ return self.delete(self._project_endpoint(f"catalog/{catalog_id}/collaboration/tag"))
192
+
193
+ # Wiki operations
194
+ def set_wiki(self, catalog_id: str, text: str) -> None:
195
+ """Set wiki on a catalog object."""
196
+ return self.post(self._project_endpoint(f"catalog/{catalog_id}/collaboration/wiki"), data={"text": text})
197
+
198
+ def get_wiki(self, catalog_id: str) -> dict:
199
+ """Get wiki from a catalog object."""
200
+ return self.get(self._project_endpoint(f"catalog/{catalog_id}/collaboration/wiki"))
201
+
202
+ def delete_wiki(self, catalog_id: str) -> None:
203
+ """Delete wiki from a catalog object."""
204
+ return self.delete(self._project_endpoint(f"catalog/{catalog_id}/collaboration/wiki"))
205
+
206
+ # Source operations
207
+ def create_source(self, source_data: Dict[str, Any]) -> Dict[str, Any]:
208
+ """Create a source."""
209
+ return self.post(self._project_endpoint("catalog"), data=source_data)
210
+
211
+ def update_source(self, source_id: str, source_data: Dict[str, Any]) -> Dict[str, Any]:
212
+ """Update a source."""
213
+ return self.put(self._project_endpoint(f"catalog/{source_id}"), data=source_data)
214
+
215
+ def delete_source(self, source_id: str, tag: str) -> None:
216
+ """Delete a source."""
217
+ return self.delete(self._project_endpoint(f"catalog/{source_id}?tag={tag}"))
218
+
219
+ def refresh_source(self, source_id: str) -> Dict[str, Any]:
220
+ """Refresh source metadata."""
221
+ return self.post(self._project_endpoint(f"source/{source_id}/refresh"))
222
+
223
+ def test_source_connection(self, config: Dict[str, Any]) -> Dict[str, Any]:
224
+ """Test source connection."""
225
+ return self.post(self._project_endpoint("source/test"), data=config)
226
+
227
+ # Grant operations
228
+ def list_grants(self, catalog_id: str) -> Dict[str, Any]:
229
+ """List grants for a catalog object."""
230
+ return self.get(self._project_endpoint(f"catalog/{catalog_id}/grants"))
231
+
232
+ def add_grant(self, catalog_id: str, grant_data: Dict[str, Any]) -> None:
233
+ """Add a grant to a catalog object."""
234
+ return self.post(self._project_endpoint(f"catalog/{catalog_id}/grants"), data=grant_data)
235
+
236
+ def remove_grant(self, catalog_id: str, grantee_type: str, grantee_id: str) -> None:
237
+ """Remove a grant from a catalog object."""
238
+ return self.delete(self._project_endpoint(f"catalog/{catalog_id}/grants/{grantee_type}/{grantee_id}"))
239
+
240
+ def set_grants(self, catalog_id: str, grants_data: Dict[str, Any]) -> None:
241
+ """Set all grants for a catalog object."""
242
+ return self.put(self._project_endpoint(f"catalog/{catalog_id}/grants"), data=grants_data)
243
+
244
+ # User operations
245
+ def list_users(self) -> Dict[str, Any]:
246
+ """List all users."""
247
+ return self.get(self._project_endpoint("user"))
248
+
249
+ def get_user(self, user_id: str) -> Dict[str, Any]:
250
+ """Get user by ID."""
251
+ return self.get(self._project_endpoint(f"user/{user_id}"))
252
+
253
+ def create_user(self, user_data: Dict[str, Any]) -> Dict[str, Any]:
254
+ """Create a user."""
255
+ return self.post(self._project_endpoint("user"), data=user_data)
256
+
257
+ def update_user(self, user_id: str, user_data: Dict[str, Any]) -> Dict[str, Any]:
258
+ """Update a user."""
259
+ return self.put(self._project_endpoint(f"user/{user_id}"), data=user_data)
260
+
261
+ def delete_user(self, user_id: str) -> None:
262
+ """Delete a user."""
263
+ return self.delete(self._project_endpoint(f"user/{user_id}"))
264
+
265
+ # Role operations
266
+ def list_roles(self) -> Dict[str, Any]:
267
+ """List all roles."""
268
+ return self.get(self._project_endpoint("role"))
269
+
270
+ def get_role(self, role_id: str) -> Dict[str, Any]:
271
+ """Get role by ID."""
272
+ return self.get(self._project_endpoint(f"role/{role_id}"))
273
+
274
+ def create_role(self, role_data: Dict[str, Any]) -> Dict[str, Any]:
275
+ """Create a role."""
276
+ return self.post(self._project_endpoint("role"), data=role_data)
277
+
278
+ def update_role(self, role_id: str, role_data: Dict[str, Any]) -> Dict[str, Any]:
279
+ """Update a role."""
280
+ return self.put(self._project_endpoint(f"role/{role_id}"), data=role_data)
281
+
282
+ def delete_role(self, role_id: str) -> None:
283
+ """Delete a role."""
284
+ return self.delete(self._project_endpoint(f"role/{role_id}"))
285
+
286
+ def add_role_member(self, role_id: str, user_id: str) -> None:
287
+ """Add a user to a role."""
288
+ return self.post(self._project_endpoint(f"role/{role_id}/members"), data={"userId": user_id})
289
+
290
+ def remove_role_member(self, role_id: str, user_id: str) -> None:
291
+ """Remove a user from a role."""
292
+ return self.delete(self._project_endpoint(f"role/{role_id}/members/{user_id}"))
293
+
294
+ # Table operations
295
+ def promote_dataset(self, dataset_id: str) -> Dict[str, Any]:
296
+ """Promote a dataset to a physical dataset."""
297
+ return self.post(self._project_endpoint(f"catalog/{dataset_id}/promote"))
298
+
299
+ def set_dataset_format(self, dataset_id: str, format_config: Dict[str, Any]) -> Dict[str, Any]:
300
+ """Set format configuration for a dataset."""
301
+ return self.post(self._project_endpoint(f"catalog/{dataset_id}/format"), data=format_config)
302
+
303
+ def update_dataset(self, dataset_id: str, dataset_data: Dict[str, Any]) -> Dict[str, Any]:
304
+ """Update dataset metadata."""
305
+ return self.put(self._project_endpoint(f"catalog/{dataset_id}"), data=dataset_data)
@@ -0,0 +1,122 @@
1
+ """Client factory for creating appropriate Dremio clients."""
2
+
3
+ from typing import Dict, Any, Union
4
+
5
+ from dremio_cli.client.cloud import CloudClient
6
+ from dremio_cli.client.software import SoftwareClient
7
+ from dremio_cli.client.auth import authenticate_with_username_password
8
+ from dremio_cli.utils.exceptions import ConfigurationError, AuthenticationError
9
+
10
+
11
+ def create_client(profile: Dict[str, Any]) -> Union[CloudClient, SoftwareClient]:
12
+ """Create appropriate Dremio client from profile.
13
+
14
+ Args:
15
+ profile: Profile configuration dictionary
16
+
17
+ Returns:
18
+ CloudClient or SoftwareClient instance
19
+
20
+ Raises:
21
+ ConfigurationError: If profile is invalid
22
+ AuthenticationError: If authentication fails
23
+ """
24
+ profile_type = profile.get("type")
25
+
26
+ if not profile_type:
27
+ raise ConfigurationError("Profile missing 'type' field")
28
+
29
+ if profile_type not in ["cloud", "software"]:
30
+ raise ConfigurationError(f"Invalid profile type: {profile_type}")
31
+
32
+ base_url = profile.get("base_url")
33
+ if not base_url:
34
+ raise ConfigurationError("Profile missing 'base_url' field")
35
+
36
+ auth = profile.get("auth", {})
37
+ auth_type = auth.get("type")
38
+
39
+ if not auth_type:
40
+ raise ConfigurationError("Profile missing 'auth.type' field")
41
+
42
+ # Get or generate token
43
+ token = _get_token(profile, auth, base_url)
44
+
45
+ # Create appropriate client
46
+ if profile_type == "cloud":
47
+ project_id = profile.get("project_id")
48
+ if not project_id:
49
+ raise ConfigurationError("Cloud profile missing 'project_id' field")
50
+
51
+ return CloudClient(
52
+ base_url=base_url,
53
+ project_id=project_id,
54
+ token=token,
55
+ )
56
+ else: # software
57
+ return SoftwareClient(
58
+ base_url=base_url,
59
+ token=token,
60
+ )
61
+
62
+
63
+ def _get_token(profile: Dict[str, Any], auth: Dict[str, Any], base_url: str) -> str:
64
+ """Get authentication token from profile or generate it.
65
+
66
+ Args:
67
+ profile: Profile configuration
68
+ auth: Auth configuration
69
+ base_url: Base URL for API
70
+
71
+ Returns:
72
+ Authentication token
73
+
74
+ Raises:
75
+ AuthenticationError: If authentication fails
76
+ ConfigurationError: If auth configuration is invalid
77
+ """
78
+ auth_type = auth.get("type")
79
+
80
+ if auth_type == "pat":
81
+ token = auth.get("token")
82
+ if not token:
83
+ raise ConfigurationError("PAT auth requires 'token' field")
84
+ return token
85
+
86
+ elif auth_type == "oauth":
87
+ token = auth.get("token")
88
+ if not token:
89
+ raise ConfigurationError("OAuth auth requires 'token' field")
90
+ # TODO: Check if token is expired and refresh if needed
91
+ return token
92
+
93
+ elif auth_type == "username_password":
94
+ # Check if we have a cached token
95
+ cached_token = auth.get("token")
96
+ if cached_token:
97
+ # TODO: Check if token is expired
98
+ return cached_token
99
+
100
+ # Generate new token
101
+ username = auth.get("username")
102
+ password = auth.get("password")
103
+
104
+ if not username or not password:
105
+ raise ConfigurationError(
106
+ "Username/password auth requires 'username' and 'password' fields"
107
+ )
108
+
109
+ # Only supported for Software
110
+ if profile.get("type") != "software":
111
+ raise ConfigurationError(
112
+ "Username/password auth only supported for Dremio Software"
113
+ )
114
+
115
+ token = authenticate_with_username_password(base_url, username, password)
116
+
117
+ # TODO: Cache token in profile for future use
118
+
119
+ return token
120
+
121
+ else:
122
+ raise ConfigurationError(f"Unsupported auth type: {auth_type}")