예제 #1
0
    def remove_whitelisted_items_from_file(file_content: str, secrets_white_list: set) -> str:
        """Removes whitelisted items from file content

        Arguments:
            file_content (str): The content of the file to remove the whitelisted item from
            secrets_white_list (set): List of whitelist items to remove from the file content.

        Returns:
            str: The file content with the whitelisted items removed.
        """
        for item in secrets_white_list:
            try:
                file_content = re.sub(WHILEIST_REGEX.format(re.escape(item)), '', file_content)
            except re.error as err:
                error_string = f"Could not use secrets with item: {item}"
                print_error(error_string)
                raise re.error(error_string, str(err))
        return file_content
예제 #2
0
 def remove_white_list_regex(file_contents, secrets_white_list):
     for regex in secrets_white_list:
         file_contents = re.sub(regex, '', file_contents)
     return file_contents