Aliases - Bulk update

Hi everyone,

i wan't to bulk update all aliases in a certain vault, i did that using the AliasUpdate from UnitFly, but there is one problem, what about all the rules that are using aliases as definitions?

I'm having alot of unresolved rules because of that (good thing i did that on a development vault Slight smile). 

The way i tried to update all of this is as follows:

Get the whole json metadata file and get a json file with updated aliases. Then i can use python script with fuzzy search and update the whole metadata card using that script, but some of the aliases before had different values than the updated ones (for example the first name of state when it was created was "A", but it was after renamed into "B" without manually changing the alias). 

Because of that i cant use the python script to fully update the whole metadata, is there a different way how i can update aliases and that those aliases are updated in metadata configuration, property calculator, compliance kit and other applications?

BTW Here is the python script if someone had a similar issue, but they have similar alias names so they can resolve unresolved rules. Slight smile

import json
from fuzzywuzzy import process, fuzz

# Define file paths
correct_aliases_path = 'C://test//New_Aliases.json'
metadata_path = 'C://test//Current_Metadata.json'
corrected_metadata_path = 'C://test//Corrected_Metadata.json'

# Load the list of correct aliases
with open(correct_aliases_path, 'r', encoding='utf-8') as file:
    correct_aliases = json.load(file)

# Function to find the closest match with a threshold
def find_closest(alias, choices, threshold=90):

    highest = process.extractOne(str(alias), choices, scorer=fuzz.ratio)
    if highest[1] >= threshold:
        return highest[0]
    else:
        return alias

# Recursive function to update properties
def update_properties(data, correct_aliases):
    if isinstance(data, dict):
        for key, value in data.items():
            if key == 'Property' and isinstance(value, str):
                data[key] = find_closest(value, correct_aliases)
            else:
                update_properties(value, correct_aliases)
    elif isinstance(data, list):
        for item in data:
            update_properties(item, correct_aliases)

# Load the Metadata.json file
with open(metadata_path, 'r', encoding='utf-8') as file:
    metadata = json.load(file)

# Update properties recursively
update_properties(metadata, correct_aliases)

# Save the corrected metadata back to a file
with open(corrected_metadata_path, 'w', encoding='utf-8') as file:
    json.dump(metadata, file, ensure_ascii=False, indent=4)

print("Finished processing.")

Parents Reply Children
No Data