11__author__ = "desultory"
2- __version__ = "4.1.2 "
2+ __version__ = "4.1.3 "
33
44from json import loads
55from pathlib import Path
@@ -404,15 +404,19 @@ def _validate_luks_config(self, mapped_name: str) -> None:
404404
405405def export_crypt_sources (self ) -> list [str ]:
406406 """Validates the cryptsetup configuration (if enabled).
407+ Sets CRYPTSETUP_HEADER_{name} if a header file is set.
407408 Adds the cryptsetup source and token to the exports.
408409 Sets the token to the partuuid or uuid if it exists.
409410 Sets the SOURCE when using a path.
410411 Only allows using the path if validation is disabled.
411- sets CRYPTSETUP_HEADER_{name} if a header file is set.
412412 """
413413 for name , parameters in self ["cryptsetup" ].items ():
414- _validate_luks_config (self , name )
415- if parameters .get ("path" ):
414+ _validate_luks_config (self , name ) # First validate the configuration
415+ if header_file := parameters .get ("header_file" ): # Then add the header file to the exports, if defined
416+ self ["exports" ]["CRYPTSETUP_HEADER_%s" % name ] = header_file
417+ self .logger .debug ("Set CRYPTSETUP_HEADER_%s: %s" % (name , header_file ))
418+
419+ if parameters .get ("path" ): # If a path is set, only allow it if validation is disabled
416420 if not self ["validate" ]:
417421 self .logger .warning (
418422 "Using device paths is unreliable and can result in boot failures. Consider using partuuid."
@@ -424,16 +428,13 @@ def export_crypt_sources(self) -> list[str]:
424428 elif not parameters .get ("partuuid" ) and not parameters .get ("uuid" ) and parameters .get ("path" ):
425429 raise ValidationError ("Device source for cryptsetup mount must be specified: %s" % name )
426430
427- for token_type in ["partuuid" , "uuid" ]:
431+ for token_type in ["partuuid" , "uuid" ]: # Attempt to set the token from partuuid or uuid
428432 if token := parameters .get (token_type ):
429433 self ["exports" ]["CRYPTSETUP_TOKEN_%s" % name ] = f"{ token_type .upper ()} ={ token } "
430434 self .logger .debug ("Set CRYPTSETUP_TOKEN_%s: %s=%s" % (name , token_type .upper (), token ))
431435 break
432- else :
436+ else : # Raise an error if no usable token/config is set
433437 raise ValidationError ("A partuuid or uuid must be specified for cryptsetup mount: %s" % name )
434- if header_file := parameters .get ("header_file" ):
435- self ["exports" ]["CRYPTSETUP_HEADER_%s" % name ] = header_file
436- self .logger .debug ("Set CRYPTSETUP_HEADER_%s: %s" % (name , header_file ))
437438
438439
439440def get_crypt_dev (self ) -> str :
0 commit comments