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

Finish migrating to ContextObj #826

Closed agateau-gg closed 8 months ago

agateau-gg commented 8 months ago

Description

This PR finishes the migration to ContextObj. It does two things:

Interesting trivia

Interestingly this pointed out harmless typing errors, for example:

if not scan.success or not isinstance(scan, IaCScanResult):
    handle_scan_error(client, scan)
    return None

pyright complained because the 2nd argument of handle_scan_error() expects a Detail instance, but pyright thought it could be a IaCScanResult. From a typing perspective, it could happen if scan.success was False but isinstance(scan, IaCScanResult) was True. In practice it cannot happen because scan is always a Detail when scan.success is False.

I wondered why it did not complain before, and I realized it's because client was previously defined as client = ctx.obj["client"], so pyright had no idea what type it was. And also had no idea what the return type of client.iac_directory_scan() was.

Now that client is defined as client.ctx_obj.client, pyright knows it's a GGClient instance and thus knows the return type of client.iac_directory_scan().

codecov-commenter commented 8 months ago

Codecov Report

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

Comparison is base (5801d88) 91.61% compared to head (90f582f) 91.59%.

Files Patch % Lines
ggshield/cmd/iac/scan/ci.py 0.00% 4 Missing :warning:
ggshield/cmd/iac/scan/precommit.py 25.00% 3 Missing :warning:
ggshield/cmd/secret/ignore.py 0.00% 3 Missing :warning:
ggshield/cmd/iac/scan/prereceive.py 50.00% 1 Missing :warning:

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

Additional details and impacted files ```diff @@ Coverage Diff @@ ## main #826 +/- ## ========================================== - Coverage 91.61% 91.59% -0.02% ========================================== Files 168 168 Lines 6919 6928 +9 ========================================== + Hits 6339 6346 +7 - Misses 580 582 +2 ``` | [Flag](https://app.codecov.io/gh/GitGuardian/ggshield/pull/826/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/826/flags?src=pr&el=flag&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=GitGuardian) | `91.59% <73.80%> (-0.02%)` | :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.