Source code for galaxy.managers.api_keys

from typing import (

from galaxy.model import User
from galaxy.structured_app import BasicSharedApp

    from galaxy.model import APIKeys

[docs]class ApiKeyManager:
[docs] def __init__(self, app: BasicSharedApp): = app
[docs] def get_api_key(self, user: User) -> Optional["APIKeys"]: sa_session = api_key = ( sa_session.query( .filter_by(, deleted=False) .order_by( .first() ) return api_key
[docs] def create_api_key(self, user: User) -> "APIKeys": guid = new_key = new_key.user_id = new_key.key = guid sa_session = sa_session.add(new_key) sa_session.flush() return new_key
[docs] def get_or_create_api_key(self, user: 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. api_key = self.get_api_key(user) key = api_key.key if api_key else self.create_api_key(user).key return key
[docs] def delete_api_key(self, user: User) -> None: """Marks the current user API key as deleted.""" sa_session = # 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 api_keys = sa_session.query(, deleted=False) for api_key in api_keys: api_key.deleted = True sa_session.add(api_key) sa_session.flush()