11"""HelmValuesConfig class for managing Helm values and secrets."""
22
33import json
4+ import logging
45import os
56from dataclasses import dataclass , field
67from typing import Any , Dict , Optional
1213from helm_values_manager .models .path_data import PathData
1314from helm_values_manager .models .value import Value
1415
16+ logger = logging .getLogger (__name__ )
17+
1518
1619@dataclass
1720class Deployment :
@@ -45,6 +48,24 @@ def _load_schema(cls) -> Dict[str, Any]:
4548 with open (schema_path , "r" , encoding = "utf-8" ) as f :
4649 return json .load (f )
4750
51+ @classmethod
52+ def _validate_schema (cls , data : dict ) -> None :
53+ """
54+ Validate data against JSON schema.
55+
56+ Args:
57+ data: Dictionary to validate against schema
58+
59+ Raises:
60+ ValidationError: If the data does not match the schema
61+ """
62+ schema = cls ._load_schema ()
63+ try :
64+ jsonschema .validate (instance = data , schema = schema )
65+ except ValidationError as e :
66+ logger .error ("JSON schema validation failed: %s" , e )
67+ raise
68+
4869 def add_config_path (
4970 self , path : str , description : Optional [str ] = None , required : bool = False , sensitive : bool = False
5071 ) -> None :
@@ -110,6 +131,10 @@ def set_value(self, path: str, environment: str, value: str) -> None:
110131
111132 def validate (self ) -> None :
112133 """Validate the configuration."""
134+ # Validate against JSON schema first
135+ self ._validate_schema (self .to_dict ())
136+
137+ # Then validate each path_data
113138 for path_data in self ._path_map .values ():
114139 path_data .validate ()
115140
@@ -136,19 +161,9 @@ def from_dict(cls, data: dict) -> "HelmValuesConfig":
136161 Raises:
137162 ValidationError: If the configuration data is invalid
138163 """
139- # Convert string boolean values to actual booleans for backward compatibility
140- data = data .copy () # Don't modify the input
141- for config_item in data .get ("config" , []):
142- for boolean_field in ["required" , "sensitive" ]:
143- if boolean_field in config_item and isinstance (config_item [boolean_field ], str ):
144- config_item [boolean_field ] = config_item [boolean_field ].lower () == "true"
145-
146164 # Validate against schema
147- schema = cls ._load_schema ()
148- try :
149- jsonschema .validate (instance = data , schema = schema )
150- except ValidationError as e :
151- raise e
165+ data = data .copy () # Don't modify the input
166+ cls ._validate_schema (data )
152167
153168 config = cls ()
154169 config .version = data ["version" ]
0 commit comments