stac-utils / pystac-client

Python client for searching STAC APIs
https://pystac-client.readthedocs.io
Other
161 stars 48 forks source link

Verify requests with REQUESTS_CA_BUNDLE if set #665

Closed thwllms closed 6 months ago

thwllms commented 6 months ago

Related Issue(s):

Description: By default, the basic requests.get, requests.post, etc., functions look for an environment variable REQUESTS_CA_BUNDLE (see docs), which can point to a custom certificate bundle file instead of the default bundle provided with certifi. This is common practice in e.g., corporate settings where HTTPS inspection is being performed with SSL certificate replacement, causing HTTPS responses with odd-looking certificates. This PR ensures that pystac-client also respects the REQUESTS_CA_BUNDLE environment variable.

PR Checklist:

codecov-commenter commented 6 months ago

Codecov Report

Attention: Patch coverage is 80.00000% with 1 lines in your changes are missing coverage. Please review.

Project coverage is 93.68%. Comparing base (21435b0) to head (c1a234c). Report is 20 commits behind head on main.

Files Patch % Lines
pystac_client/stac_api_io.py 80.00% 1 Missing :warning:
Additional details and impacted files ```diff @@ Coverage Diff @@ ## main #665 +/- ## ========================================== + Coverage 93.43% 93.68% +0.24% ========================================== Files 13 13 Lines 990 997 +7 ========================================== + Hits 925 934 +9 + Misses 65 63 -2 ```

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

thwllms commented 6 months ago

Updated to include fallback to CURL_CA_BUNDLE if REQUESTS_CA_BUNDLE isn't set, following the pattern in requests. https://github.com/psf/requests/blob/2a438c27b5a5828c8ea0dc958112eecffca70b12/src/requests/sessions.py#L767

thwllms commented 6 months ago

@thwllms thanks for the PR! When reviewing, it felt like we should try to use requests's environment lookup if possible. I've opened #669 with an alternate solution, let me know what you think.

Ah, I totally missed merge_environment_settings when I was going through the docs! I like that solution better. 👍

thwllms commented 6 months ago

Closing in favor of #669