Skip to content

Refactor Utils #164

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

Merged
merged 2 commits into from
Jan 16, 2025
Merged
Changes from all commits
Commits
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
21 changes: 18 additions & 3 deletions src/spaceone/core/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -397,7 +397,11 @@ def _check_condition(match_option: str, val1, val2):


def change_dict_value(
data: dict, dotted_key: str, change_value, change_type="value"
data: dict,
dotted_key: str,
change_value,
change_type="value",
allow_new_key: bool = False,
) -> dict:
# change_value = func or value(any type)
if "." in dotted_key:
Expand All @@ -414,19 +418,30 @@ def change_dict_value(
sub_rest = rest.split(".", 1)[1]
list_data.append(
change_dict_value(
sub_data, sub_rest, change_value, change_type
sub_data,
sub_rest,
change_value,
change_type,
allow_new_key=allow_new_key,
)
)
data[key] = list_data
elif isinstance(data[key], dict):
data[key] = change_dict_value(
data[key], rest, change_value, change_type
data[key],
rest,
change_value,
change_type,
allow_new_key=allow_new_key,
)
else:
if dotted_key in data:
data[dotted_key] = _change_value_by_type(
change_type, data[dotted_key], change_value
)
else:
if allow_new_key:
data[dotted_key] = change_value

return data

Expand Down
Loading