|
5 | 5 | import logging |
6 | 6 | from functools import cache |
7 | 7 | from pathlib import Path |
| 8 | +from types import NoneType |
8 | 9 | from typing import Any |
9 | 10 |
|
10 | 11 | from hera.workflows import DAG, ConfigMapEnvFrom, Container, CronWorkflow, S3Artifact, SecretEnvFrom, Task, Workflow |
11 | 12 | from hera.workflows.archive import NoneArchiveStrategy |
12 | 13 | from hera.workflows.models import EnvVar, SecurityContext |
13 | | -from pydantic import Field, SecretStr |
| 14 | +from pydantic import Field, SecretStr, ValidationError |
14 | 15 | from pydantic_settings import SettingsConfigDict |
15 | 16 |
|
16 | 17 | from wurzel.backend.backend import Backend |
17 | 18 | from wurzel.cli import generate_cli_call |
| 19 | +from wurzel.exceptions import EnvSettingsError |
18 | 20 | from wurzel.step import TypedStep |
19 | 21 | from wurzel.step.settings import SettingsBase, SettingsLeaf |
20 | 22 | from wurzel.step_executor import BaseStepExecutor, PrometheusStepExecutor |
@@ -98,7 +100,18 @@ def _create_envs_from_step_settings(self, step: "TypedStep[Any, Any, Any]") -> l |
98 | 100 |
|
99 | 101 | env_vars = [] |
100 | 102 |
|
101 | | - for field_name, field_value in step.settings_class().model_dump().items(): |
| 103 | + if step.settings_class == NoneType: |
| 104 | + return env_vars |
| 105 | + |
| 106 | + settings_cls = step.settings_class.with_prefix(f"{step.__class__.__name__.upper()}__") |
| 107 | + try: |
| 108 | + settings_instance = settings_cls() |
| 109 | + except ValidationError as err: # type: ignore [attr-defined] |
| 110 | + e = EnvSettingsError(f"could not create {step.settings_class.__name__} from env for {step.__class__.__name__}") |
| 111 | + e.add_note("To fix these issues setup env vars in the format <step_name>__<var>") |
| 112 | + raise e from err |
| 113 | + |
| 114 | + for field_name, field_value in settings_instance.model_dump().items(): |
102 | 115 | # Skip fields with sensitive keywords in their names |
103 | 116 | if isinstance(field_value, SecretStr): |
104 | 117 | log.info(f"skipped config {field_name} due to secret detection") |
|
0 commit comments