-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: implement session/client handling for search API #258
- Loading branch information
1 parent
210c5fe
commit 46a1539
Showing
1 changed file
with
32 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |