GitGuardian / ggshield

Find and fix 400+ types of hardcoded secrets and 70+ types of infrastructure-as-code misconfigurations.
https://gitguardian.com
MIT License
1.62k stars 143 forks source link

Introduce GGShieldUI #818

Closed agateau-gg closed 8 months ago

agateau-gg commented 8 months ago

Description

This rather large (sorry) PR introduces GGShieldUI, an abstract class to represent the user-interface while scanning. It has two implementations:

The SecretScannerUI already had a similar design: it now becomes ScannerUI because it works on Scannable, so it can be used by other verticals.

GGShieldUI provides a few ways to show progress:

GGShieldUI also provides display_*() methods to show messages while a progress bar is visible, without them stepping on each others. This is already useful when showing errors while scanning, but is going to also be useful to show rate-limit warnings.

Review

Best reviewed commit-by-commit.

First commit only continues porting more code to the ctx_obj = ContextObj.get(ctx), because it's necessary to introduce GGShieldUI (ContextObj gains a ui attribute storing the GGShieldUI instance).

Second commit does the actual work.

codecov-commenter commented 8 months ago

Codecov Report

Attention: 65 lines in your changes are missing coverage. Please review.

Comparison is base (ae678cf) 92.16% compared to head (be54ae0) 91.58%. Report is 8 commits behind head on main.

Files Patch % Lines
ggshield/core/ui/rich/rich_scanner_ui.py 47.22% 19 Missing :warning:
ggshield/core/ui/rich/rich_ggshield_ui.py 56.41% 17 Missing :warning:
ggshield/core/git_hooks/ci/previous_commit.py 10.00% 9 Missing :warning:
ggshield/cmd/secret/scan/docset.py 25.00% 6 Missing :warning:
...hield/core/ui/plain_text/plain_text_ggshield_ui.py 75.00% 5 Missing :warning:
ggshield/cmd/iac/scan/ci.py 33.33% 2 Missing :warning:
ggshield/cmd/iac/scan/precommit.py 33.33% 2 Missing :warning:
ggshield/verticals/secret/repo.py 50.00% 2 Missing :warning:
ggshield/__main__.py 80.00% 1 Missing :warning:
ggshield/cmd/iac/scan/prereceive.py 0.00% 1 Missing :warning:
... and 1 more

:exclamation: Your organization needs to install the Codecov GitHub app to enable full functionality.

Additional details and impacted files ```diff @@ Coverage Diff @@ ## main #818 +/- ## ========================================== - Coverage 92.16% 91.58% -0.59% ========================================== Files 160 167 +7 Lines 6714 6889 +175 ========================================== + Hits 6188 6309 +121 - Misses 526 580 +54 ``` | [Flag](https://app.codecov.io/gh/GitGuardian/ggshield/pull/818/flags?src=pr&el=flags&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=GitGuardian) | Coverage Δ | | |---|---|---| | [unittests](https://app.codecov.io/gh/GitGuardian/ggshield/pull/818/flags?src=pr&el=flag&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=GitGuardian) | `91.58% <73.79%> (-0.59%)` | :arrow_down: | Flags with carried forward coverage won't be shown. [Click here](https://docs.codecov.io/docs/carryforward-flags?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=GitGuardian#carryforward-flags-in-the-pull-request-comment) to find out more.

:umbrella: View full report in Codecov by Sentry.
:loudspeaker: Have feedback on the report? Share it here.