Skip to content

Commit 96de0e2

Browse files
Configure the landing page id, description, etc. via env vars (#639)
* Allow an easy way to configure the landing page id, description, title and version via env variables * use pydantic settings (#657) * use pydantic settings * rename stac_fastapi_id to stac_fastapi_landing_id * Update docs/src/tips-and-tricks.md --------- Co-authored-by: vincentsarago <[email protected]>
1 parent 315cfae commit 96de0e2

File tree

5 files changed

+37
-6
lines changed

5 files changed

+37
-6
lines changed

CHANGES.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66

77
* Add benchmark in CI ([#650](https://github.com/stac-utils/stac-fastapi/pull/650))
88
* Add `/queryables` link to the landing page ([#587](https://github.com/stac-utils/stac-fastapi/pull/587))
9+
- `id`, `title`, `description` and `api_version` fields can be customized via env variables
910

1011
### Changed
1112

docs/src/tips-and-tricks.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,3 +31,12 @@ from stac_fastapi.extensions.core.context import ContextExtension
3131
```
3232

3333
and then edit the `api = StacApi(...` call to add `ContextExtension()` to the list given as the `extensions` parameter.
34+
35+
## Set API title, description and version
36+
37+
For the landing page, you can set the API title, description and version using environment variables.
38+
39+
- `STAC_FASTAPI_VERSION` (string) is the version number of your API instance (this is not the STAC version).
40+
- `STAC FASTAPI_TITLE` (string) should be a self-explanatory title for your API.
41+
- `STAC FASTAPI_DESCRIPTION` (string) should be a good description for your API. It can contain CommonMark.
42+
- `STAC_FASTAPI_LANDING_ID` (string) is a unique identifier for your Landing page.

stac_fastapi/api/stac_fastapi/api/app.py

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
"""Fastapi app creation."""
2+
23
from typing import Any, Dict, List, Optional, Tuple, Type, Union
34

45
import attr
@@ -83,10 +84,22 @@ class StacApi:
8384
converter=update_openapi,
8485
)
8586
router: APIRouter = attr.ib(default=attr.Factory(APIRouter))
86-
title: str = attr.ib(default="stac-fastapi")
87-
api_version: str = attr.ib(default="0.1")
87+
title: str = attr.ib(
88+
default=attr.Factory(
89+
lambda self: self.settings.stac_fastapi_title, takes_self=True
90+
)
91+
)
92+
api_version: str = attr.ib(
93+
default=attr.Factory(
94+
lambda self: self.settings.stac_fastapi_version, takes_self=True
95+
)
96+
)
8897
stac_version: str = attr.ib(default=STAC_VERSION)
89-
description: str = attr.ib(default="stac-fastapi")
98+
description: str = attr.ib(
99+
default=attr.Factory(
100+
lambda self: self.settings.stac_fastapi_description, takes_self=True
101+
)
102+
)
90103
search_get_request_model: Type[BaseSearchGetRequest] = attr.ib(
91104
default=BaseSearchGetRequest
92105
)

stac_fastapi/types/stac_fastapi/types/config.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,11 @@ class ApiSettings(BaseSettings):
2222
# `pydantic.BaseSettings` instead
2323
default_includes: Optional[Set[str]] = None
2424

25+
stac_fastapi_title: str = "stac-fastapi"
26+
stac_fastapi_description: str = "stac-fastapi"
27+
stac_fastapi_version: str = "0.1"
28+
stac_fastapi_landing_id: str = "stac-fastapi"
29+
2530
app_host: str = "0.0.0.0"
2631
app_port: int = 8000
2732
reload: bool = True

stac_fastapi/types/stac_fastapi/types/core.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
from starlette.responses import Response
1313

1414
from stac_fastapi.types import stac as stac_types
15+
from stac_fastapi.types.config import ApiSettings
1516
from stac_fastapi.types.conformance import BASE_CONFORMANCE_CLASSES
1617
from stac_fastapi.types.extension import ApiExtension
1718
from stac_fastapi.types.requests import get_base_url
@@ -22,6 +23,8 @@
2223
NumType = Union[float, int]
2324
StacType = Dict[str, Any]
2425

26+
api_settings = ApiSettings()
27+
2528

2629
@attr.s # type:ignore
2730
class BaseTransactionsClient(abc.ABC):
@@ -255,9 +258,9 @@ class LandingPageMixin(abc.ABC):
255258
"""Create a STAC landing page (GET /)."""
256259

257260
stac_version: str = attr.ib(default=STAC_VERSION)
258-
landing_page_id: str = attr.ib(default="stac-fastapi")
259-
title: str = attr.ib(default="stac-fastapi")
260-
description: str = attr.ib(default="stac-fastapi")
261+
landing_page_id: str = attr.ib(default=api_settings.stac_fastapi_landing_id)
262+
title: str = attr.ib(default=api_settings.stac_fastapi_title)
263+
description: str = attr.ib(default=api_settings.stac_fastapi_description)
261264

262265
def _landing_page(
263266
self,

0 commit comments

Comments
 (0)