Skip to content
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

Configure the landing page id, description, etc. via env vars #639

Merged
merged 4 commits into from
Apr 11, 2024
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
9 changes: 9 additions & 0 deletions docs/src/tips-and-tricks.md
Original file line number Diff line number Diff line change
Expand Up @@ -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_ID` (string) is a unique identifier for your API.
vincentsarago marked this conversation as resolved.
Show resolved Hide resolved
19 changes: 16 additions & 3 deletions stac_fastapi/api/stac_fastapi/api/app.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Fastapi app creation."""

from typing import Any, Dict, List, Optional, Tuple, Type, Union

import attr
Expand Down Expand Up @@ -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
)
)
vincentsarago marked this conversation as resolved.
Show resolved Hide resolved
search_get_request_model: Type[BaseSearchGetRequest] = attr.ib(
default=BaseSearchGetRequest
)
Expand Down
5 changes: 5 additions & 0 deletions stac_fastapi/types/stac_fastapi/types/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
9 changes: 6 additions & 3 deletions stac_fastapi/types/stac_fastapi/types/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -22,6 +23,8 @@
NumType = Union[float, int]
StacType = Dict[str, Any]

api_settings = ApiSettings()


@attr.s # type:ignore
class BaseTransactionsClient(abc.ABC):
Expand Down Expand Up @@ -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,
Expand Down