GitGuardian / ggshield

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

Refactor oauth code: simplify request handling #847

Closed agateau-gg closed 5 months ago

agateau-gg commented 5 months ago

This PR simplifies OAuthClient code.

RequestHandler is no longer an inner class. This was required for it to get access to the RequestHandlerWrapper instance creating it, but this made the code hard to read.

This commit changes this by:

  1. Removing RequestHandlerWrapper: its complete and error_message attributes have been moved to OAuthClient as _request_finished and _request_error_message.

  2. Making RequestHandler.__init__() take an OAuthClient instance in addition to the arguments it already accepts.

  3. Making RequestHandler update the new OAuthClient attributes added in 1)

  4. Passing to HTTPServer a partial of RequestHandler class, initialized with the OAuthClient instance.

codecov-commenter commented 5 months ago

Codecov Report

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

Comparison is base (278fdcc) 91.90% compared to head (16324d7) 91.89%.

Files Patch % Lines
ggshield/verticals/auth/oauth.py 25.58% 32 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 #847 +/- ## ========================================== - Coverage 91.90% 91.89% -0.01% ========================================== Files 168 168 Lines 6991 6984 -7 ========================================== - Hits 6425 6418 -7 Misses 566 566 ``` | [Flag](https://app.codecov.io/gh/GitGuardian/ggshield/pull/847/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/847/flags?src=pr&el=flag&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=GitGuardian) | `91.89% <25.58%> (-0.01%)` | :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.