Skip to content

Commit

Permalink
Review fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
LouisTrezzini committed Jul 10, 2018
1 parent f31080b commit 8842526
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 8 deletions.
11 changes: 11 additions & 0 deletions detect_secrets/plugins/core/yaml_file_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,17 @@ def _create_key_value_pair_for_mapping_node_value(key, value, tag):
)

def get_ignored_lines(self):
"""
Return a set of integers that refer to line numbers that were
whitelisted by the user and should be ignored.
We need to parse the file separately from PyYAML parsing because
the parser drops the comments (at least up to version 3.13):
https://github.com/yaml/pyyaml/blob/a2d481b8dbd2b352cb001f07091ccf669227290f/lib3/yaml/scanner.py#L749
:return: set
"""

ignored_lines = set()

for line_number, line in enumerate(self.content.split('\n'), 1):
Expand Down
17 changes: 9 additions & 8 deletions detect_secrets/plugins/high_entropy_strings.py
Original file line number Diff line number Diff line change
Expand Up @@ -160,15 +160,16 @@ def _analyze_yaml_file(self, file, filename):
item = to_search.pop()

try:
if '__line__' in item and not item['__line__'] in ignored_lines:
potential_secrets.update(
self.analyze_string(
item['__value__'],
item['__line__'],
filename,
),
)

if '__line__' in item:
if not item['__line__'] in ignored_lines:
potential_secrets.update(
self.analyze_string(
item['__value__'],
item['__line__'],
filename,
),
)
continue

for key in item:
Expand Down

0 comments on commit 8842526

Please sign in to comment.