-
Notifications
You must be signed in to change notification settings - Fork 0
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
Conversation
…eed/titiler-ms-pc-stacapi into ab/initial-changes-for-mspc
48682e6
to
b53de47
Compare
@@ -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 |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
change was reverted
titiler/stacapi/settings.py
Outdated
@@ -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" |
There was a problem hiding this comment.
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
titiler/stacapi/reader.py
Outdated
# 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) |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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
There was a problem hiding this 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!
@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 |
@@ -258,6 +259,7 @@ def get_assets( | |||
f"{self.url}/search", | |||
stac_io=stac_api_io, | |||
**params, | |||
modifier=pc.sign_inplace, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
❤️
titiler/stacapi/settings.py
Outdated
@@ -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_", |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
some of these env_prefix
s 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?
There was a problem hiding this comment.
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
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ok reverted those changes
titiler/stacapi/stac_reader.py
Outdated
|
||
stac_config = STACSettings() | ||
stac_api_config = STACAPISettings() |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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!
@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. |
This PR primarily:
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:
LayerDict
)Questions
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 theSTACAPIBackend
which is defined intitiler/stacapi/backend.py
and relies onCustomSTACReader
(not sure how I missed this dependency before).