Skip to content

Commit

Permalink
implementing server-side validation of package dir and existing reque…
Browse files Browse the repository at this point in the history
…st group names in test request submissions
  • Loading branch information
PhillipsOwen committed Mar 26, 2024
1 parent ab48e46 commit c5f0036
Show file tree
Hide file tree
Showing 3 changed files with 65 additions and 8 deletions.
24 changes: 20 additions & 4 deletions src/common/pg_impl.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ def __del__(self):

def get_environment_type_names(self):
"""
gets the test types
gets the test environment types
:return:
"""
Expand Down Expand Up @@ -79,7 +79,7 @@ def get_test_names(self):

def get_dbms_image_names(self):
"""
gets the DBMS types
gets the DBMS image names
:return:
"""
Expand All @@ -95,7 +95,7 @@ def get_dbms_image_names(self):

def get_os_image_names(self):
"""
gets the test types
gets the os image names
:return:
"""
Expand All @@ -111,7 +111,7 @@ def get_os_image_names(self):

def get_test_request_names(self):
"""
gets the test types
gets the irods test request names
:return:
"""
Expand All @@ -125,6 +125,22 @@ def get_test_request_names(self):
# return the data
return ret_val

def get_test_request_name_exists(self, request_name):
"""
gets true/false if the request name already exists
:return:
"""

# create the sql
sql: str = f"SELECT public.get_test_request_name_exists('{request_name}');"

# get the data
ret_val = self.exec_sql('irods-sv', sql)

# return the data
return ret_val

def get_run_status(self, request_group):
"""
gets the run status
Expand Down
41 changes: 39 additions & 2 deletions src/common/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
from pathlib import Path
from enum import Enum
from src.common.logger import LoggingUtil
from src.common.pg_impl import PGImplementation


class GenUtils:
Expand Down Expand Up @@ -45,7 +46,7 @@ def get_log_file_list(filter_param: str = ''):
# get the log file path
log_file_path: str = LoggingUtil.get_log_path()

# if a filter param was declared make it a wildcard
# if a filter param was declared, make it a wildcard
if filter_param:
filter_param += '*'

Expand All @@ -60,7 +61,7 @@ def get_log_file_list(filter_param: str = ''):
# save the absolute file path, endpoint URL, and file size in a dict
ret_val.update({f"{file_path.name}_{counter}": {'file_path': final_path[1:], 'file_size': f'{file_path.stat().st_size} bytes'}})

# if nothing was found return a message
# if nothing was found, return a message
if len(ret_val) == 0 and filter_param:
ret_val = {'Warning': f'Nothing found using your filter parameter ({filter_param[:-1]})'}

Expand All @@ -79,6 +80,42 @@ def check_freeze_status() -> bool:
# return to the caller
return freeze_mode

@staticmethod
def validate_settings_input(workflow_type, run_status, package_dir, tests, request_group, db_info) -> str:
"""
checks to see if the path passed exists or is using a default
:return:
"""
ret_val: list = []

if not workflow_type:
ret_val.append(['No workflow type found'])

if not run_status:
ret_val.append('No run status')

if len(package_dir) != 0 and not os.path.exists(package_dir):
ret_val.append('Invalid package directory')

if not tests:
ret_val.append('No tests')

if not request_group:
ret_val.append('No request group')
else:
# does the request group name already exist?
db_ret_val = db_info.get_test_request_name_exists(request_group)

# check the results
if db_ret_val < 0:
ret_val.append('DB error getting test request name.')
elif db_ret_val:
ret_val.append(f"Test request name '{request_group}' already exists.")

# return to the caller
return ', '.join(ret_val)


class WorkflowTypeName(str, Enum):
"""
Expand Down
8 changes: 6 additions & 2 deletions src/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -517,8 +517,11 @@ async def superv_workflow_request(workflow_type: WorkflowTypeName,
db_ret_val: int = 0

try:
# get the validation results
validation_msg: str = GenUtils.validate_settings_input(workflow_type, run_status, package_dir, tests, request_group, db_info)

# made sure all the params are valid
if workflow_type and run_status and os_image and tests: # and db_image and test_image and tests
if len(validation_msg) == 0:
# convert the string to a dict
test_request = json.loads(tests)

Expand Down Expand Up @@ -579,6 +582,7 @@ async def superv_workflow_request(workflow_type: WorkflowTypeName,
# else there were no valid tests requested
else:
ret_val = {'Error': 'No valid tests found.'}

# else there were no tests requested
else:
ret_val = {'Error': 'No tests requested.'}
Expand All @@ -589,7 +593,7 @@ async def superv_workflow_request(workflow_type: WorkflowTypeName,
else:
ret_val = {'Success': 'Request successfully submitted.'}
else:
ret_val = {'Error': 'Invalid or missing input parameters.'}
ret_val = {'Error': validation_msg}

except Exception:
# return a failure message
Expand Down

0 comments on commit c5f0036

Please sign in to comment.