pltr-cli 0.4.0__py3-none-any.whl → 0.5.1__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.
@@ -0,0 +1,305 @@
1
+ """
2
+ Connectivity service wrapper for Foundry SDK.
3
+ """
4
+
5
+ from typing import Any, Optional, Dict, List
6
+
7
+ from .base import BaseService
8
+
9
+
10
+ class ConnectivityService(BaseService):
11
+ """Service wrapper for Foundry connectivity operations."""
12
+
13
+ def _get_service(self) -> Any:
14
+ """Get the Foundry client for connectivity operations."""
15
+ return self.client
16
+
17
+ @property
18
+ def connections_service(self) -> Any:
19
+ """Get the connections service from the client."""
20
+ return self.client.connections
21
+
22
+ @property
23
+ def file_imports_service(self) -> Any:
24
+ """Get the file imports service from the client."""
25
+ return self.client.file_imports
26
+
27
+ @property
28
+ def table_imports_service(self) -> Any:
29
+ """Get the table imports service from the client."""
30
+ return self.client.table_imports
31
+
32
+ def list_connections(self) -> List[Dict[str, Any]]:
33
+ """
34
+ List available connections.
35
+
36
+ Returns:
37
+ List of connection information dictionaries
38
+ """
39
+ try:
40
+ connections = self.connections_service.Connection.list()
41
+ return [self._format_connection_info(conn) for conn in connections]
42
+ except Exception as e:
43
+ raise RuntimeError(f"Failed to list connections: {e}")
44
+
45
+ def get_connection(self, connection_rid: str) -> Dict[str, Any]:
46
+ """
47
+ Get information about a specific connection.
48
+
49
+ Args:
50
+ connection_rid: Connection Resource Identifier
51
+
52
+ Returns:
53
+ Connection information dictionary
54
+ """
55
+ try:
56
+ connection = self.connections_service.Connection.get(connection_rid)
57
+ return self._format_connection_info(connection)
58
+ except Exception as e:
59
+ raise RuntimeError(f"Failed to get connection {connection_rid}: {e}")
60
+
61
+ def create_file_import(
62
+ self,
63
+ connection_rid: str,
64
+ source_path: str,
65
+ target_dataset_rid: str,
66
+ import_config: Optional[Dict[str, Any]] = None,
67
+ ) -> Dict[str, Any]:
68
+ """
69
+ Create a file import via connection.
70
+
71
+ Args:
72
+ connection_rid: Connection Resource Identifier
73
+ source_path: Path to source file in the connection
74
+ target_dataset_rid: Target dataset RID
75
+ import_config: Optional import configuration
76
+
77
+ Returns:
78
+ File import information dictionary
79
+ """
80
+ try:
81
+ config = import_config or {}
82
+ file_import = self.file_imports_service.FileImport.create(
83
+ connection_rid=connection_rid,
84
+ source_path=source_path,
85
+ target_dataset_rid=target_dataset_rid,
86
+ **config,
87
+ )
88
+ return self._format_import_info(file_import)
89
+ except Exception as e:
90
+ raise RuntimeError(
91
+ f"Failed to create file import from {connection_rid}:{source_path}: {e}"
92
+ )
93
+
94
+ def get_file_import(self, import_rid: str) -> Dict[str, Any]:
95
+ """
96
+ Get information about a specific file import.
97
+
98
+ Args:
99
+ import_rid: File import Resource Identifier
100
+
101
+ Returns:
102
+ File import information dictionary
103
+ """
104
+ try:
105
+ file_import = self.file_imports_service.FileImport.get(import_rid)
106
+ return self._format_import_info(file_import)
107
+ except Exception as e:
108
+ raise RuntimeError(f"Failed to get file import {import_rid}: {e}")
109
+
110
+ def execute_file_import(self, import_rid: str) -> Dict[str, Any]:
111
+ """
112
+ Execute a file import.
113
+
114
+ Args:
115
+ import_rid: File import Resource Identifier
116
+
117
+ Returns:
118
+ Execution result information
119
+ """
120
+ try:
121
+ result = self.file_imports_service.FileImport.execute(import_rid)
122
+ return self._format_execution_result(result)
123
+ except Exception as e:
124
+ raise RuntimeError(f"Failed to execute file import {import_rid}: {e}")
125
+
126
+ def create_table_import(
127
+ self,
128
+ connection_rid: str,
129
+ source_table: str,
130
+ target_dataset_rid: str,
131
+ import_config: Optional[Dict[str, Any]] = None,
132
+ ) -> Dict[str, Any]:
133
+ """
134
+ Create a table import via connection.
135
+
136
+ Args:
137
+ connection_rid: Connection Resource Identifier
138
+ source_table: Source table name in the connection
139
+ target_dataset_rid: Target dataset RID
140
+ import_config: Optional import configuration
141
+
142
+ Returns:
143
+ Table import information dictionary
144
+ """
145
+ try:
146
+ config = import_config or {}
147
+ table_import = self.table_imports_service.TableImport.create(
148
+ connection_rid=connection_rid,
149
+ source_table=source_table,
150
+ target_dataset_rid=target_dataset_rid,
151
+ **config,
152
+ )
153
+ return self._format_import_info(table_import)
154
+ except Exception as e:
155
+ raise RuntimeError(
156
+ f"Failed to create table import from {connection_rid}:{source_table}: {e}"
157
+ )
158
+
159
+ def get_table_import(self, import_rid: str) -> Dict[str, Any]:
160
+ """
161
+ Get information about a specific table import.
162
+
163
+ Args:
164
+ import_rid: Table import Resource Identifier
165
+
166
+ Returns:
167
+ Table import information dictionary
168
+ """
169
+ try:
170
+ table_import = self.table_imports_service.TableImport.get(import_rid)
171
+ return self._format_import_info(table_import)
172
+ except Exception as e:
173
+ raise RuntimeError(f"Failed to get table import {import_rid}: {e}")
174
+
175
+ def execute_table_import(self, import_rid: str) -> Dict[str, Any]:
176
+ """
177
+ Execute a table import.
178
+
179
+ Args:
180
+ import_rid: Table import Resource Identifier
181
+
182
+ Returns:
183
+ Execution result information
184
+ """
185
+ try:
186
+ result = self.table_imports_service.TableImport.execute(import_rid)
187
+ return self._format_execution_result(result)
188
+ except Exception as e:
189
+ raise RuntimeError(f"Failed to execute table import {import_rid}: {e}")
190
+
191
+ def list_file_imports(
192
+ self, connection_rid: Optional[str] = None
193
+ ) -> List[Dict[str, Any]]:
194
+ """
195
+ List file imports, optionally filtered by connection.
196
+
197
+ Args:
198
+ connection_rid: Optional connection RID to filter by
199
+
200
+ Returns:
201
+ List of file import information dictionaries
202
+ """
203
+ try:
204
+ if connection_rid:
205
+ imports = self.file_imports_service.FileImport.list(
206
+ connection_rid=connection_rid
207
+ )
208
+ else:
209
+ imports = self.file_imports_service.FileImport.list()
210
+ return [self._format_import_info(imp) for imp in imports]
211
+ except Exception as e:
212
+ raise RuntimeError(f"Failed to list file imports: {e}")
213
+
214
+ def list_table_imports(
215
+ self, connection_rid: Optional[str] = None
216
+ ) -> List[Dict[str, Any]]:
217
+ """
218
+ List table imports, optionally filtered by connection.
219
+
220
+ Args:
221
+ connection_rid: Optional connection RID to filter by
222
+
223
+ Returns:
224
+ List of table import information dictionaries
225
+ """
226
+ try:
227
+ if connection_rid:
228
+ imports = self.table_imports_service.TableImport.list(
229
+ connection_rid=connection_rid
230
+ )
231
+ else:
232
+ imports = self.table_imports_service.TableImport.list()
233
+ return [self._format_import_info(imp) for imp in imports]
234
+ except Exception as e:
235
+ raise RuntimeError(f"Failed to list table imports: {e}")
236
+
237
+ def _format_connection_info(self, connection: Any) -> Dict[str, Any]:
238
+ """
239
+ Format connection information for display.
240
+
241
+ Args:
242
+ connection: Connection object from SDK
243
+
244
+ Returns:
245
+ Formatted connection dictionary
246
+ """
247
+ try:
248
+ return {
249
+ "rid": getattr(connection, "rid", "N/A"),
250
+ "display_name": getattr(connection, "display_name", "N/A"),
251
+ "description": getattr(connection, "description", ""),
252
+ "connection_type": getattr(connection, "connection_type", "N/A"),
253
+ "status": getattr(connection, "status", "N/A"),
254
+ "created_time": getattr(connection, "created_time", "N/A"),
255
+ "modified_time": getattr(connection, "modified_time", "N/A"),
256
+ }
257
+ except Exception:
258
+ return {"raw": str(connection)}
259
+
260
+ def _format_import_info(self, import_obj: Any) -> Dict[str, Any]:
261
+ """
262
+ Format import information for display.
263
+
264
+ Args:
265
+ import_obj: Import object from SDK
266
+
267
+ Returns:
268
+ Formatted import dictionary
269
+ """
270
+ try:
271
+ return {
272
+ "rid": getattr(import_obj, "rid", "N/A"),
273
+ "display_name": getattr(import_obj, "display_name", "N/A"),
274
+ "connection_rid": getattr(import_obj, "connection_rid", "N/A"),
275
+ "target_dataset_rid": getattr(import_obj, "target_dataset_rid", "N/A"),
276
+ "status": getattr(import_obj, "status", "N/A"),
277
+ "import_type": getattr(import_obj, "import_type", "N/A"),
278
+ "source": getattr(import_obj, "source", "N/A"),
279
+ "created_time": getattr(import_obj, "created_time", "N/A"),
280
+ "modified_time": getattr(import_obj, "modified_time", "N/A"),
281
+ }
282
+ except Exception:
283
+ return {"raw": str(import_obj)}
284
+
285
+ def _format_execution_result(self, result: Any) -> Dict[str, Any]:
286
+ """
287
+ Format execution result for display.
288
+
289
+ Args:
290
+ result: Execution result object from SDK
291
+
292
+ Returns:
293
+ Formatted result dictionary
294
+ """
295
+ try:
296
+ return {
297
+ "execution_rid": getattr(result, "execution_rid", "N/A"),
298
+ "status": getattr(result, "status", "N/A"),
299
+ "started_time": getattr(result, "started_time", "N/A"),
300
+ "completed_time": getattr(result, "completed_time", ""),
301
+ "records_processed": getattr(result, "records_processed", 0),
302
+ "errors": getattr(result, "errors", []),
303
+ }
304
+ except Exception:
305
+ return {"raw": str(result)}