Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[private key plugin] Change analyze_string output dict #15

Merged
merged 2 commits into from
Apr 6, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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