secretshield 0.2.1__tar.gz → 0.3.1__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (37) hide show
  1. {secretshield-0.2.1 → secretshield-0.3.1}/PKG-INFO +137 -2
  2. secretshield-0.2.1/secretshield.egg-info/PKG-INFO → secretshield-0.3.1/README.md +490 -380
  3. {secretshield-0.2.1 → secretshield-0.3.1}/pyproject.toml +1 -1
  4. {secretshield-0.2.1 → secretshield-0.3.1}/secretshield/__init__.py +1 -1
  5. secretshield-0.3.1/secretshield/autofix/__init__.py +7 -0
  6. secretshield-0.3.1/secretshield/autofix/env.py +73 -0
  7. secretshield-0.3.1/secretshield/autofix/fixer.py +273 -0
  8. secretshield-0.3.1/secretshield/autofix/gitignore.py +32 -0
  9. secretshield-0.3.1/secretshield/autofix/python.py +161 -0
  10. {secretshield-0.2.1 → secretshield-0.3.1}/secretshield/cli.py +219 -14
  11. secretshield-0.3.1/secretshield/git/__init__.py +21 -0
  12. secretshield-0.3.1/secretshield/git/hooks.py +236 -0
  13. secretshield-0.3.1/secretshield/github/__init__.py +7 -0
  14. secretshield-0.3.1/secretshield/github/actions.py +58 -0
  15. secretshield-0.2.1/README.md → secretshield-0.3.1/secretshield.egg-info/PKG-INFO +515 -355
  16. {secretshield-0.2.1 → secretshield-0.3.1}/secretshield.egg-info/SOURCES.txt +14 -1
  17. secretshield-0.3.1/tests/test_autofix.py +335 -0
  18. secretshield-0.3.1/tests/test_git_hooks.py +146 -0
  19. secretshield-0.3.1/tests/test_github_action.py +58 -0
  20. {secretshield-0.2.1 → secretshield-0.3.1}/tests/test_scan.py +42 -0
  21. secretshield-0.3.1/tests/test_v030_cli_integration.py +162 -0
  22. {secretshield-0.2.1 → secretshield-0.3.1}/LICENSE +0 -0
  23. {secretshield-0.2.1 → secretshield-0.3.1}/secretshield/config.py +0 -0
  24. {secretshield-0.2.1 → secretshield-0.3.1}/secretshield/detector.py +0 -0
  25. {secretshield-0.2.1 → secretshield-0.3.1}/secretshield/guardian.py +0 -0
  26. {secretshield-0.2.1 → secretshield-0.3.1}/secretshield/notifications.py +0 -0
  27. {secretshield-0.2.1 → secretshield-0.3.1}/secretshield/patterns.py +0 -0
  28. {secretshield-0.2.1 → secretshield-0.3.1}/secretshield/redactor.py +0 -0
  29. {secretshield-0.2.1 → secretshield-0.3.1}/secretshield.egg-info/dependency_links.txt +0 -0
  30. {secretshield-0.2.1 → secretshield-0.3.1}/secretshield.egg-info/entry_points.txt +0 -0
  31. {secretshield-0.2.1 → secretshield-0.3.1}/secretshield.egg-info/requires.txt +0 -0
  32. {secretshield-0.2.1 → secretshield-0.3.1}/secretshield.egg-info/top_level.txt +0 -0
  33. {secretshield-0.2.1 → secretshield-0.3.1}/setup.cfg +0 -0
  34. {secretshield-0.2.1 → secretshield-0.3.1}/tests/test_detector.py +0 -0
  35. {secretshield-0.2.1 → secretshield-0.3.1}/tests/test_logging.py +0 -0
  36. {secretshield-0.2.1 → secretshield-0.3.1}/tests/test_redactor.py +0 -0
  37. {secretshield-0.2.1 → secretshield-0.3.1}/tests/test_stdout.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: secretshield
3
- Version: 0.2.1
3
+ Version: 0.3.1
4
4
  Summary: Detect and redact likely secrets before they reach Python's terminal output or logging system.
5
5
  Author: Samarth Chugh (Sam3360)
6
6
  License-Expression: MIT
@@ -57,6 +57,15 @@ exactly that class of mistake during local development and debugging.
57
57
  It is **not** a replacement for secret management, code review, or
58
58
  static-analysis security tooling — see [Limitations](#limitations) below.
59
59
 
60
+ ## 🎥 Demo
61
+
62
+ See SecretShield in action:
63
+
64
+ [![SecretShield Demo](https://img.youtube.com/vi/g95lNIhWsXM/maxresdefault.jpg)](https://youtu.be/g95lNIhWsXM)
65
+
66
+ **▶️ [Watch the full demo on YouTube](https://youtu.be/g95lNIhWsXM)**
67
+
68
+
60
69
  ## Installation
61
70
 
62
71
  ```bash
@@ -265,6 +274,110 @@ secretshield.configure(
265
274
 
266
275
  Sensible defaults mean most projects need zero configuration.
267
276
 
277
+ ## Auto-Fix -- moving secrets into `.env`
278
+
279
+ ```bash
280
+ secretshield scan . --fix
281
+ ```
282
+
283
+ `--fix` adds an *interactive* repair step on top of the normal scan.
284
+ For each detected secret, SecretShield asks whether to move it into a
285
+ local `.env` file:
286
+
287
+ ```text
288
+ Secret 1/1 detected
289
+ File: app.py
290
+ Line: 5
291
+ Detected value: ********
292
+
293
+ Would you like me to move this secret to a local .env file automatically? [y/N]
294
+ ```
295
+
296
+ If you confirm, this:
297
+
298
+ ```python
299
+ API_KEY = "actual-secret-value"
300
+ ```
301
+
302
+ becomes:
303
+
304
+ ```python
305
+ import os
306
+
307
+ API_KEY = os.getenv("API_KEY")
308
+ ```
309
+
310
+ with the real value moved into `.env` (created if missing, and never
311
+ overwritten -- new variables are only ever appended), `.gitignore`
312
+ updated to exclude `.env` if it isn't already, and `.env.example`
313
+ updated with a blank placeholder (`API_KEY=`, never the real value) so
314
+ you can safely commit the example file.
315
+
316
+ **Auto-Fix is conservative by design.** It only rewrites Python, and
317
+ only lines that are unambiguously a simple assignment --
318
+ `API_KEY = "..."`. Anything less certain -- a value inside a dict, an
319
+ f-string, a function call argument, a non-Python file -- is reported
320
+ but left untouched:
321
+
322
+ ```text
323
+ Secret detected, but SecretShield could not safely determine how to
324
+ replace it automatically.
325
+
326
+ No changes were made.
327
+ ```
328
+
329
+ Every fix is validated after being written (confirming the secret is
330
+ gone from the source and present in `.env`); if anything about a fix
331
+ fails, that file is rolled back to its original content rather than
332
+ left half-modified. `--fix` only prompts in a real interactive
333
+ terminal -- in CI or any non-interactive environment, it makes no
334
+ changes and does not hang waiting for input.
335
+
336
+ ## Git pre-commit hook
337
+
338
+ ```bash
339
+ secretshield install-hook
340
+ ```
341
+
342
+ Installs a hook that scans **staged file contents** (not the whole
343
+ working tree, and not what's merely on disk if you've only partially
344
+ staged a file) before every commit, blocking it if a likely secret is
345
+ found:
346
+
347
+ ```text
348
+ SecretShield: scanning staged files...
349
+
350
+ ✗ Potential secret detected
351
+
352
+ File: config.py
353
+ Line: 14
354
+ Type: API token
355
+
356
+ Commit blocked.
357
+
358
+ Remove the secret from the staged changes and try again.
359
+ ```
360
+
361
+ If a `pre-commit` hook already exists, SecretShield never overwrites
362
+ it: the original is backed up to `pre-commit.secretshield-backup` and
363
+ wrapped so both run on every commit. Remove SecretShield's hook (and
364
+ automatically restore any hook it wrapped) with:
365
+
366
+ ```bash
367
+ secretshield uninstall-hook
368
+ ```
369
+
370
+ ## GitHub Actions
371
+
372
+ ```bash
373
+ secretshield github-action
374
+ ```
375
+
376
+ Generates `.github/workflows/secretshield.yml`, a workflow that installs
377
+ SecretShield and runs `secretshield scan .` on every push and pull
378
+ request, failing the check if a potential secret is found. Won't
379
+ overwrite an existing workflow file unless you pass `--force`.
380
+
268
381
  ## Detection methods
269
382
 
270
383
  `secretshield` combines two strategies:
@@ -291,7 +404,16 @@ secretshield/
291
404
  ├── config.py # configure()/get_config(): runtime settings
292
405
  ├── notifications.py # safe, secret-free console/desktop warnings
293
406
  ├── guardian.py # stdout/stderr wrapping + logging record-factory hook
294
- └── cli.py # `secretshield` command-line entry point
407
+ ├── cli.py # `secretshield` command-line entry point
408
+ ├── autofix/ # interactive scan --fix
409
+ │ ├── fixer.py # orchestration, atomic writes, rollback
410
+ │ ├── python.py # ast-based safe-assignment detection
411
+ │ ├── env.py # safe .env / .env.example handling
412
+ │ └── gitignore.py # ensures .env stays out of Git
413
+ ├── git/ # pre-commit hook install/uninstall
414
+ │ └── hooks.py
415
+ └── github/ # GitHub Actions workflow generation
416
+ └── actions.py
295
417
  ```
296
418
 
297
419
  Key design points:
@@ -352,6 +474,19 @@ local exposure during development and debugging — not as a substitute
352
474
  for proper secret management (vaults, environment isolation, `.gitignore`
353
475
  discipline, secret scanning in CI, least-privilege credentials, etc.).
354
476
 
477
+ **Auto-Fix (`--fix`)** only rewrites Python, and only when a line is
478
+ unambiguously a simple `NAME = "value"` assignment (checked via Python's
479
+ own `ast` module, not a regex). Secrets inside dicts, f-strings,
480
+ function-call arguments, or any other language are reported but never
481
+ automatically rewritten — you'll need to fix those by hand.
482
+
483
+ **The pre-commit hook** invokes the `secretshield` command by name, so
484
+ it needs to be resolvable on `PATH` at commit time. If you installed
485
+ SecretShield inside a virtual environment, make sure that environment
486
+ is active (or `secretshield` is otherwise on `PATH`) whenever you run
487
+ `git commit` — otherwise the hook itself will fail to run rather than
488
+ silently skip the scan.
489
+
355
490
  ## Security considerations
356
491
 
357
492
  * secretshield performs **no network calls** and collects **no