Skip to content

Commit

Permalink
feat: implement session/client handling for search API #258
Browse files Browse the repository at this point in the history
  • Loading branch information
MRichards99 committed Nov 24, 2021
1 parent 210c5fe commit 46a1539
Showing 1 changed file with 32 additions and 12 deletions.
44 changes: 32 additions & 12 deletions datagateway_api/src/search_api/session_handler.py
Original file line number Diff line number Diff line change
@@ -1,20 +1,40 @@
# TODO - can we enforce a singleton pattern on the class?
class SessionHandler:
def __init__(self):
self.client = None
self.session_id = None
from functools import wraps
import logging

from icat.exception import ICATSessionError

from datagateway_api.src.datagateway_api.icat.icat_client_pool import ICATClient

log = logging.getLogger()

def requires_session_id(method):

class SessionHandler:
"""
Class to store Python ICAT client to be used within the search API. As the API
requires no authentication, the same client object can be used which logs in as the
anon user
"""
TODO

client = ICATClient()


def client_manager(method):
"""
pass
Decorator to manage the client object at the beginning of each request. This
decorator checks if the client has a valid session, and if not, logs in as the anon
user
:param method: The function used to process an incoming request
"""

@wraps(method)
def wrapper_requires_session(*args, **kwargs):
pass
def wrapper_client_manager(*args, **kwargs):
try:
SessionHandler.client.getRemainingMinutes()
except ICATSessionError as e:
log.debug("Current client session expired: %s", e)
SessionHandler.client.login("anon", {})

return wrapper_requires_session
"""
return method(*args, **kwargs)

return wrapper_client_manager

0 comments on commit 46a1539

Please sign in to comment.