Sfoglia il codice sorgente

validation clean up

xcad 6 mesi fa
parent
commit
f67391f74a

+ 2 - 43
cli/core/module.py

@@ -102,51 +102,10 @@ class Module(ABC):
     template = self._get_template(id)
     
     # Validate template (will raise TemplateValidationError if validation fails)
-    self._validate_template(template, id)
-    
-    print("TEST SUCCESSFUL")
-  
-  def _validate_template(self, template, template_id: str) -> None:
-    """Validate template and raise error if validation fails."""
-    from .exceptions import TemplateValidationError
-    
-    validation_errors = []
-    
-    # Update template variables with module variable registry
     module_variable_registry = getattr(self, 'variables', None)
-    if module_variable_registry:
-      template.update_variables_with_module_metadata(module_variable_registry)
-      
-      # Validate parent-child relationships in the registry
-      registry_errors = module_variable_registry.validate_parent_child_relationships()
-      if registry_errors:
-        validation_errors.extend(registry_errors)
-      
-      # Validate that all template variables are either registered or in template_vars
-      unregistered_vars = []
-      for var_name in template.vars:
-        # Check if variable is registered in module
-        if not module_variable_registry.get_variable(var_name):
-          # Check if it's defined in template's frontmatter variable_metadata (template_vars)
-          if var_name not in template.variable_metadata:
-            unregistered_vars.append(var_name)
-      
-      if unregistered_vars:
-        validation_errors.append(
-          f"Unregistered variables found: {', '.join(unregistered_vars)}. "
-          f"Variables must be either registered in the module or defined in template frontmatter 'variables' section."
-        )
-    
-    # Validate template syntax and structure
-    template_warnings = template.validate(module_variable_registry)
+    template.validate(module_variable_registry, id)
     
-    # If there are validation errors, fail with TemplateValidationError
-    if validation_errors:
-      raise TemplateValidationError(template_id, validation_errors)
-    
-    # If there are non-critical warnings, log them but don't fail
-    if template_warnings:
-      logger.warning(f"Template '{template_id}' has validation warnings: {template_warnings}")
+    print("TEST SUCCESSFUL")
   
   def register_cli(self, app: Typer):
     """Register module commands with the main app."""

+ 48 - 35
cli/core/template.py

@@ -147,59 +147,62 @@ class Template:
       logging.getLogger('boilerplates').debug(f"Error parsing template variables: {e}")
       return set(), {}
 
-  def validate(self, module_variable_metadata: Dict[str, Dict[str, Any]] = None) -> List[str]:
+  def validate(self, module_variable_registry=None, template_id: str = None):
     """Validate template integrity.
     
     Args:
-        module_variable_metadata: Module's variable metadata for validation
-    
-    Returns:
-        List of validation error messages. Empty list if valid.
+        module_variable_registry: Module's VariableRegistry for validation
+        template_id: Template ID for error messages (uses self.id if not provided)
     
     Raises:
-        TemplateValidationError: If validation fails (critical errors only).
+        TemplateValidationError: If validation fails.
     """
+    import logging
+    from .exceptions import TemplateValidationError
+    
+    logger = logging.getLogger('boilerplates')
+    template_id = template_id or self.id
     errors = []
+    warnings = []
     
-    # Check for Jinja2 syntax errors (critical - should raise immediately)
+    # Check for Jinja2 syntax errors (critical)
     try:
       env = self._create_jinja_env()
       env.from_string(self.content)
     except TemplateSyntaxError as e:
-      raise TemplateValidationError(self.id, [f"Invalid Jinja2 syntax at line {e.lineno}: {e.message}"])
+      raise TemplateValidationError(template_id, [f"Invalid Jinja2 syntax at line {e.lineno}: {e.message}"])
     except Exception as e:
-      raise TemplateValidationError(self.id, [f"Template parsing error: {str(e)}"])
+      raise TemplateValidationError(template_id, [f"Template parsing error: {str(e)}"])
     
-    # Validate variable definitions (critical - should raise immediately)
-    undefined_vars = self._validate_variable_definitions(module_variable_metadata or {})
-    if undefined_vars:
-      raise TemplateValidationError(self.id, undefined_vars)
+    # Validate module variable registry consistency
+    if module_variable_registry:
+      registry_errors = module_variable_registry.validate_parent_child_relationships()
+      if registry_errors:
+        errors.extend(registry_errors)
     
-    # All variables are now auto-detected, no need to check for undefined
-    # The template parser will have found all variables used
+    # Validate variable definitions (critical)
+    undefined_vars = self._validate_variable_definitions(module_variable_registry)
+    if undefined_vars:
+      errors.extend(undefined_vars)
     
-    # Check for missing required frontmatter fields
+    # Check for missing frontmatter fields (warnings)
     if not self.name:
-      errors.append("Missing 'name' in frontmatter")
+      warnings.append("Missing 'name' in frontmatter")
     
     if not self.description or self.description == 'No description available':
-      errors.append("Missing 'description' in frontmatter")
+      warnings.append("Missing 'description' in frontmatter")
     
-    # Check for empty content (unless it's intentionally a metadata-only template)
+    # Check for empty content (warning)
     if not self.content.strip() and not self.files:
-      errors.append("Template has no content")
+      warnings.append("Template has no content")
     
-    return errors
-
-  def update_variables_with_module_metadata(self, module_variable_registry) -> None:
-    """Update template variables with module variable registry.
+    # Raise if critical errors found
+    if errors:
+      raise TemplateValidationError(template_id, errors)
     
-    Args:
-        module_variable_registry: Module's VariableRegistry instance
-    """
-    # This method is kept for compatibility but simplified
-    # Variables are now managed directly by the VariableRegistry
-    pass
+    # Log warnings
+    for warning in warnings:
+      logger.warning(f"Template '{template_id}': {warning}")
 
   def _validate_variable_definitions(self, module_variable_registry) -> List[str]:
     """Validate that all template variables are properly defined.
@@ -212,13 +215,23 @@ class Template:
     """
     errors = []
     
-    # For now, simplified validation - just check template-specific variables
-    # Module variables are validated by the VariableRegistry itself
+    if not module_variable_registry:
+      return errors
+    
+    # Check that all template variables are either registered or in frontmatter
+    unregistered_vars = []
     for var_name in self.vars:
-      if var_name.startswith('template.'):
-        # Template-specific variables must be defined in frontmatter
+      # Check if variable is registered in module
+      if not module_variable_registry.get_variable(var_name):
+        # Check if it's defined in template's frontmatter
         if var_name not in self.variable_metadata:
-          errors.append(f"Template variable '{var_name}' must be defined in frontmatter 'variables' section")
+          unregistered_vars.append(var_name)
+    
+    if unregistered_vars:
+      errors.append(
+        f"Unregistered variables found: {', '.join(unregistered_vars)}. "
+        f"Variables must be either registered in the module or defined in template frontmatter 'variables' section."
+      )
     
     return errors
 

+ 3 - 1
library/compose/n8n/compose.yaml

@@ -62,6 +62,9 @@ services:
     {% endif %}
     restart: {{ restart_policy | default('unless-stopped') }}
     {% if ports %}
+    ports:
+      - "5678:5678"
+    {% endif %}
 
 volumes:
   data:
@@ -74,4 +77,3 @@ networks:
     external: true
   {% endif %}
 {% endif %}
-{% endif %}

+ 77 - 0
library/compose/n8n/compose.yaml.backup

@@ -0,0 +1,77 @@
+---
+name: "n8n"
+description: "Workflow automation and integration tool"
+version: "0.0.1"
+date: "2025-09-03"
+author: "Christian Lempa"
+tags:
+  - n8n
+  - automation
+  - workflows
+  - compose
+variables:
+  template.custom_config:
+    description: "Custom configuration for n8n"
+    hint: "Additional environment variables or settings"
+    type: "string"
+    default: ""
+---
+services:
+  {{ service_name }}:
+    image: n8nio/n8n:1.110.1
+    environment:
+      - N8N_LOG_LEVEL={{ container_loglevel | default('info') }}
+      - GENERIC_TIMEZONE={{ container_timezone }}
+      - TZ={{ container_timezone }}
+      - N8N_ENFORCE_SETTINGS_FILE_PERMISSIONS=true
+      - N8N_RUNNERS_ENABLED=true
+      {% if traefik %}
+      {% if traefik.tls %}
+      - N8N_EDITOR_BASE_URL=https://{{ traefik.host }}
+      {% else %}
+      - N8N_EDITOR_BASE_URL=http://{{ traefik.host }}
+      {% endif %}
+      {% endif %}
+      {% if postgres %}
+      - DB_TYPE=postgresdb
+      - DB_POSTGRESDB_HOST={{ postgres.host }}
+      - DB_POSTGRESDB_PORT=${DB_POSTGRESDB_PORT:-5432}
+      - DB_POSTGRESDB_DATABASE=${POSTGRES_DB}
+      - DB_POSTGRESDB_USER=${POSTGRES_USER}
+      - DB_POSTGRESDB_PASSWORD=${POSTGRES_PASSWORD}
+      {% endif %}
+    volumes:
+      - /etc/localtime:/etc/localtime:ro
+      - data:/home/node/.n8n
+    {% if network %}
+    networks:
+      - {{ network.name | default('bridge') }}
+    {% endif %}
+    {% if traefik %}
+    labels:
+      - traefik.enable={{ traefik | default('true') }}
+      - traefik.http.routers.{{ service_name }}.rule=Host(`{{ traefik.host }}`)
+      {% if traefik.tls %}
+      - traefik.http.routers.{{ service_name }}.entrypoints={{ traefik.tls.entrypoint | default('websecure') }}
+      - traefik.http.routers.{{ service_name }}.tls=true
+      - traefik.http.routers.{{ service_name }}.tls.certresolver={{ traefik.tls.certresolver }}
+      {% else %}
+      - traefik.http.routers.{{ service_name }}.entrypoints={{ traefik.entrypoint | default('web') }}
+      {% endif %}
+      - traefik.http.services.{{ service_name }}.loadbalancer.server.port=5678
+    {% endif %}
+    restart: {{ restart_policy | default('unless-stopped') }}
+    {% if ports %}
+
+volumes:
+  data:
+    driver: local
+
+{% if network %}
+networks:
+  {{ network.name | default('bridge') }}:
+  {% if network.external %}
+    external: true
+  {% endif %}
+{% endif %}
+{% endif %}