33import logging
44import os
55import time
6+ import warnings
67from typing import Any , Dict , List , Optional , Tuple
78from urllib .parse import urlparse
89
@@ -65,7 +66,7 @@ def create_session(self, name: str, dbid: str, pwd: str, memory: SessionMemoryVa
6566 json = {"name" : name , "instance_id" : dbid , "password" : pwd , "memory" : memory .value },
6667 )
6768
68- self ._check_code (response )
69+ self ._check_resp (response )
6970
7071 return SessionDetails .fromJson (response .json ())
7172
@@ -77,7 +78,7 @@ def list_session(self, session_id: str, dbid: str) -> Optional[SessionDetails]:
7778 if response .status_code == 404 :
7879 return None
7980
80- self ._check_code (response )
81+ self ._check_resp (response )
8182
8283 return SessionDetails .fromJson (response .json ())
8384
@@ -86,7 +87,7 @@ def list_sessions(self, dbid: str) -> List[SessionDetails]:
8687 f"{ self ._base_uri } /v1beta5/data-science/sessions?instanceId={ dbid } " ,
8788 )
8889
89- self ._check_code (response )
90+ self ._check_resp (response )
9091
9192 return [SessionDetails .fromJson (s ) for s in response .json ()]
9293
@@ -125,12 +126,13 @@ def delete_session(self, session_id: str, dbid: str) -> bool:
125126 json = {"instance_id" : dbid },
126127 )
127128
129+ self ._check_endpoint_expiry (response )
130+
128131 if response .status_code == 404 :
129132 return False
130133 elif response .status_code == 202 :
131134 return True
132-
133- self ._check_code (response )
135+ self ._check_endpoint_expiry (response )
134136
135137 return False
136138
@@ -151,7 +153,7 @@ def create_instance(
151153
152154 response = self ._request_session .post (f"{ self ._base_uri } /v1/instances" , json = data )
153155
154- self ._check_code (response )
156+ self ._check_resp (response )
155157
156158 return InstanceCreateDetails .from_json (response .json ()["data" ])
157159
@@ -161,14 +163,14 @@ def delete_instance(self, instance_id: str) -> Optional[InstanceSpecificDetails]
161163 if response .status_code == 404 :
162164 return None
163165
164- self ._check_code (response )
166+ self ._check_resp (response )
165167
166168 return InstanceSpecificDetails .fromJson (response .json ()["data" ])
167169
168170 def list_instances (self ) -> List [InstanceDetails ]:
169171 response = self ._request_session .get (f"{ self ._base_uri } /v1/instances" , params = {"tenantId" : self ._tenant_id })
170172
171- self ._check_code (response )
173+ self ._check_resp (response )
172174
173175 raw_data = response .json ()["data" ]
174176
@@ -180,7 +182,7 @@ def list_instance(self, instance_id: str) -> Optional[InstanceSpecificDetails]:
180182 if response .status_code == 404 :
181183 return None
182184
183- self ._check_code (response )
185+ self ._check_resp (response )
184186
185187 raw_data = response .json ()["data" ]
186188
@@ -221,13 +223,13 @@ def estimate_size(
221223 }
222224
223225 response = self ._request_session .post (f"{ self ._base_uri } /v1/instances/sizing" , json = data )
224- self ._check_code (response )
226+ self ._check_resp (response )
225227
226228 return EstimationDetails .from_json (response .json ()["data" ])
227229
228230 def _get_tenant_id (self ) -> str :
229231 response = self ._request_session .get (f"{ self ._base_uri } /v1/tenants" )
230- self ._check_code (response )
232+ self ._check_resp (response )
231233
232234 raw_data = response .json ()["data" ]
233235
@@ -242,17 +244,30 @@ def _get_tenant_id(self) -> str:
242244 def tenant_details (self ) -> TenantDetails :
243245 if not self ._tenant_details :
244246 response = self ._request_session .get (f"{ self ._base_uri } /v1/tenants/{ self ._tenant_id } " )
245- self ._check_code (response )
247+ self ._check_resp (response )
246248 self ._tenant_details = TenantDetails .from_json (response .json ()["data" ])
247249 return self ._tenant_details
248250
249- def _check_code (self , resp : requests .Response ) -> None :
251+ def _check_resp (self , resp : requests .Response ) -> None :
252+ self ._check_status_code (resp )
253+ self ._check_endpoint_expiry (resp )
254+
255+ def _check_status_code (self , resp : requests .Response ) -> None :
250256 if resp .status_code >= 400 :
251257 raise AuraApiError (
252258 f"Request for { resp .url } failed with status code { resp .status_code } - { resp .reason } : { resp .text } " ,
253259 status_code = resp .status_code ,
254260 )
255261
262+ def _check_endpoint_expiry (self , resp : requests .Response ) -> None :
263+ expiry_date = resp .headers .get ("X-Tyk-Api-Expires" )
264+ if expiry_date :
265+ warnings .warn (
266+ f"The endpoint is deprecated and will be removed on { expiry_date } ."
267+ " Please update to a newer version of this client." ,
268+ DeprecationWarning ,
269+ )
270+
256271 def _instance_type (self ) -> str :
257272 return "enterprise-ds" if not self ._dev_env else "professional-ds"
258273
0 commit comments