mirror of
https://github.com/pre-commit/pre-commit-hooks.git
synced 2026-04-01 02:56:52 +00:00
feat: add whitelist support for detect-privat-key hook
This commit is contained in:
parent
6336b8e792
commit
706b591462
2 changed files with 19 additions and 1 deletions
|
|
@ -108,6 +108,14 @@ The following arguments are available:
|
|||
#### `detect-private-key`
|
||||
Checks for the existence of private keys.
|
||||
|
||||
The following arguments are available:
|
||||
- `--whitelist` - the filename with with the files (relative path) to whitelist. For example:
|
||||
|
||||
```yaml
|
||||
- id: detect-private-key
|
||||
args: [--whitelist=.detect-private-key.whitelist]
|
||||
```
|
||||
|
||||
#### `double-quote-string-fixer`
|
||||
This hook replaces double quoted strings with single quoted strings.
|
||||
|
||||
|
|
|
|||
|
|
@ -20,14 +20,24 @@ BLACKLIST = [
|
|||
def main(argv: Sequence[str] | None = None) -> int:
|
||||
parser = argparse.ArgumentParser()
|
||||
parser.add_argument('filenames', nargs='*', help='Filenames to check')
|
||||
parser.add_argument(
|
||||
'--whitelist',
|
||||
help='The filename with with the files (relative path) to whitelist',
|
||||
)
|
||||
args = parser.parse_args(argv)
|
||||
|
||||
private_key_files = []
|
||||
whitelisted_files = ''
|
||||
|
||||
if args.whitelist:
|
||||
with open(args.whitelist) as f:
|
||||
whitelisted_files = f.read()
|
||||
|
||||
for filename in args.filenames:
|
||||
with open(filename, 'rb') as f:
|
||||
content = f.read()
|
||||
if any(line in content for line in BLACKLIST):
|
||||
if any(line in content for line in BLACKLIST) \
|
||||
and filename not in whitelisted_files:
|
||||
private_key_files.append(filename)
|
||||
|
||||
if private_key_files:
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue