Skip to content

Planetary computer credential provider #379

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

Merged
merged 21 commits into from
Mar 21, 2025

Conversation

kylebarron
Copy link
Member

@kylebarron kylebarron commented Mar 19, 2025

Closes #368

from obstore.store import AzureStore
from obstore.auth.planetary_computer import PlanetaryComputerCredentialProvider

container = "landsat-c2"
account_name = "landsateuwest"
credential_provider = PlanetaryComputerCredentialProvider(
    container=container,
    account=account_name,
)
store = AzureStore(
    container=container,
    account_name=account_name,
    credential_provider=credential_provider,
)
next(store.list())

prints:

[{'path': 'level-1',
  'last_modified': datetime.datetime(2021, 10, 19, 19, 13, 35, tzinfo=datetime.timezone.utc),
  'size': 0,
  'e_tag': '0x8D993348C653FF0',
  'version': None},
 {'path': 'level-1/standard',
  'last_modified': datetime.datetime(2021, 10, 19, 19, 13, 35, tzinfo=datetime.timezone.utc),
  'size': 0,
  'e_tag': '0x8D993348C83067C',
  'version': None},
 {'path': 'level-1/standard/mss',
  'last_modified': datetime.datetime(2021, 10, 19, 19, 13, 35, tzinfo=datetime.timezone.utc),
  'size': 0,
  'e_tag': '0x8D993348C8E04F8',
  'version': None},
 {'path': 'level-1/standard/mss/1972',
  'last_modified': datetime.datetime(2021, 10, 19, 19, 13, 35, tzinfo=datetime.timezone.utc),
  'size': 0,
  'e_tag': '0x8D993348C909D86',
  'version': None},
 {'path': 'level-1/standard/mss/1972/001',
  'last_modified': datetime.datetime(2021, 10, 19, 19, 14, 57, tzinfo=datetime.timezone.utc),
  'size': 0,
  'e_tag': '0x8D99334BD5DFDC3',
  'version': None},
 {'path': 'level-1/standard/mss/1972/001/001',
  'last_modified': datetime.datetime(2021, 10, 19, 23, 1, 49, tzinfo=datetime.timezone.utc),
  'size': 0,
  'e_tag': '0x8D993546EAC018F',
  'version': None},
 {'path': 'level-1/standard/mss/1972/001/002',
  'last_modified': datetime.datetime(2021, 10, 19, 21, 53, 57, tzinfo=datetime.timezone.utc),
  'size': 0,
  'e_tag': '0x8D9934AF3665168',
  'version': None},
 {'path': 'level-1/standard/mss/1972/001/003',
  'last_modified': datetime.datetime(2021, 10, 19, 19, 48, 25, tzinfo=datetime.timezone.utc),
  'size': 0,
  'e_tag': '0x8D993396A5A920A',
  'version': None},
 {'path': 'level-1/standard/mss/1972/001/004',
  'last_modified': datetime.datetime(2021, 10, 19, 22, 4, 31, tzinfo=datetime.timezone.utc),
  'size': 0,
  'e_tag': '0x8D9934C6D7A4027',
  'version': None},
 {'path': 'level-1/standard/mss/1972/001/005',
  'last_modified': datetime.datetime(2021, 10, 19, 20, 28, 4, tzinfo=datetime.timezone.utc),
  'size': 0,
  'e_tag': '0x8D9933EF48400A2',
  'version': None},
 {'path': 'level-1/standard/mss/1972/001/006',
  'last_modified': datetime.datetime(2021, 10, 19, 20, 5, 1, tzinfo=datetime.timezone.utc),
  'size': 0,
  'e_tag': '0x8D9933BBBC549AD',
  'version': None},
 {'path': 'level-1/standard/mss/1972/001/007',
  'last_modified': datetime.datetime(2021, 10, 19, 19, 16, 35, tzinfo=datetime.timezone.utc),
  'size': 0,
  'e_tag': '0x8D99334F7E08520',
  'version': None},
 {'path': 'level-1/standard/mss/1972/001/008',
  'last_modified': datetime.datetime(2021, 10, 19, 22, 42, 2, tzinfo=datetime.timezone.utc),
  'size': 0,
  'e_tag': '0x8D99351AB8597CD',
  'version': None},
 {'path': 'level-1/standard/mss/1972/001/009',
  'last_modified': datetime.datetime(2021, 10, 19, 20, 50, 19, tzinfo=datetime.timezone.utc),
  'size': 0,
  'e_tag': '0x8D993420FDDCDFA',
  'version': None},
 {'path': 'level-1/standard/mss/1972/001/010',
  'last_modified': datetime.datetime(2021, 10, 19, 22, 4, 13, tzinfo=datetime.timezone.utc),
  'size': 0,
  'e_tag': '0x8D9934C62FCF1FB',
  'version': None},
 {'path': 'level-1/standard/mss/1972/001/010/LM01_L1GS_001010_19720908_20200909_02_T2',
  'last_modified': datetime.datetime(2021, 10, 19, 22, 4, 14, tzinfo=datetime.timezone.utc),
  'size': 0,
  'e_tag': '0x8D9934C63798B7F',
  'version': None},
 {'path': 'level-1/standard/mss/1972/001/010/LM01_L1GS_001010_19720908_20200909_02_T2/LM01_L1GS_001010_19720908_20200909_02_T2_B4.TIF',
  'last_modified': datetime.datetime(2021, 10, 19, 22, 4, 16, tzinfo=datetime.timezone.utc),
  'size': 3312017,
  'e_tag': '0x8D9934C64E320F0',
  'version': None},
 {'path': 'level-1/standard/mss/1972/001/010/LM01_L1GS_001010_19720908_20200909_02_T2/LM01_L1GS_001010_19720908_20200909_02_T2_B5.TIF',
  'last_modified': datetime.datetime(2021, 10, 19, 22, 4, 16, tzinfo=datetime.timezone.utc),
  'size': 4790183,
  'e_tag': '0x8D9934C64D82270',
  'version': None},
 {'path': 'level-1/standard/mss/1972/001/010/LM01_L1GS_001010_19720908_20200909_02_T2/LM01_L1GS_001010_19720908_20200909_02_T2_B6.TIF',
  'last_modified': datetime.datetime(2021, 10, 19, 22, 4, 17, tzinfo=datetime.timezone.utc),
  'size': 8718281,
  'e_tag': '0x8D9934C6504B8BF',
  'version': None},
 {'path': 'level-1/standard/mss/1972/001/010/LM01_L1GS_001010_19720908_20200909_02_T2/LM01_L1GS_001010_19720908_20200909_02_T2_B7.TIF',
  'last_modified': datetime.datetime(2021, 10, 19, 22, 4, 16, tzinfo=datetime.timezone.utc),
  'size': 6330612,
  'e_tag': '0x8D9934C64EE6D95',
  'version': None},
...

TODO

  • It would be nice to be able to pass the config down to the AzureStore from inside the credential provider, so that we only
  • Ensure the params like account_name for the credential provider match the params for the azure config.
  • Add async version.
  • Make a second pass on the settings config. Document how to pass in custom parameters.
  • Add example to documentation; add to integrations list.

@kylebarron
Copy link
Member Author

kylebarron commented Mar 20, 2025

For non-https blob urls: works when we use the token provided by the pc stac api:

import pystac_client
import planetary_computer

catalog = pystac_client.Client.open(
    "https://planetarycomputer.microsoft.com/api/stac/v1/",
    modifier=planetary_computer.sign_inplace,
)

asset = catalog.get_collection("io-lulc-9-class").assets["geoparquet-items"]

store = AzureStore("items", account_name="pcstacitems", sas_key=asset.extra_fields["table:storage_options"]["credential"])
store.head("io-lulc-9-class.parquet")

Fails when we try to fetch our own token

collection_id = "io-lulc-9-class"
token_url = f"https://planetarycomputer.microsoft.com/api/sas/v1/token/{collection_id}"
token = requests.get(token_url).json()["token"]
store = AzureStore("items", account_name="pcstacitems", sas_key=token)
store.head("io-lulc-9-class.parquet")

Edit: figured this out in 2908f05 (#379)

@kylebarron kylebarron added this to the 0.6.0 milestone Mar 21, 2025
@kylebarron kylebarron marked this pull request as ready for review March 21, 2025 20:03
@kylebarron kylebarron merged commit 7d2c6b0 into main Mar 21, 2025
6 checks passed
@kylebarron kylebarron deleted the kyle/planetary-computer-credential-provider branch March 21, 2025 20:19
@kylebarron kylebarron mentioned this pull request Mar 21, 2025
2 tasks
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.

Add Planetary Computer credential provider?
1 participant