Skip to content

Commit

Permalink
Merge pull request #15 from Yelp/14_fix_private_key_analyze_string
Browse files Browse the repository at this point in the history
[private key plugin] Change analyze_string output dict
  • Loading branch information
KevinHock committed Apr 6, 2018
2 parents afe6f0b + 1925cdb commit ccc60fd
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 6 deletions.
14 changes: 9 additions & 5 deletions detect_secrets/plugins/private_key.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,14 @@ class PrivateKeyDetector(BasePlugin):
def analyze(self, file, filename):
"""We override this, because we're only looking at the first line.
Though this doesn't strictly follow the schema of the parent function,
all that really matters is that each secret within this file scanned
has a unique key. Since we're only expecting at most one secret from
this file, by definition any key is a unique key, so we good.
:param file: The File object itself.
:param filename: string; filename of File object, used for creating
PotentialSecret objects
:returns dictionary representation of set (for random access by hash)
{ detect_secrets.core.potential_secret.__hash__:
detect_secrets.core.potential_secret }
"""

return self.analyze_string(
file.readline(),
1,
Expand All @@ -40,11 +43,12 @@ def analyze_string(self, string, line_num, filename):
output = {}

if any(line in string for line in BLACKLIST):
output[filename] = PotentialSecret(
secret = PotentialSecret(
self.secret_type,
filename,
line_num,
string,
)
output[secret] = secret

return output
5 changes: 4 additions & 1 deletion tests/plugins/private_key_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,7 @@ def test_analyze(self):
)

f = create_file_object_from_string(file_content)
assert 'mock_filename' in logic.analyze(f, 'mock_filename')
output = logic.analyze(f, 'mock_filename')
assert len(output) == 1
for potential_secret in output:
assert 'mock_filename' == potential_secret.filename

0 comments on commit ccc60fd

Please sign in to comment.