@@ -71,7 +71,6 @@ class Permission(str, Enum):
7171 # transactions
7272 RUN_TRANSACTION = "run:transaction"
7373 READ_TRANSACTION = "read:transaction"
74- DELETE_TRANSACTION = "delete:transaction"
7574 # credits
7675 READ_CREDITS_USAGE = "read:credits_usage"
7776 # oauth clients
@@ -109,7 +108,6 @@ class Permission(str, Enum):
109108 "delete_database" ,
110109 "delete_engine" ,
111110 "delete_model" ,
112- "delete_transaction" ,
113111 "disable_user" ,
114112 "enable_user" ,
115113 "delete_oauth_client" ,
@@ -120,6 +118,7 @@ class Permission(str, Enum):
120118 "get_transaction" ,
121119 "get_transaction_metadata" ,
122120 "get_transaction_results" ,
121+ "cancel_transaction" ,
123122 "get_user" ,
124123 "list_databases" ,
125124 "list_edbs" ,
@@ -130,6 +129,7 @@ class Permission(str, Enum):
130129 "load_csv" ,
131130 "update_user" ,
132131 "query" ,
132+ "query_async" ,
133133]
134134
135135
@@ -163,7 +163,7 @@ def _get_resource(ctx: Context, path: str, key=None, **kwargs) -> dict:
163163
164164
165165# Retrieve a generic collection of resources.
166- def _list_collection (ctx , path : str , key = None , ** kwargs ):
166+ def _get_collection (ctx , path : str , key = None , ** kwargs ):
167167 rsp = rest .get (ctx , _mkurl (ctx , path ), ** kwargs )
168168 rsp = json .loads (rsp .read ())
169169 return rsp [key ] if key else rsp
@@ -248,12 +248,6 @@ def delete_engine(ctx: Context, engine: str) -> dict:
248248 return json .loads (rsp .read ())
249249
250250
251- def delete_transaction (ctx : Context , id : str ) -> dict :
252- url = _mkurl (ctx , f"{ PATH_TRANSACTIONS } /{ id } " )
253- rsp = rest .delete (ctx , url , None )
254- return json .loads (rsp .read ())
255-
256-
257251def delete_user (ctx : Context , id : str ) -> dict :
258252 url = _mkurl (ctx , f"{ PATH_USER } /{ id } " )
259253 rsp = rest .delete (ctx , url , None )
@@ -291,7 +285,15 @@ def get_transaction(ctx: Context, id: str) -> dict:
291285
292286
293287def get_transaction_metadata (ctx : Context , id : str ) -> dict :
294- return _get_resource (ctx , f"{ PATH_TRANSACTIONS } /{ id } /metadata" )
288+ return _get_collection (ctx , f"{ PATH_TRANSACTIONS } /{ id } /metadata" )
289+
290+
291+ def list_transactions (ctx : Context ) -> list :
292+ return _get_collection (ctx , PATH_TRANSACTIONS , key = "transactions" )
293+
294+
295+ def get_transaction_problems (ctx : Context , id : str ) -> dict :
296+ return _get_collection (ctx , f"{ PATH_TRANSACTIONS } /{ id } /problems" )
295297
296298
297299def get_transaction_results (ctx : Context , id : str ) -> list :
@@ -303,6 +305,11 @@ def get_transaction_results(ctx: Context, id: str) -> list:
303305 return _parse_multipart (content_type , rsp .read ())
304306
305307
308+ def cancel_transaction (ctx : Context , id : str ) -> dict :
309+ rsp = rest .post (ctx , _mkurl (ctx , f"{ PATH_TRANSACTIONS } /{ id } /cancel" ), {})
310+ return json .loads (rsp .read ())
311+
312+
306313def get_user (ctx : Context , userid : str ) -> dict :
307314 return _get_resource (ctx , f"{ PATH_USER } /{ userid } " , name = userid )
308315
@@ -311,22 +318,22 @@ def list_engines(ctx: Context, state=None) -> list:
311318 kwargs = {}
312319 if state is not None :
313320 kwargs ["state" ] = state
314- return _list_collection (ctx , PATH_ENGINE , key = "computes" , ** kwargs )
321+ return _get_collection (ctx , PATH_ENGINE , key = "computes" , ** kwargs )
315322
316323
317324def list_databases (ctx : Context , state = None ) -> list :
318325 kwargs = {}
319326 if state is not None :
320327 kwargs ["state" ] = state
321- return _list_collection (ctx , PATH_DATABASE , key = "databases" , ** kwargs )
328+ return _get_collection (ctx , PATH_DATABASE , key = "databases" , ** kwargs )
322329
323330
324331def list_users (ctx : Context ) -> list :
325- return _list_collection (ctx , PATH_USER , key = "users" )
332+ return _get_collection (ctx , PATH_USER , key = "users" )
326333
327334
328335def list_oauth_clients (ctx : Context ) -> list :
329- return _list_collection (ctx , PATH_OAUTH_CLIENT , key = "clients" )
336+ return _get_collection (ctx , PATH_OAUTH_CLIENT , key = "clients" )
330337
331338
332339def update_user (ctx : Context , userid : str , status : str = None , roles = None ):
@@ -340,9 +347,6 @@ def update_user(ctx: Context, userid: str, status: str = None, roles=None):
340347 return json .loads (rsp .read ())
341348
342349
343- #
344- # Transaction endpoint
345- #
346350class Transaction (object ):
347351 def __init__ (self , database : str , engine : str , abort = False ,
348352 mode : Mode = Mode .OPEN , nowait_durable = False , readonly = False ,
@@ -398,23 +402,15 @@ def run(self, ctx: Context, *args) -> dict:
398402 return json .loads (rsp .read ())
399403
400404
401- #
402- # /transactions endpoint
403- #
404405class TransactionAsync (object ):
405- def __init__ (self , database : str , engine : str , command : str , nowait_durable = False , readonly = False ,
406- inputs : dict = None ):
406+ def __init__ (self , database : str , engine : str , nowait_durable = False , readonly = False ):
407407 self .database = database
408408 self .engine = engine
409- self .command = command
410409 self .nowait_durable = nowait_durable
411410 self .readonly = readonly
412- self .inputs = inputs
413411
414412 @property
415413 def data (self ):
416- inputs = self .inputs or {}
417- inputs = [_query_action_input (k , v ) for k , v in inputs .items ()]
418414 result = {
419415 "dbname" : self .database ,
420416 "nowait_durable" : self .nowait_durable ,
@@ -423,16 +419,18 @@ def data(self):
423419 }
424420 if self .engine is not None :
425421 result ["engine_name" ] = self .engine
426- result ["query" ] = self .command
427- result ["inputs" ] = inputs
428422 return result
429423
430- def run (self , ctx : Context ) -> Union [dict , list ]:
424+ def run (self , ctx : Context , command : str , inputs : dict = None ) -> Union [dict , list ]:
431425 data = self .data
432- url = _mkurl (ctx , PATH_TRANSACTIONS )
433- rsp = rest .post (ctx , url , data )
426+ data ["query" ] = command
427+ if not inputs is None :
428+ inputs = [_query_action_input (k , v ) for k , v in inputs .items ()]
429+ data ["v1_inputs" ] = inputs
430+ rsp = rest .post (ctx , _mkurl (ctx , PATH_TRANSACTIONS ), data )
434431 content_type = rsp .headers .get ('content-type' , None )
435432 content = rsp .read ()
433+ # todo: response model should be based on status code (200 v. 201)
436434 # async mode
437435 if content_type .lower () == "application/json" :
438436 return json .loads (content )
@@ -660,8 +658,8 @@ def query(ctx: Context, database: str, engine: str, command: str,
660658
661659def query_async (ctx : Context , database : str , engine : str , command : str ,
662660 readonly : bool = True , inputs : dict = None ) -> Union [dict , list ]:
663- tx = TransactionAsync (database , engine , command , readonly = readonly , inputs = inputs )
664- return tx .run (ctx )
661+ tx = TransactionAsync (database , engine , readonly = readonly )
662+ return tx .run (ctx , command , inputs = inputs )
665663
666664
667665create_compute = create_engine # deprecated, use create_engine
0 commit comments