3
3
import logging
4
4
import os
5
5
import time
6
+ import warnings
6
7
from typing import Any , Dict , List , Optional , Tuple
7
8
from urllib .parse import urlparse
8
9
@@ -65,7 +66,7 @@ def create_session(self, name: str, dbid: str, pwd: str, memory: SessionMemoryVa
65
66
json = {"name" : name , "instance_id" : dbid , "password" : pwd , "memory" : memory .value },
66
67
)
67
68
68
- self ._check_code (response )
69
+ self ._check_resp (response )
69
70
70
71
return SessionDetails .fromJson (response .json ())
71
72
@@ -77,7 +78,7 @@ def list_session(self, session_id: str, dbid: str) -> Optional[SessionDetails]:
77
78
if response .status_code == 404 :
78
79
return None
79
80
80
- self ._check_code (response )
81
+ self ._check_resp (response )
81
82
82
83
return SessionDetails .fromJson (response .json ())
83
84
@@ -86,7 +87,7 @@ def list_sessions(self, dbid: str) -> List[SessionDetails]:
86
87
f"{ self ._base_uri } /v1beta5/data-science/sessions?instanceId={ dbid } " ,
87
88
)
88
89
89
- self ._check_code (response )
90
+ self ._check_resp (response )
90
91
91
92
return [SessionDetails .fromJson (s ) for s in response .json ()]
92
93
@@ -125,12 +126,13 @@ def delete_session(self, session_id: str, dbid: str) -> bool:
125
126
json = {"instance_id" : dbid },
126
127
)
127
128
129
+ self ._check_endpoint_expiry (response )
130
+
128
131
if response .status_code == 404 :
129
132
return False
130
133
elif response .status_code == 202 :
131
134
return True
132
-
133
- self ._check_code (response )
135
+ self ._check_endpoint_expiry (response )
134
136
135
137
return False
136
138
@@ -151,7 +153,7 @@ def create_instance(
151
153
152
154
response = self ._request_session .post (f"{ self ._base_uri } /v1/instances" , json = data )
153
155
154
- self ._check_code (response )
156
+ self ._check_resp (response )
155
157
156
158
return InstanceCreateDetails .from_json (response .json ()["data" ])
157
159
@@ -161,14 +163,14 @@ def delete_instance(self, instance_id: str) -> Optional[InstanceSpecificDetails]
161
163
if response .status_code == 404 :
162
164
return None
163
165
164
- self ._check_code (response )
166
+ self ._check_resp (response )
165
167
166
168
return InstanceSpecificDetails .fromJson (response .json ()["data" ])
167
169
168
170
def list_instances (self ) -> List [InstanceDetails ]:
169
171
response = self ._request_session .get (f"{ self ._base_uri } /v1/instances" , params = {"tenantId" : self ._tenant_id })
170
172
171
- self ._check_code (response )
173
+ self ._check_resp (response )
172
174
173
175
raw_data = response .json ()["data" ]
174
176
@@ -180,7 +182,7 @@ def list_instance(self, instance_id: str) -> Optional[InstanceSpecificDetails]:
180
182
if response .status_code == 404 :
181
183
return None
182
184
183
- self ._check_code (response )
185
+ self ._check_resp (response )
184
186
185
187
raw_data = response .json ()["data" ]
186
188
@@ -221,13 +223,13 @@ def estimate_size(
221
223
}
222
224
223
225
response = self ._request_session .post (f"{ self ._base_uri } /v1/instances/sizing" , json = data )
224
- self ._check_code (response )
226
+ self ._check_resp (response )
225
227
226
228
return EstimationDetails .from_json (response .json ()["data" ])
227
229
228
230
def _get_tenant_id (self ) -> str :
229
231
response = self ._request_session .get (f"{ self ._base_uri } /v1/tenants" )
230
- self ._check_code (response )
232
+ self ._check_resp (response )
231
233
232
234
raw_data = response .json ()["data" ]
233
235
@@ -242,17 +244,30 @@ def _get_tenant_id(self) -> str:
242
244
def tenant_details (self ) -> TenantDetails :
243
245
if not self ._tenant_details :
244
246
response = self ._request_session .get (f"{ self ._base_uri } /v1/tenants/{ self ._tenant_id } " )
245
- self ._check_code (response )
247
+ self ._check_resp (response )
246
248
self ._tenant_details = TenantDetails .from_json (response .json ()["data" ])
247
249
return self ._tenant_details
248
250
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 :
250
256
if resp .status_code >= 400 :
251
257
raise AuraApiError (
252
258
f"Request for { resp .url } failed with status code { resp .status_code } - { resp .reason } : { resp .text } " ,
253
259
status_code = resp .status_code ,
254
260
)
255
261
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
+
256
271
def _instance_type (self ) -> str :
257
272
return "enterprise-ds" if not self ._dev_env else "professional-ds"
258
273
0 commit comments