Skip to content

Commit

Permalink
feat: add configuration option to set authenticator and its credentia…
Browse files Browse the repository at this point in the history
…ls in the search API #350

BREAKING CHANGE: This commits adds a mandatory config option, so is a major change.
  • Loading branch information
antolinos authored and MRichards99 committed Mar 29, 2022
1 parent fdd511f commit 1c30f2f
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 4 deletions.
5 changes: 4 additions & 1 deletion datagateway_api/config.json.example
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,10 @@
"search_api": {
"extension": "/search-api",
"icat_url": "https://localhost:8181",
"icat_check_cert": false
"icat_check_cert": false,
"plugin": "anon",
"username": "",
"password": ""
},
"flask_reloader": false,
"log_level": "WARN",
Expand Down
3 changes: 3 additions & 0 deletions datagateway_api/src/common/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,9 @@ class SearchAPI(BaseModel):
extension: StrictStr
icat_check_cert: StrictBool
icat_url: StrictStr
plugin: StrictStr
username: StrictStr
password: StrictStr

_validate_extension = validator("extension", allow_reuse=True)(validate_extension)

Expand Down
5 changes: 2 additions & 3 deletions datagateway_api/src/search_api/session_handler.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from functools import wraps
import logging

from datagateway_api.src.common.config import Config
from icat.exception import ICATSessionError

from datagateway_api.src.datagateway_api.icat.icat_client_pool import ICATClient
Expand Down Expand Up @@ -33,8 +33,7 @@ def wrapper_client_manager(*args, **kwargs):
SessionHandler.client.getRemainingMinutes()
except ICATSessionError as e:
log.debug("Current client session expired: %s", e.args)
SessionHandler.client.login("anon", {})

SessionHandler.client.login(Config.config.search_api.plugin, {"username": Config.config.search_api.username, "password" : Config.config.search_api.password})
return method(*args, **kwargs)

return wrapper_client_manager

0 comments on commit 1c30f2f

Please sign in to comment.