From: Taewan Kim Date: Mon, 22 May 2023 09:59:08 +0000 (+0900) Subject: Check the names of training job and feature group X-Git-Tag: 1.1.0~8 X-Git-Url: https://gerrit.o-ran-sc.org/r/gitweb?a=commitdiff_plain;h=refs%2Fchanges%2F42%2F11142%2F5;p=aiml-fw%2Fawmf%2Ftm.git Check the names of training job and feature group - consist of letters, numbers and underscore - string length between 3 and 63 Issue-ID: AIMLFW-35 Change-Id: Ifc38762206e3dd710d046d844b617bfe31c3a3f0 Signed-off-by: Taewan Kim --- diff --git a/tests/test_tm_apis.py b/tests/test_tm_apis.py index d596d98..e076146 100644 --- a/tests/test_tm_apis.py +++ b/tests/test_tm_apis.py @@ -1205,4 +1205,3 @@ class Test_delete_list_of_trainingjob_version: response=self.client.delete('/trainingjobs', data=json.dumps(delete_req), content_type="application/json") assert response.data==expected_res assert response.status_code == 200 , "status code is not equal" - \ No newline at end of file diff --git a/trainingmgr/common/trainingmgr_util.py b/trainingmgr/common/trainingmgr_util.py index 49e407b..d8941ee 100644 --- a/trainingmgr/common/trainingmgr_util.py +++ b/trainingmgr/common/trainingmgr_util.py @@ -20,6 +20,7 @@ This file contains Training management utility functions """ import json +import re from flask_api import status import requests from trainingmgr.db.common_db_fun import change_in_progress_to_failed_by_latest_version, \ @@ -243,6 +244,11 @@ def validate_trainingjob_name(trainingjob_name, ps_db_obj): """ results = None isavailable = False + pattern = re.compile(r"[a-zA-Z0-9_]+") + if (not re.fullmatch(pattern, trainingjob_name) or + len(trainingjob_name) < 3 or len(trainingjob_name) > 63): + raise TMException("The name of training job is invalid.") + try: results = get_all_versions_info_by_name(trainingjob_name, ps_db_obj) except Exception as err: @@ -273,4 +279,4 @@ def get_all_pipeline_names_svc(training_config_obj): except Exception as err: logger.error(str(err)) logger.debug(pipeline_names) - return pipeline_names \ No newline at end of file + return pipeline_names diff --git a/trainingmgr/trainingmgr_main.py b/trainingmgr/trainingmgr_main.py index f7969ed..5e4779b 100644 --- a/trainingmgr/trainingmgr_main.py +++ b/trainingmgr/trainingmgr_main.py @@ -1320,7 +1320,11 @@ def create_feature_group(): (feature_group_name, features, datalake_source, enable_dme, dme_host, dme_port, bucket, token, source_name,db_org)=check_feature_group_data(json_data) # check the data conformance LOGGER.debug("the db info is : ", get_feature_group_by_name_db(PS_DB_OBJ, feature_group_name)) - if len(feature_group_name) < 3 or len(feature_group_name) > 63 or get_feature_group_by_name_db(PS_DB_OBJ, feature_group_name): + + pattern = re.compile(r"[a-zA-Z0-9_]+") + if (not re.fullmatch(pattern, feature_group_name) or + len(feature_group_name) < 3 or len(feature_group_name) > 63 or + get_feature_group_by_name_db(PS_DB_OBJ, feature_group_name)): api_response = {"Exception": "Failed to create the feature group since feature group not valid or already present"} response_code = status.HTTP_400_BAD_REQUEST else: