stac-fastapi-core 4.0.0__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- stac_fastapi/core/__init__.py +1 -0
- stac_fastapi/core/base_database_logic.py +54 -0
- stac_fastapi/core/base_settings.py +12 -0
- stac_fastapi/core/basic_auth.py +61 -0
- stac_fastapi/core/core.py +1071 -0
- stac_fastapi/core/database_logic.py +226 -0
- stac_fastapi/core/datetime_utils.py +39 -0
- stac_fastapi/core/extensions/__init__.py +5 -0
- stac_fastapi/core/extensions/aggregation.py +577 -0
- stac_fastapi/core/extensions/fields.py +41 -0
- stac_fastapi/core/extensions/filter.py +202 -0
- stac_fastapi/core/extensions/query.py +79 -0
- stac_fastapi/core/models/__init__.py +1 -0
- stac_fastapi/core/models/links.py +205 -0
- stac_fastapi/core/models/search.py +1 -0
- stac_fastapi/core/rate_limit.py +44 -0
- stac_fastapi/core/route_dependencies.py +176 -0
- stac_fastapi/core/serializers.py +177 -0
- stac_fastapi/core/session.py +25 -0
- stac_fastapi/core/utilities.py +164 -0
- stac_fastapi/core/version.py +2 -0
- stac_fastapi_core-4.0.0.dist-info/METADATA +373 -0
- stac_fastapi_core-4.0.0.dist-info/RECORD +25 -0
- stac_fastapi_core-4.0.0.dist-info/WHEEL +5 -0
- stac_fastapi_core-4.0.0.dist-info/top_level.txt +1 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"""Core library."""
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
"""Base database logic."""
|
|
2
|
+
|
|
3
|
+
import abc
|
|
4
|
+
from typing import Any, Dict, Iterable, Optional
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
class BaseDatabaseLogic(abc.ABC):
|
|
8
|
+
"""
|
|
9
|
+
Abstract base class for database logic.
|
|
10
|
+
|
|
11
|
+
This class defines the basic structure and operations for database interactions.
|
|
12
|
+
Subclasses must provide implementations for these methods.
|
|
13
|
+
"""
|
|
14
|
+
|
|
15
|
+
@abc.abstractmethod
|
|
16
|
+
async def get_all_collections(
|
|
17
|
+
self, token: Optional[str], limit: int
|
|
18
|
+
) -> Iterable[Dict[str, Any]]:
|
|
19
|
+
"""Retrieve a list of all collections from the database."""
|
|
20
|
+
pass
|
|
21
|
+
|
|
22
|
+
@abc.abstractmethod
|
|
23
|
+
async def get_one_item(self, collection_id: str, item_id: str) -> Dict:
|
|
24
|
+
"""Retrieve a single item from the database."""
|
|
25
|
+
pass
|
|
26
|
+
|
|
27
|
+
@abc.abstractmethod
|
|
28
|
+
async def create_item(self, item: Dict, refresh: bool = False) -> None:
|
|
29
|
+
"""Create an item in the database."""
|
|
30
|
+
pass
|
|
31
|
+
|
|
32
|
+
@abc.abstractmethod
|
|
33
|
+
async def delete_item(
|
|
34
|
+
self, item_id: str, collection_id: str, refresh: bool = False
|
|
35
|
+
) -> None:
|
|
36
|
+
"""Delete an item from the database."""
|
|
37
|
+
pass
|
|
38
|
+
|
|
39
|
+
@abc.abstractmethod
|
|
40
|
+
async def create_collection(self, collection: Dict, refresh: bool = False) -> None:
|
|
41
|
+
"""Create a collection in the database."""
|
|
42
|
+
pass
|
|
43
|
+
|
|
44
|
+
@abc.abstractmethod
|
|
45
|
+
async def find_collection(self, collection_id: str) -> Dict:
|
|
46
|
+
"""Find a collection in the database."""
|
|
47
|
+
pass
|
|
48
|
+
|
|
49
|
+
@abc.abstractmethod
|
|
50
|
+
async def delete_collection(
|
|
51
|
+
self, collection_id: str, refresh: bool = False
|
|
52
|
+
) -> None:
|
|
53
|
+
"""Delete a collection from the database."""
|
|
54
|
+
pass
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
"""Basic Authentication Module."""
|
|
2
|
+
|
|
3
|
+
import logging
|
|
4
|
+
import secrets
|
|
5
|
+
|
|
6
|
+
from fastapi import Depends, HTTPException, status
|
|
7
|
+
from fastapi.security import HTTPBasic, HTTPBasicCredentials
|
|
8
|
+
from typing_extensions import Annotated
|
|
9
|
+
|
|
10
|
+
_LOGGER = logging.getLogger("uvicorn.default")
|
|
11
|
+
_SECURITY = HTTPBasic()
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
class BasicAuth:
|
|
15
|
+
"""Apply basic authentication to the provided FastAPI application \
|
|
16
|
+
based on environment variables for username, password, and endpoints."""
|
|
17
|
+
|
|
18
|
+
def __init__(self, credentials: list) -> None:
|
|
19
|
+
"""Generate basic_auth property."""
|
|
20
|
+
self.basic_auth = {}
|
|
21
|
+
for credential in credentials:
|
|
22
|
+
self.basic_auth[credential["username"]] = credential
|
|
23
|
+
|
|
24
|
+
async def __call__(
|
|
25
|
+
self,
|
|
26
|
+
credentials: Annotated[HTTPBasicCredentials, Depends(_SECURITY)],
|
|
27
|
+
) -> str:
|
|
28
|
+
"""Check if the provided credentials match the expected \
|
|
29
|
+
username and password stored in basic_auth.
|
|
30
|
+
|
|
31
|
+
Args:
|
|
32
|
+
credentials (HTTPBasicCredentials): The HTTP basic authentication credentials.
|
|
33
|
+
|
|
34
|
+
Returns:
|
|
35
|
+
str: The username if authentication is successful.
|
|
36
|
+
|
|
37
|
+
Raises:
|
|
38
|
+
HTTPException: If authentication fails due to incorrect username or password.
|
|
39
|
+
"""
|
|
40
|
+
user = self.basic_auth.get(credentials.username)
|
|
41
|
+
|
|
42
|
+
if not user:
|
|
43
|
+
raise HTTPException(
|
|
44
|
+
status_code=status.HTTP_401_UNAUTHORIZED,
|
|
45
|
+
detail="Incorrect username or password",
|
|
46
|
+
headers={"WWW-Authenticate": "Basic"},
|
|
47
|
+
)
|
|
48
|
+
|
|
49
|
+
# Compare the provided username and password with the correct ones using compare_digest
|
|
50
|
+
if not secrets.compare_digest(
|
|
51
|
+
credentials.username.encode("utf-8"), user.get("username").encode("utf-8")
|
|
52
|
+
) or not secrets.compare_digest(
|
|
53
|
+
credentials.password.encode("utf-8"), user.get("password").encode("utf-8")
|
|
54
|
+
):
|
|
55
|
+
raise HTTPException(
|
|
56
|
+
status_code=status.HTTP_401_UNAUTHORIZED,
|
|
57
|
+
detail="Incorrect username or password",
|
|
58
|
+
headers={"WWW-Authenticate": "Basic"},
|
|
59
|
+
)
|
|
60
|
+
|
|
61
|
+
return credentials.username
|