1010
1111import cads_api_client
1212
13- from . import catalogue , config , processing , profile
13+ from . import __version__ , catalogue , config , processing , profile
1414
1515
1616@attrs .define (slots = False )
@@ -69,11 +69,12 @@ def __attrs_post_init__(self) -> None:
6969 warnings .warn (str (exc ), UserWarning )
7070
7171 def _get_headers (self , key_is_mandatory : bool = True ) -> dict [str , str ]:
72- if self .key is None :
73- if key_is_mandatory :
74- raise ValueError ("The API key is needed to access this resource" )
75- return {}
76- return {"PRIVATE-TOKEN" : self .key }
72+ headers = {"User-Agent" : f"cads-api-client/{ __version__ } " }
73+ if self .key is not None :
74+ headers ["PRIVATE-TOKEN" ] = self .key
75+ elif key_is_mandatory :
76+ raise ValueError ("The API key is needed to access this resource" )
77+ return headers
7778
7879 @property
7980 def _retry_options (self ) -> dict [str , Any ]:
@@ -99,10 +100,10 @@ def _request_options(self) -> dict[str, Any]:
99100 }
100101
101102 def _get_request_kwargs (
102- self , mandatory_key : bool = True
103+ self , key_is_mandatory : bool = True
103104 ) -> processing .RequestKwargs :
104105 return processing .RequestKwargs (
105- headers = self ._get_headers (key_is_mandatory = mandatory_key ),
106+ headers = self ._get_headers (key_is_mandatory = key_is_mandatory ),
106107 session = self .session ,
107108 retry_options = self ._retry_options ,
108109 request_options = self ._request_options ,
@@ -116,7 +117,7 @@ def _get_request_kwargs(
116117 def _catalogue_api (self ) -> catalogue .Catalogue :
117118 return catalogue .Catalogue (
118119 f"{ self .url } /catalogue" ,
119- ** self ._get_request_kwargs (mandatory_key = False ),
120+ ** self ._get_request_kwargs (key_is_mandatory = False ),
120121 )
121122
122123 @functools .cached_property
0 commit comments