Przeglądaj źródła

fix(template): skip empty files during generation (#1518) (#1530)

Christian Lempa 4 miesięcy temu
rodzic
commit
c9338fe9ba
2 zmienionych plików z 18 dodań i 2 usunięć
  1. 4 0
      CHANGELOG.md
  2. 14 2
      cli/core/template/template.py

+ 4 - 0
CHANGELOG.md

@@ -17,6 +17,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
 - Packer template support (#1427) - Manage Packer templates with schema 1.0
 - Alphabetically sorted commands in help output with grouped panels for better organization
 - Separate help panels for "Template Commands" and "Configuration Commands"
+- Compose Schema 1.2: Authentik Traefik middleware integration with `authentik_traefik_middleware` variable
 
 ### Changed
 - Removed Jinja2 `| default()` filter extraction and merging (#1410) - All defaults must now be defined in template/module specs
@@ -24,9 +25,12 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
 - Improved debug logging to capture module discovery and registration during initialization
 - Enhanced debug logging for better troubleshooting
 - Simplified dry-run output to show only essential information (files, sizes, status)
+- Traefik template now uses module spec variable `authentik_traefik_middleware` instead of template-specific `traefik_authentik_middleware_name`
 
 ### Fixed
 - CLI --var flag now properly converts boolean and numeric strings to appropriate Python types (#1522)
+- Empty template files are no longer created during generation (#1518)
+- Enhanced user confirmation flow for template generation (#1428)
 
 ## [0.0.7] - 2025-10-28
 

+ 14 - 2
cli/core/template/template.py

@@ -739,20 +739,28 @@ class Template:
             debug: Enable debug mode with verbose output
 
         Returns:
-            Tuple of (rendered_files, variable_values) where variable_values includes autogenerated values
+            Tuple of (rendered_files, variable_values) where variable_values includes autogenerated values.
+            Empty files (files with only whitespace) are excluded from the returned dict.
         """
         variable_values = variables.get_satisfied_values()
         self._generate_autogenerated_values(variables, variable_values)
         self._log_render_start(debug, variable_values)
 
         rendered_files = {}
+        skipped_files = []
         available_vars = set(variable_values.keys())
 
         for template_file in self.template_files:
             if template_file.file_type == "j2":
                 try:
                     content = self._render_jinja2_file(template_file, variable_values, available_vars, debug)
-                    rendered_files[str(template_file.output_path)] = content
+                    # Skip empty files (only whitespace or empty string)
+                    if content.strip():
+                        rendered_files[str(template_file.output_path)] = content
+                    else:
+                        skipped_files.append(str(template_file.output_path))
+                        if debug:
+                            logger.info(f"Skipping empty file: {template_file.output_path}")
                 except (
                     UndefinedError,
                     Jinja2TemplateSyntaxError,
@@ -773,8 +781,12 @@ class Template:
                     ) from e
             elif template_file.file_type == "static":
                 content = self._render_static_file(template_file, debug)
+                # Static files are always included, even if empty
                 rendered_files[str(template_file.output_path)] = content
 
+        if skipped_files:
+            logger.debug(f"Skipped {len(skipped_files)} empty file(s): {', '.join(skipped_files)}")
+
         return rendered_files, variable_values
 
     def _sanitize_content(self, content: str, _file_path: Path) -> str: