22
22
import logging
23
23
import os
24
24
25
+
25
26
import requests
26
27
27
- from pyatlan . client . index import IndexClient
28
+ from pydantic import BaseSettings , HttpUrl , PrivateAttr , Field
28
29
from pyatlan .exceptions import AtlanServiceException
29
- from pyatlan .utils import HTTPMethod , HTTPStatus , get_logger , type_coerce
30
+ from pyatlan .utils import HTTPMethod , HTTPStatus , get_logger
30
31
31
32
LOGGER = get_logger ()
32
33
33
34
34
- class AtlanClient :
35
- def __init__ (self , host , api_key ):
36
- self .session = requests .Session ()
37
- self .host = host
38
- self .request_params = {"headers" : {"authorization" : f"Bearer { api_key } " }}
39
- self .index_client = IndexClient (self )
35
+ class AtlanClient (BaseSettings ):
36
+ host : HttpUrl
37
+ api_key : str
38
+ session : requests .Session = Field (default_factory = requests .Session )
39
+ _request_params : dict = PrivateAttr ()
40
+
41
+ class Config :
42
+ env_prefix = "atlan_"
43
+
44
+ def __init__ (self , ** data ):
45
+ super ().__init__ (** data )
46
+ self ._request_params = {"headers" : {"authorization" : f"Bearer { self .api_key } " }}
40
47
41
48
def call_api (self , api , response_type = None , query_params = None , request_obj = None ):
42
- params = copy .deepcopy (self .request_params )
49
+ params = copy .deepcopy (self ._request_params )
43
50
path = os .path .join (self .host , api .path )
44
51
45
52
params ["headers" ]["Accept" ] = api .consumes
@@ -92,8 +99,12 @@ def call_api(self, api, response_type=None, query_params=None, request_obj=None)
92
99
LOGGER .debug (response .json ())
93
100
if response_type == str :
94
101
return json .dumps (response .json ())
95
-
96
- return type_coerce (response .json (), response_type )
102
+ with open (
103
+ "/Users/ernesthill/PycharmProjects/TypeDefAnalyzer/typedefs.json" ,
104
+ "w" ,
105
+ ) as outfile :
106
+ json .dump (response .json (), outfile )
107
+ return response_type (** response .json ())
97
108
except Exception as e :
98
109
print (e )
99
110
LOGGER .exception (
@@ -109,3 +120,8 @@ def call_api(self, api, response_type=None, query_params=None, request_obj=None)
109
120
return None
110
121
else :
111
122
raise AtlanServiceException (api , response )
123
+
124
+
125
+ if __name__ == "__main__" :
126
+ client = AtlanClient ()
127
+ print (client .dict ())
0 commit comments