Download example.py from CobuildX-AI/cbx-secrets-detector-17M: direct link, hf CLI and curl.
- Browser
- Download file 1.32 kB
-
https://huggingface.co/CobuildX-AI/cbx-secrets-detector-17M/resolve/main/example.py
- Command line
-
hf download hf://CobuildX-AI/cbx-secrets-detector-17M/example.py
-
curl -L -o example.py https://huggingface.co/CobuildX-AI/cbx-secrets-detector-17M/resolve/main/example.py
1.32 kB
| """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") | |