|
4 | 4 | from dataclasses import dataclass, field |
5 | 5 | from functools import cache, cached_property |
6 | 6 | from pathlib import Path |
7 | | -from typing import Iterator, Optional, Sequence, Union, cast |
| 7 | +from typing import Iterator, Literal, Mapping, Optional, Sequence, Union, cast |
8 | 8 |
|
9 | 9 | import requests |
10 | 10 | import semver |
|
71 | 71 | # Generic Helper functions and classes |
72 | 72 | ############################################################################### |
73 | 73 |
|
74 | | -def colorize(text: str, color: str = None, bold: bool = False) -> str: |
| 74 | +Color = Literal["black", "grey", "red", "green", "yellow", "blue", "magenta", "cyan"] |
| 75 | +Attribute = Literal["bold", "dark", "underline", "blink", "reverse", "concealed"] |
| 76 | + |
| 77 | +def colorize(text: str, color: Color | None = None, bold: bool = False) -> str: |
75 | 78 | """Apply color and formatting to text""" |
76 | | - attrs = ["bold"] if bold else None |
| 79 | + attrs: list[Attribute] = ["bold"] if bold else [] |
77 | 80 | return colored(text, color, attrs=attrs) |
78 | 81 |
|
79 | 82 | def camel_to_snake(name: str) -> str: |
@@ -258,10 +261,10 @@ def helm_chart(self) -> HelmChart: |
258 | 261 |
|
259 | 262 | def sync_values_files_schema_header_version(self) -> None: |
260 | 263 | """Sync schema version in all values files""" |
| 264 | + if self.helm_chart.platform_managed_chart_version is None: |
| 265 | + return |
261 | 266 | for value_file in self.values_files: |
262 | | - value_file.set_header_schema_version( |
263 | | - self.helm_chart.platform_managed_chart_version |
264 | | - ) |
| 267 | + value_file.set_header_schema_version(self.helm_chart.platform_managed_chart_version) |
265 | 268 |
|
266 | 269 | class ServiceInstanceConfigValidator: |
267 | 270 |
|
@@ -410,7 +413,7 @@ def iter_schema_validation_errors(self) -> Iterator[SchemaValidationError]: |
410 | 413 | ) |
411 | 414 |
|
412 | 415 | def enrich_error_message(self, error: ValidationError) -> ValidationError: |
413 | | - if error.message.endswith("is too long") and error.schema.get("maxLength"): |
| 416 | + if error.message.endswith("is too long") and isinstance(error.schema, Mapping) and error.schema.get("maxLength"): |
414 | 417 | error.message += f', the maximum length is {error.schema["maxLength"]}' |
415 | 418 | return error |
416 | 419 |
|
@@ -478,8 +481,8 @@ def format_error(error: Union[ValidationError, SchemaValidationError]) -> str: |
478 | 481 | location = "/".join(map(str, error.absolute_path)) |
479 | 482 | error_message = f"{colorize('ERROR:', 'red')} {error.message}\n at: {colorize(location, bold=True)}" |
480 | 483 |
|
481 | | - if description := error.schema and error.schema.get("description"): |
482 | | - title, description = description.split("\n", maxsplit=1) |
| 484 | + if isinstance(error.schema, Mapping) and "description" in error.schema: |
| 485 | + title, description = error.schema["description"].split("\n", maxsplit=1) |
483 | 486 | error_message += f"\n\n {colorize('Hint:', bold=True)} {title}\n\n" |
484 | 487 | error_message += textwrap.indent(description, prefix=" " * 7) |
485 | 488 |
|
|
0 commit comments