Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add a mechanism for adding headers to StacIO requests #889

Merged
merged 4 commits into from
Oct 13, 2022

Conversation

john-dupuy
Copy link
Contributor

@john-dupuy john-dupuy commented Sep 23, 2022

Related Issue(s): #886

Description:
This PR aims to address #886 by adding a mechanism for adding headers for StacIO requests.

The suggested approach for using this:

from pystac import StacIO
stac_io = StacIO.default()
stac_io.headers = {"Authorization": "<some-authn-header>"}

catalog = Catalog.from_file("<some-href-that-requires-authn>", stac_io=stac_io)

You could also just directly instantiate the StacIO or DefaultStacIO class, with headers included as an arg.

PR Checklist:

  • Code is formatted (run pre-commit run --all-files)
  • Tests pass (run scripts/test)
  • Documentation has been updated to reflect changes, if applicable
  • This PR maintains or improves overall codebase code coverage.
  • Changes are added to the CHANGELOG. See the docs for information about adding to the changelog.

@john-dupuy john-dupuy marked this pull request as draft September 23, 2022 22:50
@john-dupuy john-dupuy marked this pull request as ready for review September 26, 2022 15:42
@john-dupuy john-dupuy changed the title Draft: Add a mechanism for adding headers to StacIO requests Add a mechanism for adding headers to StacIO requests Sep 26, 2022
@john-dupuy
Copy link
Contributor Author

@gadomski can you take a look?

@gadomski
Copy link
Member

gadomski commented Sep 28, 2022

@gadomski can you take a look?

Yes, it's in my queue, thanks for the bump. Right now I'm working on PySTAC issues in my off time so responses may be a bit slower, apologies.

@gadomski gadomski self-requested a review October 10, 2022 20:19
@codecov-commenter
Copy link

Codecov Report

Base: 94.29% // Head: 94.31% // Increases project coverage by +0.01% 🎉

Coverage data is based on head (7bd8605) compared to base (8b2a540).
Patch coverage: 100.00% of modified lines in pull request are covered.

Additional details and impacted files
@@            Coverage Diff             @@
##             main     #889      +/-   ##
==========================================
+ Coverage   94.29%   94.31%   +0.01%     
==========================================
  Files          80       80              
  Lines       11909    11922      +13     
  Branches     1130     1130              
==========================================
+ Hits        11230    11244      +14     
  Misses        496      496              
+ Partials      183      182       -1     
Impacted Files Coverage Δ
pystac/stac_io.py 87.82% <100.00%> (+0.43%) ⬆️
tests/test_stac_io.py 100.00% <100.00%> (ø)
pystac/catalog.py 91.34% <0.00%> (+0.24%) ⬆️

Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here.

☔ View full report at Codecov.
📢 Do you have feedback about the report comment? Let us know in this issue.

@john-dupuy john-dupuy force-pushed the add-headers-stacio-requests branch from 7bd8605 to 66a7b06 Compare October 11, 2022 17:35
Copy link
Member

@gadomski gadomski left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've tested this with a real-world STAC server that requires authorization, and it appears to work. Thanks for the contribution! I'm going to request @matthewhanson's review as well, because he brought up the point in a side channel that you could just use pystac-client, which already supports authorization. In my opinion, this PR is still useful, as it doesn't add any extra dependencies to add functionality, but would like Matt to weigh in as well.

@matthewhanson
Copy link
Member

Thanks for the PR @john-dupuy . As @gadomski said, you could use pystac-client here which handles header auth and works fine on static catalogs. However I agree that since it requires no dependencies and is a simple addition it doesn't hurt to include it in PySTAC as well.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants