-
Notifications
You must be signed in to change notification settings - Fork 18
Expand file tree
/
Copy pathlimpa_segredos.py
More file actions
48 lines (43 loc) · 1.7 KB
/
limpa_segredos.py
File metadata and controls
48 lines (43 loc) · 1.7 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
import os
REPO = r"C:\Users\marce\.config\opencode"
SECRET = "GROQ_API_KEY_REMOVIDO_USE_VARIAVEL_DE_AMBIENTE"
SAFE = "GROQ_API_KEY_REMOVIDO_USE_VARIAVEL_DE_AMBIENTE"
EXTS = {".md", ".txt", ".json", ".py", ".ts", ".js", ".yaml", ".yml", ".toml", ".rst"}
count = 0
for root, dirs, files in os.walk(REPO):
dirs[:] = [d for d in dirs if d != ".git"]
for fname in files:
if os.path.splitext(fname)[1] in EXTS:
path = os.path.join(root, fname)
try:
with open(path, "r", encoding="utf-8", errors="ignore") as f:
content = f.read()
if SECRET in content:
content = content.replace(SECRET, SAFE)
with open(path, "w", encoding="utf-8") as f:
f.write(content)
print(f"[OK] {path.replace(REPO, '')}")
count += 1
except Exception as e:
print(f"[ERRO] {path}: {e}")
print(f"\n{'='*50}")
print(f"Total limpo: {count} arquivo(s)")
print(f"{'='*50}")
# Verificacao final
restantes = 0
for root, dirs, files in os.walk(REPO):
dirs[:] = [d for d in dirs if d != ".git"]
for fname in files:
if os.path.splitext(fname)[1] in EXTS:
path = os.path.join(root, fname)
try:
with open(path, "r", encoding="utf-8", errors="ignore") as f:
if SECRET in f.read():
restantes += 1
print(f"[AINDA CONTEM] {path}")
except:
pass
if restantes == 0:
print("VERIFICACAO OK: nenhum segredo restante nos arquivos.")
else:
print(f"ATENCAO: {restantes} arquivo(s) ainda contem o segredo!")