From 77d10c1bf50171c04585df1e0be7cfd058430f94 Mon Sep 17 00:00:00 2001 From: John Davis Date: Tue, 26 Sep 2023 13:23:53 -0400 Subject: [PATCH] Account for shared usage between TS and galaxy apps --- lib/galaxy/managers/api_keys.py | 16 ++++++---------- 1 file changed, 6 insertions(+), 10 deletions(-) diff --git a/lib/galaxy/managers/api_keys.py b/lib/galaxy/managers/api_keys.py index cf36c58fa1c1..dbc5121670a2 100644 --- a/lib/galaxy/managers/api_keys.py +++ b/lib/galaxy/managers/api_keys.py @@ -1,15 +1,9 @@ -from typing import Optional - from sqlalchemy import ( false, select, update, ) -from galaxy.model import ( - APIKeys, - User, -) from galaxy.model.base import transaction from galaxy.structured_app import BasicSharedApp @@ -19,11 +13,12 @@ def __init__(self, app: BasicSharedApp): self.app = app self.session = self.app.model.context - def get_api_key(self, user: User) -> Optional["APIKeys"]: + def get_api_key(self, user): + APIKeys = self.app.model.APIKeys stmt = select(APIKeys).filter_by(user_id=user.id, deleted=False).order_by(APIKeys.create_time.desc()).limit(1) return self.session.scalars(stmt).first() - def create_api_key(self, user: User) -> "APIKeys": + def create_api_key(self, user): guid = self.app.security.get_new_guid() new_key = self.app.model.APIKeys() new_key.user_id = user.id @@ -33,7 +28,7 @@ def create_api_key(self, user: User) -> "APIKeys": self.session.commit() return new_key - def get_or_create_api_key(self, user: User) -> str: + def get_or_create_api_key(self, user) -> str: # Logic Galaxy has always used - but it would appear to have a race # condition. Worth fixing? Would kind of need a message queue to fix # in multiple process mode. @@ -41,7 +36,7 @@ def get_or_create_api_key(self, user: User) -> str: key = api_key.key if api_key else self.create_api_key(user).key return key - def delete_api_key(self, user: User) -> None: + def delete_api_key(self, user) -> None: """Marks the current user API key as deleted.""" # Before it was possible to create multiple API keys for the same user although they were not considered valid # So all non-deleted keys are marked as deleted for backward compatibility @@ -50,6 +45,7 @@ def delete_api_key(self, user: User) -> None: self.session.commit() def _mark_all_api_keys_as_deleted(self, user_id: int): + APIKeys = self.app.model.APIKeys stmt = ( update(APIKeys) .where(APIKeys.user_id == user_id)