mirror of
https://github.com/pre-commit/pre-commit-hooks.git
synced 2026-04-12 14:04:17 +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`
|
#### `detect-private-key`
|
||||||
Checks for the existence of private keys.
|
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`
|
#### `double-quote-string-fixer`
|
||||||
This hook replaces double quoted strings with single quoted strings.
|
This hook replaces double quoted strings with single quoted strings.
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -20,14 +20,24 @@ BLACKLIST = [
|
||||||
def main(argv: Sequence[str] | None = None) -> int:
|
def main(argv: Sequence[str] | None = None) -> int:
|
||||||
parser = argparse.ArgumentParser()
|
parser = argparse.ArgumentParser()
|
||||||
parser.add_argument('filenames', nargs='*', help='Filenames to check')
|
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)
|
args = parser.parse_args(argv)
|
||||||
|
|
||||||
private_key_files = []
|
private_key_files = []
|
||||||
|
whitelisted_files = ''
|
||||||
|
|
||||||
|
if args.whitelist:
|
||||||
|
with open(args.whitelist) as f:
|
||||||
|
whitelisted_files = f.read()
|
||||||
|
|
||||||
for filename in args.filenames:
|
for filename in args.filenames:
|
||||||
with open(filename, 'rb') as f:
|
with open(filename, 'rb') as f:
|
||||||
content = f.read()
|
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)
|
private_key_files.append(filename)
|
||||||
|
|
||||||
if private_key_files:
|
if private_key_files:
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue