66from typing import Callable , Optional
77
88# third party
9+ import requests
910import rudder_analytics
1011
1112# first party
1920class _Client (abc .ABC ):
2021 def __init__ (
2122 self ,
23+ session : requests .Session ,
2224 * ,
2325 api_key : str = None ,
2426 service_token : str = None ,
2527 host : str = None ,
2628 do_not_track : bool = False ,
29+ environment_id : int = None ,
30+ use_beta_endpoint : bool = True ,
2731 ):
28- self .api_key : Optional [str ] = api_key or os .getenv (' DBT_CLOUD_API_KEY' , None )
32+ self .api_key : Optional [str ] = api_key or os .getenv (" DBT_CLOUD_API_KEY" , None )
2933 self .service_token : Optional [str ] = service_token or os .getenv (
30- ' DBT_CLOUD_SERVICE_TOKEN' , None
34+ " DBT_CLOUD_SERVICE_TOKEN" , None
3135 )
3236 self ._host : Optional [str ] = host or os .getenv (
33- ' DBT_CLOUD_HOST' , self .DEFAULT_DOMAIN
37+ " DBT_CLOUD_HOST" , self .DEFAULT_DOMAIN
3438 )
39+ self .environment_id = environment_id or os .getenv (
40+ "DBT_CLOUD_ENVIRONMENT_ID" , None
41+ )
42+ self ._use_beta = use_beta_endpoint
3543 self .do_not_track : bool = do_not_track
3644 self ._anonymous_id : str = str (uuid .uuid4 ())
3745 self ._called_from : Optional [str ] = None
3846 self .console = err_console
47+ self .session = session
48+ self .session .headers = self .headers
3949
40- DEFAULT_DOMAIN = ' cloud.getdbt.com'
50+ DEFAULT_DOMAIN = " cloud.getdbt.com"
4151
4252 @property
4353 @abc .abstractmethod
@@ -51,29 +61,29 @@ def _header_property(self):
5161
5262 @property
5363 def _base_url (self ):
54- return f' https://{ self ._host } { self ._path } '
64+ return f" https://{ self ._host } { self ._path } "
5565
5666 @property
5767 def headers (self ):
5868 return {
59- ' Authorization' : f'Token { getattr (self , self ._header_property )} ' ,
60- ' Content-Type' : ' application/json' ,
69+ " Authorization" : f"Bearer { getattr (self , self ._header_property )} " ,
70+ " Content-Type" : " application/json" ,
6171 }
6272
6373 def full_url (self , path : str = None ):
6474 if path is not None :
65- return f' { self ._base_url } { path } '
75+ return f" { self ._base_url } { path } "
6676
6777 return self ._base_url
6878
6979 def _send_track (self , event_name : str , func : Callable , * args , ** kwargs ):
70- func_args = [a for a in inspect .getfullargspec (func ).args if a != ' self' ]
80+ func_args = [a for a in inspect .getfullargspec (func ).args if a != " self" ]
7181 properties = {
72- ' method' : func .__name__ ,
73- ' dbtc_version' : __version__ ,
74- ' called_from' : self ._called_from ,
82+ " method" : func .__name__ ,
83+ " dbtc_version" : __version__ ,
84+ " called_from" : self ._called_from ,
7585 ** dict (zip (func_args , args )),
7686 ** kwargs ,
7787 }
78- properties = {k : v for k , v in properties .items () if not k .endswith (' _id' )}
88+ properties = {k : v for k , v in properties .items () if not k .endswith (" _id" )}
7989 rudder_analytics .track (self ._anonymous_id , event_name , properties )
0 commit comments