diff --git a/CHANGELOG.md b/CHANGELOG.md index d73f688d8..6573cb0a3 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -39,6 +39,7 @@ Inspired from [Keep a Changelog](https://keepachangelog.com/en/1.0.0/) - use try-except-else block for handling unexpected exceptions during integration tests by @rawwar([#370](https://github.com/opensearch-project/opensearch-py-ml/pull/370)) - Removed pandas version pin in nox tests by @rawwar ([#368](https://github.com/opensearch-project/opensearch-py-ml/pull/368)) - Switch AL2 to AL2023 agent and DockerHub to ECR images in ml-models.JenkinsFile ([#377](https://github.com/opensearch-project/opensearch-py-ml/pull/377)) +- Refactored validators in ML Commons' client([#385](https://github.com/opensearch-project/opensearch-py-ml/pull/385)) ### Fixed - Enable make_model_config_json to add model description to model config file by @thanawan-atc in ([#203](https://github.com/opensearch-project/opensearch-py-ml/pull/203)) diff --git a/opensearch_py_ml/ml_commons/ml_commons_client.py b/opensearch_py_ml/ml_commons/ml_commons_client.py index 649d08b61..fbd38a913 100644 --- a/opensearch_py_ml/ml_commons/ml_commons_client.py +++ b/opensearch_py_ml/ml_commons/ml_commons_client.py @@ -25,8 +25,10 @@ from opensearch_py_ml.ml_commons.model_connector import Connector from opensearch_py_ml.ml_commons.model_execute import ModelExecute from opensearch_py_ml.ml_commons.model_uploader import ModelUploader -from opensearch_py_ml.ml_commons.validators.profile import validate_profile_input -from opensearch_py_ml.ml_commons.validators.stats import validate_stats_input +from opensearch_py_ml.ml_commons.validators import ( + validate_profile_input, + validate_stats_input, +) class MLCommonClient: diff --git a/opensearch_py_ml/ml_commons/model_access_control.py b/opensearch_py_ml/ml_commons/model_access_control.py index bae4e603e..af676cc09 100644 --- a/opensearch_py_ml/ml_commons/model_access_control.py +++ b/opensearch_py_ml/ml_commons/model_access_control.py @@ -11,7 +11,7 @@ from opensearchpy.exceptions import NotFoundError from opensearch_py_ml.ml_commons.ml_common_utils import ML_BASE_URI -from opensearch_py_ml.ml_commons.validators.model_access_control import ( +from opensearch_py_ml.ml_commons.validators import ( validate_create_model_group_parameters, validate_delete_model_group_parameters, validate_search_model_group_parameters, diff --git a/opensearch_py_ml/ml_commons/validators/stats.py b/opensearch_py_ml/ml_commons/stats.py similarity index 100% rename from opensearch_py_ml/ml_commons/validators/stats.py rename to opensearch_py_ml/ml_commons/stats.py diff --git a/opensearch_py_ml/ml_commons/validators/model_access_control.py b/opensearch_py_ml/ml_commons/validators.py similarity index 91% rename from opensearch_py_ml/ml_commons/validators/model_access_control.py rename to opensearch_py_ml/ml_commons/validators.py index 2fb928e25..4224165cc 100644 --- a/opensearch_py_ml/ml_commons/validators/model_access_control.py +++ b/opensearch_py_ml/ml_commons/validators.py @@ -95,3 +95,11 @@ def validate_delete_model_group_parameters(model_group_id: str): def validate_search_model_group_parameters(query: dict): _validate_model_group_query(query) + + +def validate_profile_input(path_parameter, payload): + if path_parameter is not None and not isinstance(path_parameter, str): + raise ValueError("path_parameter needs to be a string or None") + + if payload is not None and not isinstance(payload, dict): + raise ValueError("payload needs to be a dictionary or None") diff --git a/opensearch_py_ml/ml_commons/validators/__init__.py b/opensearch_py_ml/ml_commons/validators/__init__.py deleted file mode 100644 index 8d89f2583..000000000 --- a/opensearch_py_ml/ml_commons/validators/__init__.py +++ /dev/null @@ -1,6 +0,0 @@ -# SPDX-License-Identifier: Apache-2.0 -# The OpenSearch Contributors require contributions made to -# this file be licensed under the Apache-2.0 license or a -# compatible open source license. -# Any modifications Copyright OpenSearch Contributors. See -# GitHub history for details. diff --git a/opensearch_py_ml/ml_commons/validators/profile.py b/opensearch_py_ml/ml_commons/validators/profile.py deleted file mode 100644 index 602edb0f9..000000000 --- a/opensearch_py_ml/ml_commons/validators/profile.py +++ /dev/null @@ -1,16 +0,0 @@ -# SPDX-License-Identifier: Apache-2.0 -# The OpenSearch Contributors require contributions made to -# this file be licensed under the Apache-2.0 license or a -# compatible open source license. -# Any modifications Copyright OpenSearch Contributors. See -# GitHub history for details. - -"""Module for validating Profile API parameters """ - - -def validate_profile_input(path_parameter, payload): - if path_parameter is not None and not isinstance(path_parameter, str): - raise ValueError("path_parameter needs to be a string or None") - - if payload is not None and not isinstance(payload, dict): - raise ValueError("payload needs to be a dictionary or None") diff --git a/tests/ml_commons/test_validators/test_model_access_control_validators.py b/tests/ml_commons/test_validators.py similarity index 98% rename from tests/ml_commons/test_validators/test_model_access_control_validators.py rename to tests/ml_commons/test_validators.py index d5701e702..35534ca97 100644 --- a/tests/ml_commons/test_validators/test_model_access_control_validators.py +++ b/tests/ml_commons/test_validators.py @@ -7,7 +7,7 @@ import pytest -from opensearch_py_ml.ml_commons.validators.model_access_control import ( +from opensearch_py_ml.ml_commons.validators import ( _validate_model_group_access_mode, _validate_model_group_add_all_backend_roles, _validate_model_group_backend_roles,