]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph.git/commitdiff
python-common: Move validation function to utils and remove unused 67384/head
authorAshwin M. Joshi <ashjosh1@in.ibm.com>
Wed, 18 Feb 2026 05:49:12 +0000 (11:19 +0530)
committerAshwin M. Joshi <ashjosh1@in.ibm.com>
Wed, 3 Jun 2026 15:49:18 +0000 (21:19 +0530)
Fixes: https://tracker.ceph.com/issues/74986
Signed-off-by: Ashwin M. Joshi <ashjosh1@in.ibm.com>
 Conflicts:
src/python-common/ceph/deployment/service_spec.py
src/python-common/ceph/deployment/utils.py

src/python-common/ceph/deployment/service_spec.py
src/python-common/ceph/deployment/utils.py

index 86bdf18451af8d40a1fbfd7bae5c611227c4f6eb..b5726820ee5ca9b1b5075c3ed1d3d90e26095cdb 100644 (file)
@@ -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:
index 3e901669f5cffa6d521d0bcf7d33c44ea043f9ab..52a53ea5b4f6c515bdb2c91eebf27dcb9b30f066 100644 (file)
@@ -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.")