Skip to content

Commit

Permalink
Add option to ignor mathing kvs in diff utils.
Browse files Browse the repository at this point in the history
  • Loading branch information
albertofori committed Dec 6, 2024
1 parent a287786 commit fcc4d33
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ def __init__(self, src_kvs, compare_fields, preserve_labels=True, label=None, co
kv.label = label

# Returns a diff in the form {"add": List[KeyValue], "delete": List[KeyValue], "update": List[{"new": KeyValue, "old": KeyValue}]}
def compare(self, dest_kvs, strict=False):
def compare(self, dest_kvs, strict=False, ignore_matching_kvs=True):
if not strict and not self._src_kvs:
return {}

Expand All @@ -52,7 +52,7 @@ def compare(self, dest_kvs, strict=False):
kv_diff[JsonDiff.ADD].append(kv)

else:
if not self._kv_equals(kv, dest_kv_lookup[lookup_key], self._compare_fields):
if not (ignore_matching_kvs and self._kv_equals(kv, dest_kv_lookup[lookup_key], self._compare_fields)):
kv_diff[JsonDiff.UPDATE].append({"new": kv, "old": dest_kv_lookup[lookup_key]})

del dest_kv_lookup[lookup_key]
Expand Down
4 changes: 2 additions & 2 deletions src/azure-cli/azure/cli/command_modules/appconfig/keyvalue.py
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ def import_config(cmd,
label=label,
content_type=content_type)

kv_diff = kv_comparer.compare(dest_kvs=dest_kvs, strict=strict)
kv_diff = kv_comparer.compare(dest_kvs=dest_kvs, strict=strict, ignore_matching_kvs=import_mode==ImportMode.IGNORE_MATCH)
# Show indented key-value preview similar to kvset for appconfig source
indent = 2 if source == "appconfig" else None
need_kv_change = print_preview(kv_diff, source, yes=yes, strict=strict, title="Key Values", indent=indent)
Expand All @@ -198,7 +198,7 @@ def import_config(cmd,
compare_fields=CompareFieldsMap[source],
preserve_labels=source == "appconfig" and preserve_labels,
label=label)
ff_diff = ff_comparer.compare(dest_kvs=dest_features, strict=strict)
ff_diff = ff_comparer.compare(dest_kvs=dest_features, strict=strict, ignore_matching_kvs=import_mode==ImportMode.IGNORE_MATCH)
need_feature_change = print_preview(ff_diff, source, yes=yes, strict=strict, title="Feature Flags")

if not need_kv_change and not need_feature_change:
Expand Down

0 comments on commit fcc4d33

Please sign in to comment.