Skip to content

Commit 7f45f68

Browse files
author
Jongmin Kim
authored
Merge pull request #164 from whdalsrnt/master
Refactor Utils
2 parents 7708281 + 5b578aa commit 7f45f68

File tree

1 file changed

+18
-3
lines changed

1 file changed

+18
-3
lines changed

src/spaceone/core/utils.py

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -397,7 +397,11 @@ def _check_condition(match_option: str, val1, val2):
397397

398398

399399
def change_dict_value(
400-
data: dict, dotted_key: str, change_value, change_type="value"
400+
data: dict,
401+
dotted_key: str,
402+
change_value,
403+
change_type="value",
404+
allow_new_key: bool = False,
401405
) -> dict:
402406
# change_value = func or value(any type)
403407
if "." in dotted_key:
@@ -414,19 +418,30 @@ def change_dict_value(
414418
sub_rest = rest.split(".", 1)[1]
415419
list_data.append(
416420
change_dict_value(
417-
sub_data, sub_rest, change_value, change_type
421+
sub_data,
422+
sub_rest,
423+
change_value,
424+
change_type,
425+
allow_new_key=allow_new_key,
418426
)
419427
)
420428
data[key] = list_data
421429
elif isinstance(data[key], dict):
422430
data[key] = change_dict_value(
423-
data[key], rest, change_value, change_type
431+
data[key],
432+
rest,
433+
change_value,
434+
change_type,
435+
allow_new_key=allow_new_key,
424436
)
425437
else:
426438
if dotted_key in data:
427439
data[dotted_key] = _change_value_by_type(
428440
change_type, data[dotted_key], change_value
429441
)
442+
else:
443+
if allow_new_key:
444+
data[dotted_key] = change_value
430445

431446
return data
432447

0 commit comments

Comments
 (0)