Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(config-parsing): add support for variable expansion for in variables in between string #4350

Merged
merged 25 commits into from
Mar 8, 2022
Merged
Show file tree
Hide file tree
Changes from 22 commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
09441d3
fix(spark-lineage): select mock server port dynamically for unit test
MugdhaHardikar-GSLab Jan 31, 2022
cac9e4b
refactor(spark-lineage): remove dependency of spark from McpEmitter
MugdhaHardikar-GSLab Feb 2, 2022
6f64a20
fix(spark-lineage): fix checkstyle issues
MugdhaHardikar-GSLab Feb 3, 2022
8270c24
fix(spark-lineage): restore consumers
MugdhaHardikar-GSLab Feb 3, 2022
dffa6c4
Merge branch 'linkedin:master' into master
MugdhaHardikar-GSLab Feb 10, 2022
1675dfe
refactor(spark-lineage): enhance logging and documentation
MugdhaHardikar-GSLab Feb 10, 2022
d6583fc
Update McpEmitter.java
MugdhaHardikar-GSLab Feb 10, 2022
8e9291c
add debugging section
MugdhaHardikar-GSLab Feb 10, 2022
7ba4ddf
refactor(spark-lineage): enhance logs
MugdhaHardikar-GSLab Feb 10, 2022
d396664
Merge branch 'spark-logging' of https://github.com/MugdhaHardikar-GSL…
MugdhaHardikar-GSLab Feb 10, 2022
08b51d7
Merge pull request #1 from MugdhaHardikar-GSLab/spark-logging
MugdhaHardikar-GSLab Feb 10, 2022
2c54135
Add https and auth token support
MugdhaHardikar-GSLab Feb 16, 2022
7b8ae31
Merge branch 'linkedin:master' into master
MugdhaHardikar-GSLab Feb 21, 2022
c59bd78
Merge branch 'linkedin:master' into master
MugdhaHardikar-GSLab Feb 25, 2022
aa4b3ef
fix(recipe-parsing): fix recipe config parsing for $
MugdhaHardikar-GSLab Feb 25, 2022
0bb7c81
fix(recipe-parsing): fix parsing for list
MugdhaHardikar-GSLab Feb 25, 2022
78fe124
Delete junit.quick.xml
MugdhaHardikar-GSLab Feb 28, 2022
7a57c96
Merge branch 'linkedin:master' into yml-parsing
MugdhaHardikar-GSLab Mar 7, 2022
8251a13
fix(config-parsing): support for variable expansion for variables in …
MugdhaHardikar-GSLab Mar 8, 2022
63f579e
Merge branch 'yml-parsing' of https://github.com/MugdhaHardikar-GSLab…
MugdhaHardikar-GSLab Mar 8, 2022
c773706
fix(config-parsing): add more test cases
MugdhaHardikar-GSLab Mar 8, 2022
977a881
Merge branch 'linkedin:master' into yml-parsing
MugdhaHardikar-GSLab Mar 8, 2022
4b482bd
fix(config-parsing): add test case for multiple variables in one string
MugdhaHardikar-GSLab Mar 8, 2022
ef91539
Merge branch 'yml-parsing' of https://github.com/MugdhaHardikar-GSLab…
MugdhaHardikar-GSLab Mar 8, 2022
9e8b7f3
adding test to validate missing env var with leading $ is handled cor…
shirshanka Mar 8, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 8 additions & 4 deletions metadata-ingestion/src/datahub/configuration/config_loader.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import io
import pathlib
import re
from typing import Union

from expandvars import UnboundVariable, expandvars
Expand All @@ -10,7 +11,7 @@


def resolve_element(element: str) -> str:
if element.startswith("${") & element.endswith("}"):
if re.search("(\$\{).+(\})", element): # noqa: W605
return expandvars(element, nounset=True)
elif element.startswith("$"):
shirshanka marked this conversation as resolved.
Show resolved Hide resolved
try:
Expand All @@ -28,20 +29,23 @@ def resolve_list(ele_list: list) -> list:
new_v.append(resolve_element(ele)) # type:ignore
elif isinstance(ele, list):
new_v.append(resolve_list(ele)) # type:ignore
elif isinstance(ele, dict):
resolve_env_variables(ele)
shirshanka marked this conversation as resolved.
Show resolved Hide resolved
new_v.append(resolve_env_variables(ele)) # type:ignore
else:
new_v = ele_list
new_v.append(ele)
return new_v


def resolve_env_variables(config: dict) -> None:
def resolve_env_variables(config: dict) -> dict:
for k, v in config.items():
if isinstance(v, dict):
resolve_env_variables(v)
elif isinstance(v, list):
config[k] = resolve_list(v)
elif isinstance(v, str):
config[k] = resolve_element(v)
return None
return config


def load_config_file(config_file: Union[pathlib.Path, str]) -> dict:
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
stuff:
password: ${SOME_PASSWORD
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
---
foo: bar
bar: ${VAR1}
nested:
hi: hello
vanilla_val_1: vanillaValue
vanilla_val_2: vanilla$Value
vanilla_val_3: vanilla${Value
vanilla_val_4: vani}lla${Value
vanilla_val_5: vanillaValue}
vanilla_val_6: vanilla$Value}
password: $VAR2
password_1: ${VAR3}
array:
- one
- two
- ${VAR4}
- three$array
- - in_one
- in_two
- $VAR5
- test_url${VAR6}
- test_url${VAR7}/action
- inner_array:
- in_ar_one
- ${VAR8}
- test_url$vanillavar
- test_url${VAR9}vanillaVar
- \${VAR10}
shirshanka marked this conversation as resolved.
Show resolved Hide resolved


60 changes: 60 additions & 0 deletions metadata-ingestion/tests/unit/config/test_config_loader.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,66 @@
{},
ConfigurationError,
),
(
# Variable expansion error
"tests/unit/config/bad_complex_variable_expansion.yml",
None,
{},
expandvars.MissingClosingBrace,
),
(
"tests/unit/config/complex_variable_expansion.yml",
{
"foo": "bar",
"bar": "stuff1",
"nested": {
"hi": "hello",
"vanilla_val_1": "vanillaValue",
"vanilla_val_2": "vanilla$Value",
"vanilla_val_3": "vanilla${Value",
"vanilla_val_4": "vani}lla${Value",
"vanilla_val_5": "vanillaValue}",
"vanilla_val_6": "vanilla$Value}",
"password": "stuff2",
"password_1": "stuff3",
"array": [
"one",
"two",
"stuff4",
"three$array",
[
"in_one",
"in_two",
"stuff5",
"test_urlstuff6",
"test_urlstuff7/action",
],
{
"inner_array": [
"in_ar_one",
"stuff8",
"test_url$vanillavar",
"test_urlstuff9vanillaVar",
"stuff10",
]
},
],
},
},
{
"VAR1": "stuff1",
"VAR2": "stuff2",
"VAR3": "stuff3",
"VAR4": "stuff4",
"VAR5": "stuff5",
"VAR6": "stuff6",
"VAR7": "stuff7",
"VAR8": "stuff8",
"VAR9": "stuff9",
"VAR10": "stuff10",
},
None,
),
],
)
def test_load(pytestconfig, filename, golden_config, env, error_type):
Expand Down