-
Notifications
You must be signed in to change notification settings - Fork 51
Feature request: Support "signing" results #259
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
Comments
One slightly awkward issue I've run into when prototyping this: this is a bit of state on the object that should probably preserved through things like That said, we can handle this in pystac-client by overriding |
I have a prototype implementaiton of this at https://github.com/stac-utils/pystac-client/compare/main...TomAugspurger:pystac-client:feature/sign?expand=1. You can see the awkwardness of doing this in pystac-client at places like https://github.com/stac-utils/pystac-client/compare/main...TomAugspurger:pystac-client:feature/sign?expand=1#diff-31bfdc592adbc2c1ac2b67b8ef4ba341f775899fa3d9c4252a441d2b58a2e87fR145. That said, doing it upstream in pystac will still require changes in pystac-client to ensure that |
Thinking abstractly here, there's nothing signing-specific about your implementation, correct? It's really more of a |
Yep, that's 100% correct. The name should probably reflect that. It's slightly similar to dataclasses'
In the case of planetary_computer.sign, it can either mutate an object or return a copy. I'm not sure whether pystac / pystac-client should take a stance on the behavior of the I'm realizing now that there's a subtle point I haven't stated explicitly: I've only considered the case of users providing a |
My preference is to mutate, leaving it up to the user to copy before calling.
The only use-case I could see would be Collection-level assets. Otherwise, I agree that pystac-client usually would want to sign children. However, if we move this functionality down to PySTAC, then we absolutely want to sign the parent I think, since you can load Items directly with PySTAC. |
SGTM. Kinda leading into the next point: the user won't have any references to the children that might be mutated inplace, so API-wise mutating or not only matters if we're calling the hook on the paranet object itself. Here's my concrete proposal: A new parameter to the various constructors,
Anticipating a future concern: what if users want to provide different modifier callables for different purposes? I think we could adopt a pattern similar to https://www.python-httpx.org/advanced/#timeout-configuration. If you provide a simple callable, we expect that it can handle anything. If you want fine-grained control, we can provide a simple class
And we would call the appropriate method. IMO that's overkill for an initial implementation. Just accepting a I think we'll want to override the I'll put up a PR along these lines sometime in the next day or two. Slight concern: up until now |
**Related Issue(s):** - Closes stac-utils#259 **Description:** This adds a new keyword, `modifier`, to the various constructors. The motivation is described in stac-utils#259. As a brief demonstration: ```python In [1]: import planetary_computer, pystac_client In [2]: catalog = pystac_client.Client.open("https://planetarycomputer.microsoft.com/api/stac/v1", modifier=planetary_computer.sign_inplace) In [3]: item = next(catalog.get_collection("sentinel-2-l2a").get_all_items()) In [4]: item.assets["B02"].href # signed URL, notice the querystring Out[4]: 'https://sentinel2l2a01.blob.core.windows.net/sentinel2-l2/52/S/GH/2022/07/28/S2B_MSIL2A_20220728T020659_N0400_R103_T52SGH_20220729T082039.SAFE/GRANULE/L2A_T52SGH_A028157_20220728T021310/IMG_DATA/R10m/T52SGH_20220728T020659_B02_10m.tif?st=2022-07-28T16%3A03%3A54Z&se=2022-07-29T16%3A48%3A54Z...' ``` **PR Checklist:** - [x] Code is formatted - [x] Tests pass - [x] Changes are added to the [CHANGELOG](https://github.com/stac-utils/pystac-api-client/blob/main/CHANGELOG.md)
**Related Issue(s):** - Closes stac-utils#259 **Description:** This adds a new keyword, `modifier`, to the various constructors. The motivation is described in stac-utils#259. As a brief demonstration: ```python In [1]: import planetary_computer, pystac_client In [2]: catalog = pystac_client.Client.open("https://planetarycomputer.microsoft.com/api/stac/v1", modifier=planetary_computer.sign_inplace) In [3]: item = next(catalog.get_collection("sentinel-2-l2a").get_all_items()) In [4]: item.assets["B02"].href # signed URL, notice the querystring Out[4]: 'https://sentinel2l2a01.blob.core.windows.net/sentinel2-l2/52/S/GH/2022/07/28/S2B_MSIL2A_20220728T020659_N0400_R103_T52SGH_20220729T082039.SAFE/GRANULE/L2A_T52SGH_A028157_20220728T021310/IMG_DATA/R10m/T52SGH_20220728T020659_B02_10m.tif?st=2022-07-28T16%3A03%3A54Z&se=2022-07-29T16%3A48%3A54Z...' ``` **PR Checklist:** - [x] Code is formatted - [x] Tests pass - [x] Changes are added to the [CHANGELOG](https://github.com/stac-utils/pystac-api-client/blob/main/CHANGELOG.md)
**Related Issue(s):** - Closes stac-utils#259 **Description:** This adds a new keyword, `modifier`, to the various constructors. The motivation is described in stac-utils#259. As a brief demonstration: ```python In [1]: import planetary_computer, pystac_client In [2]: catalog = pystac_client.Client.open("https://planetarycomputer.microsoft.com/api/stac/v1", modifier=planetary_computer.sign_inplace) In [3]: item = next(catalog.get_collection("sentinel-2-l2a").get_all_items()) In [4]: item.assets["B02"].href # signed URL, notice the querystring Out[4]: 'https://sentinel2l2a01.blob.core.windows.net/sentinel2-l2/52/S/GH/2022/07/28/S2B_MSIL2A_20220728T020659_N0400_R103_T52SGH_20220729T082039.SAFE/GRANULE/L2A_T52SGH_A028157_20220728T021310/IMG_DATA/R10m/T52SGH_20220728T020659_B02_10m.tif?st=2022-07-28T16%3A03%3A54Z&se=2022-07-29T16%3A48%3A54Z...' ``` **PR Checklist:** - [x] Code is formatted - [x] Tests pass - [x] Changes are added to the [CHANGELOG](https://github.com/stac-utils/pystac-api-client/blob/main/CHANGELOG.md)
* Add a post-init modifier keyword **Related Issue(s):** - Closes #259 **Description:** This adds a new keyword, `modifier`, to the various constructors. The motivation is described in #259. As a brief demonstration: ```python In [1]: import planetary_computer, pystac_client In [2]: catalog = pystac_client.Client.open("https://planetarycomputer.microsoft.com/api/stac/v1", modifier=planetary_computer.sign_inplace) In [3]: item = next(catalog.get_collection("sentinel-2-l2a").get_all_items()) In [4]: item.assets["B02"].href # signed URL, notice the querystring Out[4]: 'https://sentinel2l2a01.blob.core.windows.net/sentinel2-l2/52/S/GH/2022/07/28/S2B_MSIL2A_20220728T020659_N0400_R103_T52SGH_20220729T082039.SAFE/GRANULE/L2A_T52SGH_A028157_20220728T021310/IMG_DATA/R10m/T52SGH_20220728T020659_B02_10m.tif?st=2022-07-28T16%3A03%3A54Z&se=2022-07-29T16%3A48%3A54Z...' ``` **PR Checklist:** - [x] Code is formatted - [x] Tests pass - [x] Changes are added to the [CHANGELOG](https://github.com/stac-utils/pystac-api-client/blob/main/CHANGELOG.md) * pystac compat * Handle return type * use is * Remove no_modifier * fixup * Apply suggestions from code review Co-authored-by: Jon Duckworth <duckontheweb@gmail.com> * fixup Co-authored-by: Jon Duckworth <duckontheweb@gmail.com>
This is a feature request to add an argument to the
pystac_client.Client
constructor and thefrom_*
classmethods that would enabling "signing" results like those returned by the Planetary Computer and Brazil Data Cube.Motivation
Some STAC APIs, like the Planetary Computer's, are public but the assets are stored in private blob storage containers. The results returned from the STAC API need to be transformed somehow for the user to read the actual data. For the Planetary Computer, we have users hit another API endpoint that grants them a short-lived token enabling them to read from blob storage. This is implemented in python at https://github.com/microsoft/planetary-computer-sdk-for-python.
This works OK, but does need to be manually called on each result. This request is for convenience: you specifying the signing function once when creating the
Client
and it calls the callable on each result.Proposal
Add a new parameter, something like
sign_function
(name TDB), that's a callable called with the result immediately before returning it to the user.planetary_computer.sign
works with URLs, assets, items, or ItemCollections so I'm personally OK with lumping all of those under a single parameter. Alternatively we could have an object with dedicated implementations for each kind of thing being signed (or maybe just Items and ItemCollections, since those are the only thing returned by pystac-client.Note that odc-stac as implemented something similar with the
patch_url
function: https://odc-stac.readthedocs.io/en/latest/_api/odc.stac.load.html?highlight=patch_url#odc.stac.load. I think that pystac-client is more appropriate place for this functionality since not all STAC metadata represent data that can be put in a datacube.Docs for rstac's sign_bdc and sign_planetary_computer.
The text was updated successfully, but these errors were encountered: