Skip to content

Commit

Permalink
#135: Add config option for whether certs for ICAT
Browse files Browse the repository at this point in the history
- Moved the client object into the constructor so it can be accessed by all functions in the class, though this might mean a session ID becomes useless?
  • Loading branch information
MRichards99 committed Jun 19, 2020
1 parent 9755e0b commit 93d2305
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 3 deletions.
9 changes: 9 additions & 0 deletions common/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,15 @@ def get_icat_url(self):
except:
sys.exit("Missing config value, ICAT_URL")

def get_icat_check_cert(self):
try:
return self.config["icat_check_cert"]
except:
# This could be set to true if there's no value, and log a warning
# that no value has been found from the config - save app from
# exiting
sys.exit("Missing config value, icat_check_cert")

def get_log_level(self):
try:
return self.config["log_level"]
Expand Down
8 changes: 5 additions & 3 deletions common/python_icat_backend.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,17 @@ class PythonICATBackend(Backend):
"""
Class that contains functions to access and modify data in an ICAT database directly
"""

def __init__(self):
icat_server_url = config.get_icat_url()
self.client = icat.client.Client(icat_server_url, checkCert=config.get_icat_check_cert())

def login(self, credentials):
icat_server_url = config.get_icat_url()
client = icat.client.Client(icat_server_url, checkCert=False)
# Syntax for Python ICAT
login_details = {'username': credentials['username'], 'password': credentials['password']}

try:
session_id = client.login(credentials["mechanism"], login_details)
session_id = self.client.login(credentials["mechanism"], login_details)
return session_id
except ICATSessionError:
raise AuthenticationError("User credentials are incorrect")
Expand Down
1 change: 1 addition & 0 deletions config.json.example
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
"backend": "db",
"DB_URL": "mysql+pymysql://root:rootpw@localhost:13306/icatdb",
"ICAT_URL": "https://localhost.localdomain:8181",
"icat_check_cert": false,
"log_level": "WARN",
"debug_mode": false,
"generate_swagger": false,
Expand Down

0 comments on commit 93d2305

Please sign in to comment.