diff --git a/README.md b/README.md index 62770b5..ca206b8 100644 --- a/README.md +++ b/README.md @@ -74,7 +74,6 @@ Some clients require some setup before use; they are called out in this table, a | `S3Client` | Simple S3 client | Use `requester_pays=True` in the client initializer to enable access to requester pays buckets, e.g. USGS landsat's public AWS archive | | `FilesystemClient` | Moves files from place to place on a local filesystem | Mostly used for testing | | `PlanetaryComputerClient` | Signs urls with the [Planetary Computer Authentication API](https://planetarycomputer.microsoft.com/docs/reference/sas/) | No additional setup required, works out of the box | -| `UsgsErosClient` | Uses a token-based authentication workflow to download data, e.g. landsat, from USGS EROS | Requires creation of a personal access token, see section below | | `EarthdataClient` | Uses a token-based authentication to download data, from _some_ Earthdata providers, e.g. DAACs | Requires creation of a personal access token, see section below | ### S3Client @@ -82,19 +81,6 @@ Some clients require some setup before use; they are called out in this table, a To use the `requester_pays` option, you need to configure your AWS credentials. See [the AWS documentation](https://docs.aws.amazon.com/cli/latest/userguide/cli-configure-files.html) for instructions. -#### USGS EROS - -The USGS EROS system, which hosts landsat data, requires a personal access token to download assets. -Here's how to create and use your personal access token with **stac-asset**: - -1. [Create a new personal access token](https://ers.cr.usgs.gov/password/appgenerate) -2. Set two environment variables: - - `USGS_EROS_USERNAME` to your username (found in the top right of the web UI) - - `USGS_EROS_PAT` to your personal access token -3. Use `UsgsErosClient.default()` to create a new client. - -You can also provide your username and password to the `UsgsErosClient.login` method. - #### Earthdata You'll need a personal access token. diff --git a/src/stac_asset/__init__.py b/src/stac_asset/__init__.py index 29604bf..a0bbc06 100644 --- a/src/stac_asset/__init__.py +++ b/src/stac_asset/__init__.py @@ -29,7 +29,6 @@ from .planetary_computer_client import PlanetaryComputerClient from .s3_client import S3Client from .strategy import FileNameStrategy -from .usgs_eros_client import UsgsErosClient __all__ = [ "DownloadWarning", @@ -44,7 +43,6 @@ "HttpClient", "PlanetaryComputerClient", "S3Client", - "UsgsErosClient", "download_item", "download_item_collection", "guess_client", diff --git a/src/stac_asset/functions.py b/src/stac_asset/functions.py index 6c4edb3..110a7ed 100644 --- a/src/stac_asset/functions.py +++ b/src/stac_asset/functions.py @@ -10,7 +10,6 @@ from .s3_client import S3Client from .strategy import FileNameStrategy from .types import PathLikeObject -from .usgs_eros_client import UsgsErosClient async def download_item( @@ -142,8 +141,6 @@ async def guess_client(href: str, s3_requester_pays: bool = False) -> Client: return S3Client(requester_pays=s3_requester_pays) elif url.host.endswith("blob.core.windows.net"): return await PlanetaryComputerClient.default() - elif url.host == "landsatlook.usgs.gov": - return await UsgsErosClient.default() elif url.scheme == "http" or url.scheme == "https": return await HttpClient.default() else: diff --git a/src/stac_asset/usgs_eros_client.py b/src/stac_asset/usgs_eros_client.py deleted file mode 100644 index ce43b1a..0000000 --- a/src/stac_asset/usgs_eros_client.py +++ /dev/null @@ -1,89 +0,0 @@ -from __future__ import annotations - -import json -import os -from types import TracebackType -from typing import Optional, Type - -from aiohttp import ClientSession - -from .http_client import HttpClient - - -class UsgsErosClient(HttpClient): - """A client for fetching data from USGS EROS. - - This includes landsat data. - """ - - @classmethod - async def default( - cls, - ) -> UsgsErosClient: - """Logs in to the USGS EROS system using your environment variables. - - Returns: - UsgsErosClient: A client that has been logged in to the USGS EROS system - """ - return await cls.login() - - @classmethod - async def login( - cls, - username: Optional[str] = None, - pat: Optional[str] = None, - ) -> UsgsErosClient: - """Logs in to the USGS EROS system and returns a configured client. - - Args: - username: Your USGS EROS username. Will be read from the - ``USGS_EROS_USERNAME`` environment variable if not provided. - pat: Your USGS EROS personal access token. Will be read from the - ``USGS_EROS_PAT`` environment variable if not provided. - """ - if username is None: - try: - username = os.environ["USGS_EROS_USERNAME"] - except KeyError: - raise ValueError( - "USGS_EROS_USERNAME is not set as an environment variable, " - "and no username was provided" - ) - if pat is None: - try: - pat = os.environ.get("USGS_EROS_PAT") - except KeyError: - raise ValueError( - "USGS_EROS_PAT is not set as an environment variable, " - "and no personal access token was provided" - ) - session = ClientSession() - response = await session.post( - "https://m2m.cr.usgs.gov/api/api/json/stable/login-token", - data=json.dumps({"username": username, "token": pat}), - ) - response.raise_for_status() - data = await response.json() - try: - api_key = data["data"] - except KeyError: - raise ValueError( - f"unexpected response format (expected 'data' key): {json.dumps(data)}" - ) - return cls( - session=ClientSession( - headers={"X-Auth-Token": api_key}, - ) - ) - - async def __aenter__(self) -> UsgsErosClient: - return self - - async def __aexit__( - self, - exc_type: Optional[Type[BaseException]], - exc_val: Optional[BaseException], - exc_tb: Optional[TracebackType], - ) -> Optional[bool]: - await self.session.close() - return await super().__aexit__(exc_type, exc_val, exc_tb) diff --git a/tests/test_usgs_eros_client.py b/tests/test_usgs_eros_client.py deleted file mode 100644 index a179e34..0000000 --- a/tests/test_usgs_eros_client.py +++ /dev/null @@ -1,30 +0,0 @@ -import os -from pathlib import Path - -import pytest -from stac_asset import UsgsErosClient - -pytestmark = [ - pytest.mark.skipif( - os.environ.get("USGS_EROS_USERNAME") is None - or os.environ.get("USGS_EROS_PAT") is None, - reason="USGS_EROS_USERNAME or USGS_EROS_PAT are not set", - ), - pytest.mark.network_access, - pytest.mark.asyncio, -] - - -@pytest.fixture -def asset_href() -> str: - return ( - "https://landsatlook.usgs.gov/data/collection02/level-2/standard/oli-tirs/2022/004" - "/004/LC08_L2SP_004004_20220519_20220525_02_T1/LC08_L2SP_004004_20220519_20220525_02_T1_thumb_small.jpeg" - ) - - -async def test_download(tmp_path: Path, asset_href: str) -> None: - async with await UsgsErosClient.login() as client: - await client.download_href(asset_href, tmp_path / "out.jpg") - - assert os.path.getsize(tmp_path / "out.jpg") == 18517