@@ -150,9 +150,6 @@ def get_session():
150
150
151
151
152
152
class AtlanClient (BaseSettings ):
153
- _current_client_ctx : ClassVar [ContextVar ] = ContextVar (
154
- "_current_client_ctx" , default = None
155
- )
156
153
_401_has_retried_ctx : ClassVar [ContextVar ] = ContextVar (
157
154
"_401_has_retried_ctx" , default = False
158
155
)
@@ -195,25 +192,6 @@ class AtlanClient(BaseSettings):
195
192
class Config :
196
193
env_prefix = "atlan_"
197
194
198
- @classmethod
199
- def set_current_client (cls , client : AtlanClient ):
200
- """
201
- Sets the current client context
202
- """
203
- if not isinstance (client , AtlanClient ):
204
- raise ErrorCode .MISSING_ATLAN_CLIENT .exception_with_parameters ()
205
- cls ._current_client_ctx .set (client )
206
-
207
- @classmethod
208
- def get_current_client (cls ) -> AtlanClient :
209
- """
210
- Retrieves the current client context
211
- """
212
- client = cls ._current_client_ctx .get ()
213
- if not client :
214
- raise ErrorCode .NO_ATLAN_CLIENT_AVAILABLE .exception_with_parameters ()
215
- return client
216
-
217
195
def __init__ (self , ** data ):
218
196
super ().__init__ (** data )
219
197
self ._request_params = {
@@ -225,188 +203,161 @@ def __init__(self, **data):
225
203
adapter = HTTPAdapter (max_retries = self .retry )
226
204
session .mount (HTTPS_PREFIX , adapter )
227
205
session .mount (HTTP_PREFIX , adapter )
228
- AtlanClient .set_current_client (self )
229
206
self ._401_has_retried_ctx .set (False )
230
207
231
208
@property
232
209
def admin (self ) -> AdminClient :
233
210
if self ._admin_client is None :
234
- AtlanClient .set_current_client (self )
235
211
self ._admin_client = AdminClient (client = self )
236
212
return self ._admin_client
237
213
238
214
@property
239
215
def audit (self ) -> AuditClient :
240
216
if self ._audit_client is None :
241
- AtlanClient .set_current_client (self )
242
217
self ._audit_client = AuditClient (client = self )
243
218
return self ._audit_client
244
219
245
220
@property
246
221
def search_log (self ) -> SearchLogClient :
247
222
if self ._search_log_client is None :
248
- AtlanClient .set_current_client (self )
249
223
self ._search_log_client = SearchLogClient (client = self )
250
224
return self ._search_log_client
251
225
252
226
@property
253
227
def workflow (self ) -> WorkflowClient :
254
228
if self ._workflow_client is None :
255
- AtlanClient .set_current_client (self )
256
229
self ._workflow_client = WorkflowClient (client = self )
257
230
return self ._workflow_client
258
231
259
232
@property
260
233
def credentials (self ) -> CredentialClient :
261
234
if self ._credential_client is None :
262
- AtlanClient .set_current_client (self )
263
235
self ._credential_client = CredentialClient (client = self )
264
236
return self ._credential_client
265
237
266
238
@property
267
239
def group (self ) -> GroupClient :
268
240
if self ._group_client is None :
269
- AtlanClient .set_current_client (self )
270
241
self ._group_client = GroupClient (client = self )
271
242
return self ._group_client
272
243
273
244
@property
274
245
def role (self ) -> RoleClient :
275
246
if self ._role_client is None :
276
- AtlanClient .set_current_client (self )
277
247
self ._role_client = RoleClient (client = self )
278
248
return self ._role_client
279
249
280
250
@property
281
251
def asset (self ) -> AssetClient :
282
252
if self ._asset_client is None :
283
- AtlanClient .set_current_client (self )
284
253
self ._asset_client = AssetClient (client = self )
285
254
return self ._asset_client
286
255
287
256
@property
288
257
def impersonate (self ) -> ImpersonationClient :
289
258
if self ._impersonate_client is None :
290
- AtlanClient .set_current_client (self )
291
259
self ._impersonate_client = ImpersonationClient (client = self )
292
260
return self ._impersonate_client
293
261
294
262
@property
295
263
def queries (self ) -> QueryClient :
296
264
if self ._query_client is None :
297
- AtlanClient .set_current_client (self )
298
265
self ._query_client = QueryClient (client = self )
299
266
return self ._query_client
300
267
301
268
@property
302
269
def token (self ) -> TokenClient :
303
270
if self ._token_client is None :
304
- AtlanClient .set_current_client (self )
305
271
self ._token_client = TokenClient (client = self )
306
272
return self ._token_client
307
273
308
274
@property
309
275
def typedef (self ) -> TypeDefClient :
310
276
if self ._typedef_client is None :
311
- AtlanClient .set_current_client (self )
312
277
self ._typedef_client = TypeDefClient (client = self )
313
278
return self ._typedef_client
314
279
315
280
@property
316
281
def user (self ) -> UserClient :
317
282
if self ._user_client is None :
318
- AtlanClient .set_current_client (self )
319
283
self ._user_client = UserClient (client = self )
320
284
return self ._user_client
321
285
322
286
@property
323
287
def tasks (self ) -> TaskClient :
324
288
if self ._task_client is None :
325
- AtlanClient .set_current_client (self )
326
289
self ._task_client = TaskClient (client = self )
327
290
return self ._task_client
328
291
329
292
@property
330
293
def sso (self ) -> SSOClient :
331
294
if self ._sso_client is None :
332
- AtlanClient .set_current_client (self )
333
295
self ._sso_client = SSOClient (client = self )
334
296
return self ._sso_client
335
297
336
298
@property
337
299
def open_lineage (self ) -> OpenLineageClient :
338
300
if self ._open_lineage_client is None :
339
- AtlanClient .set_current_client (self )
340
301
self ._open_lineage_client = OpenLineageClient (client = self )
341
302
return self ._open_lineage_client
342
303
343
304
@property
344
305
def files (self ) -> FileClient :
345
306
if self ._file_client is None :
346
- AtlanClient .set_current_client (self )
347
307
self ._file_client = FileClient (client = self )
348
308
return self ._file_client
349
309
350
310
@property
351
311
def contracts (self ) -> ContractClient :
352
312
if self ._contract_client is None :
353
- AtlanClient .set_current_client (self )
354
313
self ._contract_client = ContractClient (client = self )
355
314
return self ._contract_client
356
315
357
316
@property
358
317
def atlan_tag_cache (self ) -> AtlanTagCache :
359
318
if self ._atlan_tag_cache is None :
360
- AtlanClient .set_current_client (self )
361
319
self ._atlan_tag_cache = AtlanTagCache (client = self )
362
320
return self ._atlan_tag_cache
363
321
364
322
@property
365
323
def enum_cache (self ) -> EnumCache :
366
324
if self ._enum_cache is None :
367
- AtlanClient .set_current_client (self )
368
325
self ._enum_cache = EnumCache (client = self )
369
326
return self ._enum_cache
370
327
371
328
@property
372
329
def group_cache (self ) -> GroupCache :
373
330
if self ._group_cache is None :
374
- AtlanClient .set_current_client (self )
375
331
self ._group_cache = GroupCache (client = self )
376
332
return self ._group_cache
377
333
378
334
@property
379
335
def role_cache (self ) -> RoleCache :
380
336
if self ._role_cache is None :
381
- AtlanClient .set_current_client (self )
382
337
self ._role_cache = RoleCache (client = self )
383
338
return self ._role_cache
384
339
385
340
@property
386
341
def user_cache (self ) -> UserCache :
387
342
if self ._user_cache is None :
388
- AtlanClient .set_current_client (self )
389
343
self ._user_cache = UserCache (client = self )
390
344
return self ._user_cache
391
345
392
346
@property
393
347
def custom_metadata_cache (self ) -> CustomMetadataCache :
394
348
if self ._custom_metadata_cache is None :
395
- AtlanClient .set_current_client (self )
396
349
self ._custom_metadata_cache = CustomMetadataCache (client = self )
397
350
return self ._custom_metadata_cache
398
351
399
352
@property
400
353
def connection_cache (self ) -> ConnectionCache :
401
354
if self ._connection_cache is None :
402
- AtlanClient .set_current_client (self )
403
355
self ._connection_cache = ConnectionCache (client = self )
404
356
return self ._connection_cache
405
357
406
358
@property
407
359
def source_tag_cache (self ) -> SourceTagCache :
408
360
if self ._source_tag_cache is None :
409
- AtlanClient .set_current_client (self )
410
361
self ._source_tag_cache = SourceTagCache (client = self )
411
362
return self ._source_tag_cache
412
363
@@ -1845,31 +1796,29 @@ def max_retries(
1845
1796
1846
1797
@contextlib .contextmanager
1847
1798
def client_connection (
1799
+ client : AtlanClient ,
1848
1800
base_url : Optional [HttpUrl ] = None ,
1849
1801
api_key : Optional [str ] = None ,
1850
1802
connect_timeout : float = 30.0 ,
1851
1803
read_timeout : float = 120.0 ,
1852
1804
retry : Retry = DEFAULT_RETRY ,
1853
1805
) -> Generator [AtlanClient , None , None ]:
1854
1806
"""
1855
- Creates a new client created with the given base_url and/api_key. The AtlanClient.default_client will
1856
- be set to the new client. AtlanClient.default_client will be reset to the current default_client before
1857
- exiting the context.
1858
- :param base_url: the base_url to be used for the new connection. If not specified the current value will be used
1859
- :param api_key: the api_key to be used for the new connection. If not specified the current value will be used
1807
+ Creates a new client created with the given base_url and/api_key.
1808
+
1809
+ :param base_url: the base_url to be used for the new connection.
1810
+ If not specified the current value will be used
1811
+ :param api_key: the api_key to be used for the new connection.
1812
+ If not specified the current value will be used
1860
1813
"""
1861
- current_client = AtlanClient .get_current_client ()
1862
1814
tmp_client = AtlanClient (
1863
- base_url = base_url or current_client .base_url ,
1864
- api_key = api_key or current_client .api_key ,
1815
+ base_url = base_url or client .base_url ,
1816
+ api_key = api_key or client .api_key ,
1865
1817
connect_timeout = connect_timeout ,
1866
1818
read_timeout = read_timeout ,
1867
1819
retry = retry ,
1868
1820
)
1869
- try :
1870
- yield tmp_client
1871
- finally :
1872
- AtlanClient .set_current_client (current_client )
1821
+ yield tmp_client
1873
1822
1874
1823
1875
1824
from pyatlan .model .keycloak_events import ( # noqa: E402
0 commit comments