mirror of
https://github.com/pre-commit/pre-commit-hooks.git
synced 2026-03-30 10:16:54 +00:00
[pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
This commit is contained in:
parent
72ad6dc953
commit
f4cd1ba0d6
813 changed files with 66015 additions and 58839 deletions
|
|
@ -2,8 +2,8 @@
|
|||
from __future__ import annotations
|
||||
|
||||
import os
|
||||
import sys
|
||||
import re
|
||||
import sys
|
||||
|
||||
|
||||
def detect_gcp_credentials_in_file(file_path):
|
||||
|
|
@ -16,13 +16,13 @@ def detect_gcp_credentials_in_file(file_path):
|
|||
Returns:
|
||||
- list: A list of potential GCP credentials found in the file.
|
||||
"""
|
||||
with open(file_path, "r") as file:
|
||||
with open(file_path) as file:
|
||||
code = file.read()
|
||||
|
||||
# Regular expression patterns for common GCP credential formats
|
||||
credential_patterns = [
|
||||
r"'(AIza[0-9A-Za-z_\-]{35})'", # GCP API Key
|
||||
r"'(-----BEGIN PRIVATE KEY-----[A-Za-z0-9+\/=\n]+-----END PRIVATE KEY-----)'" # GCP Service Account Key
|
||||
r"'(-----BEGIN PRIVATE KEY-----[A-Za-z0-9+\/=\n]+-----END PRIVATE KEY-----)'", # GCP Service Account Key
|
||||
# Add more patterns for other types of GCP credentials as needed
|
||||
]
|
||||
|
||||
|
|
@ -35,6 +35,7 @@ def detect_gcp_credentials_in_file(file_path):
|
|||
|
||||
return credentials
|
||||
|
||||
|
||||
def scan_directory(directory):
|
||||
"""
|
||||
Scan a directory and its subdirectories for Python files and check for potential GCP credentials.
|
||||
|
|
@ -47,11 +48,12 @@ def scan_directory(directory):
|
|||
file_path = os.path.join(root, file_name)
|
||||
gcp_credentials = detect_gcp_credentials_in_file(file_path)
|
||||
if gcp_credentials:
|
||||
print(f"🔴 Potential GCP credentials found in: {file_path}")
|
||||
print("Credentials:")
|
||||
print(f'🔴 Potential GCP credentials found in: {file_path}')
|
||||
print('Credentials:')
|
||||
for credential in gcp_credentials:
|
||||
print(credential)
|
||||
|
||||
|
||||
def main():
|
||||
file_paths = sys.stdin.read().strip().split('\n')
|
||||
|
||||
|
|
@ -61,13 +63,14 @@ def main():
|
|||
|
||||
# Check if any credentials were found
|
||||
if credentials:
|
||||
print("🔴 Potential GCP credentials found:")
|
||||
print('🔴 Potential GCP credentials found:')
|
||||
for credential in credentials:
|
||||
print(credential)
|
||||
print("Please remove these credentials before committing.")
|
||||
print('Please remove these credentials before committing.')
|
||||
return 1 # Abort the commit with a non-zero exit code
|
||||
return 0
|
||||
|
||||
|
||||
# Example usage
|
||||
if __name__ == "__main__":
|
||||
if __name__ == '__main__':
|
||||
raise SystemExit(main())
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue