Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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 @@

- remove pgstac 0.8.6 in tests and update documentation ([#354](https://github.com/stac-utils/stac-fastapi-pgstac/pull/354))
- simplify `extensions.query.Operator` class, by removing unused `operator` method and unncessary dependencies ([#364](https://github.com/stac-utils/stac-fastapi-pgstac/pull/364))
- handle `ENABLE_TRANSACTIONS_EXTENSIONS`, `ENABLED_EXTENSIONS` and `UVICORN_ROOT_PATH` environment configuration variables via the `config.Settings` class ([#368](https://github.com/stac-utils/stac-fastapi-pgstac/pull/368))

### Added

Expand Down
11 changes: 3 additions & 8 deletions stac_fastapi/pgstac/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
If the variable is not set, enables all extensions.
"""

import os
from contextlib import asynccontextmanager
from typing import cast

Expand Down Expand Up @@ -93,16 +92,12 @@
"collection_search",
}

if ext := os.environ.get("ENABLED_EXTENSIONS"):
if ext := settings.enabled_extensions:
enabled_extensions = set(ext.split(","))

application_extensions: list[ApiExtension] = []

with_transactions = os.environ.get("ENABLE_TRANSACTIONS_EXTENSIONS", "").lower() in [
"yes",
"true",
"1",
]
with_transactions = settings.enable_transactions_extensions
if with_transactions:
application_extensions.append(
TransactionExtension(
Expand Down Expand Up @@ -216,7 +211,7 @@ def run():
port=settings.app_port,
log_level="info",
reload=settings.reload,
root_path=os.getenv("UVICORN_ROOT_PATH", ""),
root_path=settings.uvicorn_root_path,
)
except ImportError as e:
raise RuntimeError("Uvicorn must be installed in order to use command") from e
Expand Down
4 changes: 4 additions & 0 deletions stac_fastapi/pgstac/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,8 @@ class Settings(ApiSettings):
invalid_id_chars: list[str] = DEFAULT_INVALID_ID_CHARS
base_item_cache: type[BaseItemCache] = DefaultBaseItemCache

enabled_extensions: str = ""
enable_transactions_extensions: bool = False
validate_extensions: bool = False
"""
Validate `stac_extensions` schemas against submitted data when creating or updated STAC objects.
Expand All @@ -220,6 +222,8 @@ class Settings(ApiSettings):
"Content-Type",
)

uvicorn_root_path: str = ""

testing: bool = False

@model_validator(mode="after")
Expand Down
15 changes: 15 additions & 0 deletions tests/test_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,21 @@ async def test_pg_settings_attributes(monkeypatch):
)


@pytest.mark.parametrize(
"env_var, expected",
[
("TRUE", True),
("YES", True),
("1", True),
],
)
def test_settings_enable_transactions_extensions(monkeypatch, env_var, expected):
"""Test that enable_transactions_extensions is properly parsed from environment variable."""
monkeypatch.setenv("ENABLE_TRANSACTIONS_EXTENSIONS", env_var)
settings = Settings()
assert settings.enable_transactions_extensions == expected


@pytest.mark.parametrize(
"cors_origins",
[
Expand Down
Loading