File size: 1,323 Bytes
89362a0
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
"""Check the install: find and redact secrets in four sample texts.

    python example.py

Every value below is invented: random characters in the shapes real services use. None is a working credential.
"""
from cbx_secrets import SecretDetector

SAMPLES = [
    "DATABASE_URL=postgres://app_user:Vq7mR2xL9pTz@db.internal.example:5432/orders\n"
    "STRIPE_SECRET_KEY=sk_live_4eC39HqLyjWDarjtT1zdp7dcQw8vXk2Z\n"
    "LOG_LEVEL=info\n",
    'import boto3\n\n'
    's3 = boto3.client("s3", aws_access_key_id="AKIAQ3W7RNA2FDX5KZPM",\n'
    '                  aws_secret_access_key="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")\n',
    'Hey, the deploy is failing again. I used `curl -H "Authorization: Bearer ghp_8xK2mQ9vL4nR7tY1wZ3pB6cF0hJ5sD2gA9eU"`\n'
    "and got a 401. The commit is 3f9a1c2e7b4d8f6a0e5c9b2d1a7f4e8c6b3d0a9f if that helps.",
    'jwt_secret: "Zr8!kP2qW9xM4vT7nL1sB6yH3cF0gJ5d"\n'
    "session_cookie_name: app_session\n"
    'api_key: "${API_KEY}"   # read from the environment\n',
]

det = SecretDetector()
print(f"model loaded on {det.device}\n")
for text in SAMPLES:
    spans, ms = det.timed_extract(text)
    print(text)
    for s in spans:
        print(f"   {s['label']:20} {s['text']!r}  [{s['start']}:{s['end']}]")
    print(f"   redacted: {det.redact(text)!r}")
    print(f"   ({ms:.0f} ms)\n")