1
1
"""HelmValuesConfig class for managing Helm values and secrets."""
2
2
3
3
import json
4
+ import logging
4
5
import os
5
6
from dataclasses import dataclass , field
6
7
from typing import Any , Dict , Optional
12
13
from helm_values_manager .models .path_data import PathData
13
14
from helm_values_manager .models .value import Value
14
15
16
+ logger = logging .getLogger (__name__ )
17
+
15
18
16
19
@dataclass
17
20
class Deployment :
@@ -45,6 +48,24 @@ def _load_schema(cls) -> Dict[str, Any]:
45
48
with open (schema_path , "r" , encoding = "utf-8" ) as f :
46
49
return json .load (f )
47
50
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
+
48
69
def add_config_path (
49
70
self , path : str , description : Optional [str ] = None , required : bool = False , sensitive : bool = False
50
71
) -> None :
@@ -110,6 +131,10 @@ def set_value(self, path: str, environment: str, value: str) -> None:
110
131
111
132
def validate (self ) -> None :
112
133
"""Validate the configuration."""
134
+ # Validate against JSON schema first
135
+ self ._validate_schema (self .to_dict ())
136
+
137
+ # Then validate each path_data
113
138
for path_data in self ._path_map .values ():
114
139
path_data .validate ()
115
140
@@ -136,19 +161,9 @@ def from_dict(cls, data: dict) -> "HelmValuesConfig":
136
161
Raises:
137
162
ValidationError: If the configuration data is invalid
138
163
"""
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
-
146
164
# 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 )
152
167
153
168
config = cls ()
154
169
config .version = data ["version" ]
0 commit comments