@@ -70,7 +70,11 @@ def _validate_crypysetup_key(self, key_paramters: dict) -> None:
7070
7171
7272@contains ('validate' , "Skipping cryptsetup configuration validation." , log_level = 30 )
73- def _validate_cryptsetup_config (self , mapped_name : str , config : dict ) -> None :
73+ def _validate_cryptsetup_config (self , mapped_name : str ) -> None :
74+ try :
75+ config = self ['cryptsetup' ][mapped_name ]
76+ except KeyError :
77+ raise KeyError ("No cryptsetup configuration found for: %s" % mapped_name )
7478 self .logger .log (5 , "[%s] Validating cryptsetup configuration: %s" % (mapped_name , config ))
7579 for parameter in config :
7680 if parameter not in CRYPTSETUP_PARAMETERS :
@@ -92,7 +96,6 @@ def _validate_cryptsetup_config(self, mapped_name: str, config: dict) -> None:
9296def _process_cryptsetup_multi (self , mapped_name : str , config : dict ) -> None :
9397 """ Processes the cryptsetup configuration """
9498 config = _merge_cryptsetup (self , mapped_name , config ) # Merge the config with the existing configuration
95- _validate_cryptsetup_config (self , mapped_name , config ) # Validate the configuration
9699 self .logger .debug ("[%s] Processing cryptsetup configuration: %s" % (mapped_name , config ))
97100 # Check if the key type is defined in the configuration, otherwise use the default, check if it's valid
98101 if key_type := config .get ('key_type' , self .get ('cryptsetup_key_type' )):
@@ -118,21 +121,21 @@ def _process_cryptsetup_multi(self, mapped_name: str, config: dict) -> None:
118121
119122
120123@contains ('validate' , "Skipping cryptsetup configuration validation." , log_level = 30 )
121- def _validate_luks_source (self , mapped_name : str ) -> None :
122- """ Checks that a LUKS source device is valid """
124+ def _validate_luks_config (self , mapped_name : str ) -> None :
125+ """ Checks that a LUKS config portion is valid. """
123126 for _dm_info in self ['_dm_info' ].values ():
124127 if _dm_info ['name' ] == mapped_name :
125- dm_info = _dm_info
128+ dm_info = _dm_info # Get the device mapper information
126129 break
127130 else :
128131 raise ValueError ("No device mapper information found for: %s" % mapped_name )
129132
130- cryptsetup_info = self ['cryptsetup' ][mapped_name ]
133+ cryptsetup_info = self ['cryptsetup' ][mapped_name ] # Get the cryptsetup information
131134
132- if not dm_info ['uuid' ].startswith ('CRYPT-LUKS' ):
135+ if not dm_info ['uuid' ].startswith ('CRYPT-LUKS' ): # Ensure the device is a crypt device
133136 raise ValueError ("Device is not a crypt device: %s" % dm_info )
134137
135- slave_source = dm_info ['slaves' ][0 ]
138+ slave_source = dm_info ['slaves' ][0 ] # Get the slave source
136139
137140 try :
138141 blkid_info = self ['_blkid_info' ][f'/dev/{ slave_source } ' ]
@@ -147,18 +150,19 @@ def _validate_luks_source(self, mapped_name: str) -> None:
147150 break
148151 else :
149152 raise ValueError ("[%s] Unable to validate LUKS source: %s" % (mapped_name , cryptsetup_info ))
153+ _validate_cryptsetup_config (self , mapped_name )
150154
151155
152156def export_crypt_sources (self ) -> list [str ]:
153157 """
154- Validates the cryptsetup configuration.
158+ Validates the cryptsetup configuration (if enabled) .
155159 Adds the cryptsetup source and token to the exports.
156160 Sets the token to the partuuid or uuid if it exists.
157161 Sets the SOURCE when using a path.
158162 Only allows using the path if validation is disabled.
159163 """
160164 for name , parameters in self ['cryptsetup' ].items ():
161- _validate_luks_source (self , name )
165+ _validate_luks_config (self , name )
162166 if parameters .get ('path' ):
163167 if not self ['validate' ]:
164168 self .logger .warning ("Using device paths is unreliable and can result in boot failures. Consider using partuuid." )
0 commit comments