Skip to content

Commit

Permalink
Merge branches 'master' and 'pack_content_creator_fix' of github.com:…
Browse files Browse the repository at this point in the history
…demisto/demisto-sdk into pack_content_creator_fix
  • Loading branch information
IkaDemisto committed Apr 16, 2020
2 parents 78db060 + 67695a6 commit 1f2123e
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 6 deletions.
19 changes: 14 additions & 5 deletions demisto_sdk/commands/secrets/secrets.py
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ def search_potential_secrets(self, secrets_file_paths: list, ignore_entropy: boo
file_contents = self.get_file_contents(file_path, file_extension)
# in packs regard all items as regex as well, reset pack's whitelist in order to avoid repetition later
if is_pack:
file_contents = self.remove_white_list_regex(file_contents, secrets_white_list)
file_contents = self.remove_whitelisted_items_from_file(file_contents, secrets_white_list)

yml_file_contents = self.get_related_yml_contents(file_path)
# Add all context output paths keywords to whitelist temporary
Expand Down Expand Up @@ -211,10 +211,19 @@ def search_potential_secrets(self, secrets_file_paths: list, ignore_entropy: boo
return secrets_found

@staticmethod
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
def remove_whitelisted_items_from_file(file_content: str, secrets_white_list: list) -> 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 (list): 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:
file_content = file_content.replace(item, '')
return file_content

@staticmethod
def create_temp_white_list(file_contents):
Expand Down
2 changes: 1 addition & 1 deletion demisto_sdk/commands/secrets/tests/secrets_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ def test_remove_white_list_regex(self):
shmoop
155.165.45.232
'''
file_contents = self.validator.remove_white_list_regex(white_list, file_contents)
file_contents = self.validator.remove_whitelisted_items_from_file(white_list, file_contents)
assert white_list not in file_contents

def test_temp_white_list(self):
Expand Down

0 comments on commit 1f2123e

Please sign in to comment.