forked from datahub-project/datahub
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(ingest): handle multiline string coercion (datahub-project#9484)
- Loading branch information
Showing
9 changed files
with
86 additions
and
30 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -17,10 +17,8 @@ title: "Local Development" | |
On macOS, these can be installed using [Homebrew](https://brew.sh/). | ||
|
||
```shell | ||
# Install Java 8 and 11 | ||
brew tap homebrew/cask-versions | ||
brew install java11 | ||
brew install --cask zulu8 | ||
# Install Java | ||
brew install openjdk@17 | ||
|
||
# Install Python | ||
brew install [email protected] # you may need to add this to your PATH | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
31 changes: 31 additions & 0 deletions
31
metadata-ingestion/src/datahub/configuration/validate_multiline_string.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
from typing import Optional, Type, Union | ||
|
||
import pydantic | ||
|
||
|
||
def pydantic_multiline_string(field: str) -> classmethod: | ||
"""If the field is present and contains an escaped newline, replace it with a real newline. | ||
This makes the assumption that the field value is never supposed to have a | ||
r"\n" in it, and instead should only have newline characters. This is generally | ||
a safe assumption for SSH keys and similar. | ||
The purpose of this helper is to make us more forgiving of small formatting issues | ||
in recipes, without sacrificing correctness across the board. | ||
""" | ||
|
||
def _validate_field( | ||
cls: Type, v: Union[None, str, pydantic.SecretStr] | ||
) -> Optional[str]: | ||
if v is not None: | ||
if isinstance(v, pydantic.SecretStr): | ||
v = v.get_secret_value() | ||
v = v.replace(r"\n", "\n") | ||
|
||
return v | ||
|
||
# Hack: Pydantic maintains unique list of validators by referring its __name__. | ||
# https://github.com/pydantic/pydantic/blob/v1.10.9/pydantic/main.py#L264 | ||
# This hack ensures that multiple field deprecated do not overwrite each other. | ||
_validate_field.__name__ = f"{_validate_field.__name__}_{field}" | ||
return pydantic.validator(field, pre=True, allow_reuse=True)(_validate_field) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters