Skip to content

Commit 16d54fd

Browse files
[pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
1 parent 8f9d35b commit 16d54fd

File tree

2 files changed

+19
-21
lines changed

2 files changed

+19
-21
lines changed

.pre-commit-hooks.yaml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -216,4 +216,3 @@
216216
description: can take in a custom regex file to scan for custom secrets.
217217
entry: detect-secrets
218218
langauge: python
219-

pre_commit_hooks/detect_secrets.py

Lines changed: 19 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -13,41 +13,40 @@
1313

1414
DEFAULT_PATTERNS: dict[str, str] = {
1515
# GitLab
16-
"gitlab_pat": r"glpat-[0-9A-Za-z_-]{20,}",
17-
"gitlab_runner_token": r"glrt-[0-9A-Za-z_-]{20,}",
16+
'gitlab_pat': r'glpat-[0-9A-Za-z_-]{20,}',
17+
'gitlab_runner_token': r'glrt-[0-9A-Za-z_-]{20,}',
1818

1919
# GitHub
20-
"github_pat": r"ghp_[0-9A-Za-z]{36}",
21-
"github_fine_grained_pat": r"github_pat_[0-9A-Za-z_]{82}",
20+
'github_pat': r'ghp_[0-9A-Za-z]{36}',
21+
'github_fine_grained_pat': r'github_pat_[0-9A-Za-z_]{82}',
2222

2323
# AWS
24-
"aws_access_key": r"AKIA[0-9A-Z]{16}",
25-
"aws_secret_key": r"(?i)aws(.{0,20})?(secret|access)[-_ ]?key(.{0,20})?['\"][0-9a-zA-Z/+]{40}['\"]",
24+
'aws_access_key': r'AKIA[0-9A-Z]{16}',
25+
'aws_secret_key': r"(?i)aws(.{0,20})?(secret|access)[-_ ]?key(.{0,20})?['\"][0-9a-zA-Z/+]{40}['\"]",
2626

2727
# Generic
28-
"generic_secret": r"(?i)(password|passwd|pwd|secret|token|api[_-]?key)\s*=\s*['\"].+['\"]",
28+
'generic_secret': r"(?i)(password|passwd|pwd|secret|token|api[_-]?key)\s*=\s*['\"].+['\"]",
2929
}
3030

3131

32-
3332
def load_custom_patterns(path: Path) -> dict[str, str]:
3433
patterns: dict[str, str] = {}
3534
for i, line in enumerate(path.read_text().splitlines(), start=1):
3635
line = line.strip()
37-
if not line or line.startswith("#"):
36+
if not line or line.startswith('#'):
3837
continue
3938
patterns[f"custom_rule_{i}"] = line
4039
return patterns
4140

4241

4342
def is_binary(data: bytes) -> bool:
44-
return b"\x00" in data
43+
return b'\x00' in data
4544

4645

4746
def git_tracked_files() -> list[Path]:
4847
"""Return all git-tracked files in the repo."""
4948
result = subprocess.run(
50-
["git", "ls-files"],
49+
['git', 'ls-files'],
5150
stdout=subprocess.PIPE,
5251
stderr=subprocess.DEVNULL,
5352
text=True,
@@ -57,16 +56,16 @@ def git_tracked_files() -> list[Path]:
5756

5857

5958
def main(argv: Sequence[str] | None = None) -> int:
60-
parser = argparse.ArgumentParser(description="Detect exposed secrets in repository")
59+
parser = argparse.ArgumentParser(description='Detect exposed secrets in repository')
6160
parser.add_argument(
62-
"--rules",
61+
'--rules',
6362
type=Path,
64-
help="File containing custom regex rules (one per line)",
63+
help='File containing custom regex rules (one per line)',
6564
)
6665
parser.add_argument(
67-
"filenames",
68-
nargs="*",
69-
help="Files to scan (if empty, scans entire repo)",
66+
'filenames',
67+
nargs='*',
68+
help='Files to scan (if empty, scans entire repo)',
7069
)
7170

7271
args = parser.parse_args(argv)
@@ -104,20 +103,20 @@ def main(argv: Sequence[str] | None = None) -> int:
104103
if is_binary(data):
105104
continue
106105

107-
text = data.decode(errors="ignore")
106+
text = data.decode(errors='ignore')
108107

109108
for rule, regex in compiled.items():
110109
if regex.search(text):
111110
findings.append((path, rule))
112111

113112
if findings:
114-
print("Potential secrets detected:")
113+
print('Potential secrets detected:')
115114
for path, rule in findings:
116115
print(f" - {path} (matched: {rule})")
117116
return 1
118117

119118
return 0
120119

121120

122-
if __name__ == "__main__":
121+
if __name__ == '__main__':
123122
raise SystemExit(main())

0 commit comments

Comments
 (0)