Skip to content

Commit 6cae792

Browse files
committed
Allow an easy way to configure the landing page id, description, title and version via env variables
1 parent 4fb10ec commit 6cae792

File tree

4 files changed

+25
-6
lines changed

4 files changed

+25
-6
lines changed

CHANGES.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,10 @@
22

33
## [Unreleased]
44

5+
### Added
6+
7+
- `id`, `title`, `description` and `api_version` fields can be customized via env variables
8+
59
## [2.4.9] - 2023-11-17
610

711
### Added

docs/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_ID` (string) is a unique identifier for your API.

stac_fastapi/api/stac_fastapi/api/app.py

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

45
import attr
@@ -83,10 +84,12 @@ 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(default=os.getenv("STAC_FASTAPI_TITLE", "stac-fastapi"))
88+
api_version: str = attr.ib(default=os.getenv("STAC_FASTAPI_VERSION", "0.1"))
8889
stac_version: str = attr.ib(default=STAC_VERSION)
89-
description: str = attr.ib(default="stac-fastapi")
90+
description: str = attr.ib(
91+
default=os.getenv("STAC_FASTAPI_DESCRIPTION", "stac-fastapi")
92+
)
9093
search_get_request_model: Type[BaseSearchGetRequest] = attr.ib(
9194
default=BaseSearchGetRequest
9295
)

stac_fastapi/types/stac_fastapi/types/core.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
"""Base clients."""
22
import abc
3+
import os
34
from datetime import datetime
45
from typing import Any, Dict, List, Optional, Union
56
from urllib.parse import urljoin
@@ -253,9 +254,11 @@ class LandingPageMixin(abc.ABC):
253254
"""Create a STAC landing page (GET /)."""
254255

255256
stac_version: str = attr.ib(default=STAC_VERSION)
256-
landing_page_id: str = attr.ib(default="stac-fastapi")
257-
title: str = attr.ib(default="stac-fastapi")
258-
description: str = attr.ib(default="stac-fastapi")
257+
landing_page_id: str = attr.ib(default=os.getenv("STAC_FASTAPI_ID", "0.1"))
258+
title: str = attr.ib(default=os.getenv("STAC_FASTAPI_TITLE", "stac-fastapi"))
259+
description: str = attr.ib(
260+
default=os.getenv("STAC_FASTAPI_DESCRIPTION", "stac-fastapi")
261+
)
259262

260263
def _landing_page(
261264
self,

0 commit comments

Comments
 (0)