diff --git a/CHANGES.md b/CHANGES.md index 12c776368..8856da996 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -6,6 +6,7 @@ * Add benchmark in CI ([#650](https://github.com/stac-utils/stac-fastapi/pull/650)) * Add `/queryables` link to the landing page ([#587](https://github.com/stac-utils/stac-fastapi/pull/587)) +- `id`, `title`, `description` and `api_version` fields can be customized via env variables ### Changed diff --git a/docs/src/tips-and-tricks.md b/docs/src/tips-and-tricks.md index ca5463c59..a42ce98b2 100644 --- a/docs/src/tips-and-tricks.md +++ b/docs/src/tips-and-tricks.md @@ -31,3 +31,12 @@ from stac_fastapi.extensions.core.context import ContextExtension ``` and then edit the `api = StacApi(...` call to add `ContextExtension()` to the list given as the `extensions` parameter. + +## Set API title, description and version + +For the landing page, you can set the API title, description and version using environment variables. + +- `STAC_FASTAPI_VERSION` (string) is the version number of your API instance (this is not the STAC version). +- `STAC FASTAPI_TITLE` (string) should be a self-explanatory title for your API. +- `STAC FASTAPI_DESCRIPTION` (string) should be a good description for your API. It can contain CommonMark. +- `STAC_FASTAPI_LANDING_ID` (string) is a unique identifier for your Landing page. diff --git a/stac_fastapi/api/stac_fastapi/api/app.py b/stac_fastapi/api/stac_fastapi/api/app.py index 557896d8f..7ad0c96f5 100644 --- a/stac_fastapi/api/stac_fastapi/api/app.py +++ b/stac_fastapi/api/stac_fastapi/api/app.py @@ -1,4 +1,5 @@ """Fastapi app creation.""" + from typing import Any, Dict, List, Optional, Tuple, Type, Union import attr @@ -83,10 +84,22 @@ class StacApi: converter=update_openapi, ) router: APIRouter = attr.ib(default=attr.Factory(APIRouter)) - title: str = attr.ib(default="stac-fastapi") - api_version: str = attr.ib(default="0.1") + title: str = attr.ib( + default=attr.Factory( + lambda self: self.settings.stac_fastapi_title, takes_self=True + ) + ) + api_version: str = attr.ib( + default=attr.Factory( + lambda self: self.settings.stac_fastapi_version, takes_self=True + ) + ) stac_version: str = attr.ib(default=STAC_VERSION) - description: str = attr.ib(default="stac-fastapi") + description: str = attr.ib( + default=attr.Factory( + lambda self: self.settings.stac_fastapi_description, takes_self=True + ) + ) search_get_request_model: Type[BaseSearchGetRequest] = attr.ib( default=BaseSearchGetRequest ) diff --git a/stac_fastapi/types/stac_fastapi/types/config.py b/stac_fastapi/types/stac_fastapi/types/config.py index b3f22fb65..4b88c56a4 100644 --- a/stac_fastapi/types/stac_fastapi/types/config.py +++ b/stac_fastapi/types/stac_fastapi/types/config.py @@ -22,6 +22,11 @@ class ApiSettings(BaseSettings): # `pydantic.BaseSettings` instead default_includes: Optional[Set[str]] = None + stac_fastapi_title: str = "stac-fastapi" + stac_fastapi_description: str = "stac-fastapi" + stac_fastapi_version: str = "0.1" + stac_fastapi_landing_id: str = "stac-fastapi" + app_host: str = "0.0.0.0" app_port: int = 8000 reload: bool = True diff --git a/stac_fastapi/types/stac_fastapi/types/core.py b/stac_fastapi/types/stac_fastapi/types/core.py index d915d465f..77078ace3 100644 --- a/stac_fastapi/types/stac_fastapi/types/core.py +++ b/stac_fastapi/types/stac_fastapi/types/core.py @@ -12,6 +12,7 @@ from starlette.responses import Response from stac_fastapi.types import stac as stac_types +from stac_fastapi.types.config import ApiSettings from stac_fastapi.types.conformance import BASE_CONFORMANCE_CLASSES from stac_fastapi.types.extension import ApiExtension from stac_fastapi.types.requests import get_base_url @@ -22,6 +23,8 @@ NumType = Union[float, int] StacType = Dict[str, Any] +api_settings = ApiSettings() + @attr.s # type:ignore class BaseTransactionsClient(abc.ABC): @@ -255,9 +258,9 @@ class LandingPageMixin(abc.ABC): """Create a STAC landing page (GET /).""" stac_version: str = attr.ib(default=STAC_VERSION) - landing_page_id: str = attr.ib(default="stac-fastapi") - title: str = attr.ib(default="stac-fastapi") - description: str = attr.ib(default="stac-fastapi") + landing_page_id: str = attr.ib(default=api_settings.stac_fastapi_landing_id) + title: str = attr.ib(default=api_settings.stac_fastapi_title) + description: str = attr.ib(default=api_settings.stac_fastapi_description) def _landing_page( self,