From: Ashwin M. Joshi Date: Wed, 18 Feb 2026 05:49:12 +0000 (+0530) Subject: python-common: Move validation function to utils and remove unused X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=7b37c21cfa6b6866a2efadbce257f9b6adad58ea;p=ceph.git python-common: Move validation function to utils and remove unused Fixes: https://tracker.ceph.com/issues/74986 Signed-off-by: Ashwin M. Joshi Conflicts: src/python-common/ceph/deployment/service_spec.py src/python-common/ceph/deployment/utils.py --- diff --git a/src/python-common/ceph/deployment/service_spec.py b/src/python-common/ceph/deployment/service_spec.py index 86bdf18451a..b5726820ee5 100644 --- a/src/python-common/ceph/deployment/service_spec.py +++ b/src/python-common/ceph/deployment/service_spec.py @@ -41,7 +41,7 @@ from ceph.deployment.hostspec import ( ) from ceph.deployment.utils import unwrap_ipv6, valid_addr, verify_non_negative_int from ceph.deployment.utils import verify_positive_int, verify_non_negative_number -from ceph.deployment.utils import verify_boolean, verify_enum, verify_int +from ceph.deployment.utils import verify_boolean, verify_enum, verify_int, verify_non_empty_string from ceph.deployment.utils import parse_combined_pem_file, validate_port, validate_unique_ports from ceph.cephadm.d3n_types import D3NCacheSpec, D3NCacheError from ceph.utils import is_hex @@ -52,11 +52,6 @@ ServiceSpecT = TypeVar('ServiceSpecT', bound='ServiceSpec') FuncT = TypeVar('FuncT', bound=Callable) -def validate_non_empty_string(value: Optional[str], field_name: str) -> None: - if not isinstance(value, str) or not value.strip(): - raise SpecValidationError(f"Invalid {field_name}: Must be a non-empty string.") - - class TLSBlock(TypedDict, total=False): ssl: bool certificate_source: str @@ -2827,15 +2822,16 @@ class OAuth2ProxySpec(ServiceSpec): + ', '.join(missing_required_fields) + '.' ) - validate_non_empty_string(self.provider_display_name, "provider_display_name") - validate_non_empty_string(self.client_id, "client_id") - validate_non_empty_string(self.client_secret, "client_secret") + verify_non_empty_string(self.provider_display_name, "provider_display_name") + verify_non_empty_string(self.client_id, "client_id") + verify_non_empty_string(self.client_secret, "client_secret") + self._validate_cookie_secret(self.cookie_secret) self._validate_url(self.oidc_issuer_url, "oidc_issuer_url") if self.redirect_url is not None: self._validate_url(self.redirect_url, "redirect_url") if self.scope is not None: - self._validate_non_empty_string(self.scope, "scope") + verify_non_empty_string(self.scope, "scope") if self.email_domains is not None: self._validate_domain_name(self.email_domains, "email_domains") if self.https_address is not None: @@ -3657,7 +3653,7 @@ class TunedProfileSpec(): if 'profile_name' not in spec: raise SpecValidationError('Tuned profile spec must include "profile_name" field') data['profile_name'] = spec['profile_name'] - validate_non_empty_string(data['profile_name'], "profile_name") + verify_non_empty_string(data['profile_name'], "profile_name") if 'placement' in spec: data['placement'] = PlacementSpec.from_json(spec['placement']) if 'settings' in spec: diff --git a/src/python-common/ceph/deployment/utils.py b/src/python-common/ceph/deployment/utils.py index 3e901669f5c..52a53ea5b4f 100644 --- a/src/python-common/ceph/deployment/utils.py +++ b/src/python-common/ceph/deployment/utils.py @@ -191,3 +191,9 @@ def validate_unique_ports(ports: List[int]) -> None: raise SpecValidationError( 'Invalid port: Duplicate ports are not allowed' ) + + +def verify_non_empty_string(field: Any, field_name: str) -> None: + # isinstance first so we never call .strip() on None or non-str + if not isinstance(field, str) or not field.strip(): + raise SpecValidationError(f"Invalid {field_name}: Must be a non-empty string.")