def find_key_name()

in greengrass-v2/poll-api/artifacts/com.greengrass.GGUtils/1.0.0/GGUtils.py [0:0]


def find_key_name(name, config, name_for_error_message):
    # Look for a key that matches has a key that ends with the expected name with a dot before it or matches exactly.
    #   The dot notation indicates that the config value is from another component.
    value = {key: value for (key, value) in config.items() if key.endswith(f".{name}") or key == name}

    if value is None:
        raise ValueError(f"Could not find key {name} - {name_for_error_message}")

    if len(value) > 1:
        raise ValueError(f"Multiple values found for {name} - {name_for_error_message}")

    # Return the actual name of the variable
    return list(value.keys())[0]