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

Ab/initial changes for mspc #1

Merged
merged 27 commits into from
May 24, 2024
Merged

Conversation

abarciauskas-bgse
Copy link

@abarciauskas-bgse abarciauskas-bgse commented May 22, 2024

This PR primarily:

  • removes WMTS code + documentation
  • Adds planetary computer library and code to sign STAC asset urls

I made this a draft primarily because I'm still thinking what could be the best approach for conditionally signing requests with the planetary computer library.

Todos:

  • Address questions
  • Remove unused models (such as LayerDict)

Questions

  • Do we need titiler/stacapi/backend.py? I do not see how CustomSTACReader is being used anywhere.

I think the answer to the question above is we do need titiler/stacapi/backend.py if we're going to use the collections endpoint: https://github.com/developmentseed/titiler-stacapi-mspc/blob/main/titiler/stacapi/main.py#L87-L91 uses MosaicTilerFactory which is included in this repo and requires the STACAPIBackend which is defined in titiler/stacapi/backend.py and relies on CustomSTACReader (not sure how I missed this dependency before).

@@ -13,7 +13,6 @@ The `Item` endpoints are created using TiTiler's [MultiBaseTilerFactory](https:/
| `POST` | `/collections/{collection_id}/items/{item_id}/statistics` | GeoJSON ([Statistics][multistats_geojson_model]) | return assets statistics for a GeoJSON (merged)
| `GET` | `/collections/{collection_id}/items/{item_id}/tiles[/{TileMatrixSetId}]/{z}/{x}/{y}[@{scale}x][.{format}]` | image/bin | create a web map tile image from assets
| `GET` | `/collections/{collection_id}/items/{item_id}[/{TileMatrixSetId}]/tilejson.json` | JSON ([TileJSON][tilejson_model]) | return a Mapbox TileJSON document
| `GET` | `/collections/{collection_id}/items/{item_id}[/{TileMatrixSetId}]/WMTSCapabilities.xml` | XML | return OGC WMTS Get Capabilities
Copy link
Member

Choose a reason for hiding this comment

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

the items endpoints comes from titiler MultiBaseTilerFactory so it will still be present

Copy link
Author

Choose a reason for hiding this comment

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

change was reverted

@@ -77,6 +77,7 @@ class STACAPISettings(BaseSettings):
"""STAC API settings"""

stac_api_url: str
mspc_default_api_url: str = "https://planetarycomputer.microsoft.com/api/stac/v1"
Copy link
Member

Choose a reason for hiding this comment

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

I think it's fine having stac_api_url to default to https://planetarycomputer.microsoft.com/api/stac/v1

# 2. Set a boolean in settings, something like "SIGN_REQUESTS"
# 3. Just assume all requests are to MS PC API and sign them. Stub out this function in tests and/or when ENV=test
if stac_api_config.stac_api_url == stac_api_config.mspc_default_api_url:
url = planetary_computer.sign(url)
Copy link
Member

Choose a reason for hiding this comment

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

Copy link
Member

Choose a reason for hiding this comment

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

to avoid having a new settings, we could simply check if the asset url is on MS datastore

Copy link
Author

Choose a reason for hiding this comment

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

FYI this is how it's done in MC planetary computer https://github.com/microsoft/planetary-computer-apis/blob/main/pctiler/pctiler/reader.py#L43-L59

Nice, thanks for sharing that. It looks like we would not use this code exactly because it relies on a CollectionConfigTable

to avoid having a new settings, we could simply check if the asset url is on MS datastore

👍🏽 it does appear we can re-use some of https://github.com/microsoft/planetary-computer-apis/blob/main/pccommon/pccommon/cdn.py#L8 to do this. I noticed that this code determines if there is an azureedge configured for the data, but I don't think there is anyway for this application to know about that? Since that code relies on (I think) some redis cache? https://github.com/microsoft/planetary-computer-apis/blob/main/pccommon/pccommon/config/core.py#L28

@hrodmn hrodmn requested review from hrodmn and vincentsarago and removed request for hrodmn May 23, 2024 20:19
Copy link

@hrodmn hrodmn left a comment

Choose a reason for hiding this comment

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

@abarciauskas-bgse I'm sorry I missed your request for a review - didn't have my notifications set up yet! That is fixed now.

We discussed this in our call today but one other way to sign the assets is to use the modifier parameter in the pystac.ItemSearch (or pystac.Client) class where we use it (backend.py, dependencies.py, factory.py I think)

ItemSearch(..., modifier=planetary_computer.sign_inplace)

I don't know if it would be more efficient than checking each asset url, but maybe it would be!

@abarciauskas-bgse
Copy link
Author

@hrodmn I used the ItemSearch modifier option signing method. I verified it didn't break when non-MS PC results are returned from search. So this does seem cleaner than including a regex to check URLs against.

@vincentsarago are there any other initial changes you think we should make? For example, I am not sure if the models in models.py are being used apart from the Link model and I think they were used as part of the WMTS endpoints. Do you think it's safe to remove all of the models apart from Link?

@@ -258,6 +259,7 @@ def get_assets(
f"{self.url}/search",
stac_io=stac_api_io,
**params,
modifier=pc.sign_inplace,
Copy link
Member

Choose a reason for hiding this comment

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

❤️

@@ -67,7 +68,7 @@ class RetrySettings(BaseSettings):
retry_factor: Annotated[float, Field(ge=0.0)] = 0.0

model_config = {
"env_prefix": "TITILER_STACAPI_API_",
"env_prefix": "TITILER_STACAPI_RETRY_",
Copy link
Member

Choose a reason for hiding this comment

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

why do we need this change?

Copy link
Author

Choose a reason for hiding this comment

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

some of these env_prefixs were the same, which seems like it could cause a bug if one of these classes both had the same attribute name so I thought we could rename the env_prefixes to match the class name. What do you think?

Copy link
Member

Choose a reason for hiding this comment

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

It's not necessary, pydantic basettings is smart enough to handle this.

they are distributed into multiple classes because they are not used at the same places

Copy link
Author

Choose a reason for hiding this comment

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

ok reverted those changes


stac_config = STACSettings()
stac_api_config = STACAPISettings()
Copy link
Member

Choose a reason for hiding this comment

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

This setting is not used?

Copy link
Author

Choose a reason for hiding this comment

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

thanks for noticing this, I had misconfigured the pre-commit linter so missed it!

@abarciauskas-bgse abarciauskas-bgse marked this pull request as ready for review May 24, 2024 15:39
@abarciauskas-bgse
Copy link
Author

@vincentsarago I moved this from draft to ready for review as I have addressed the outstanding questions I had. Let me know if you think any other changes should be made for this initial PR.

@vincentsarago vincentsarago self-requested a review May 24, 2024 16:21
@abarciauskas-bgse abarciauskas-bgse merged commit 3b80678 into main May 24, 2024
6 checks passed
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.

3 participants