Skip to content

Instantly share code, notes, and snippets.

@fourirakbar
Last active May 29, 2020 09:48
Show Gist options
  • Select an option

  • Save fourirakbar/64493438311d697d3c00c64bee8488f7 to your computer and use it in GitHub Desktop.

Select an option

Save fourirakbar/64493438311d697d3c00c64bee8488f7 to your computer and use it in GitHub Desktop.
#!/usr/bin/env python3
import sys
import os
import re
precommit_check = sys.argv[1]
def check_secret(secret_file):
for root, dirs, files in os.walk(secret_file):
for file in files:
with open(os.path.join(root, file), "r") as auto:
if ".groovy" in file:
nameFile = root + "/" + file
secret = r'([a-zA-Z0-9]{37}(?![a-zA-Z0-9]))'
with open(nameFile) as f:
for i in re.findall(secret, f.read(), re.DOTALL):
# raise ValueError("Secret detected: " + i + ". File name: " + nameFile)
print("Secret detected: " + i + " || File name: " + nameFile)
# return -1
if __name__ == '__main__':
check_secret(precommit_check)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment