stac-fastapi.core 2.3.0__tar.gz → 2.3.1__tar.gz

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.
Files changed (27) hide show
  1. {stac_fastapi_core-2.3.0 → stac_fastapi_core-2.3.1}/PKG-INFO +5 -4
  2. {stac_fastapi_core-2.3.0 → stac_fastapi_core-2.3.1}/setup.py +4 -3
  3. stac_fastapi_core-2.3.1/stac_fastapi/core/basic_auth.py +115 -0
  4. {stac_fastapi_core-2.3.0 → stac_fastapi_core-2.3.1}/stac_fastapi/core/core.py +1 -1
  5. {stac_fastapi_core-2.3.0 → stac_fastapi_core-2.3.1}/stac_fastapi/core/version.py +1 -1
  6. {stac_fastapi_core-2.3.0 → stac_fastapi_core-2.3.1}/stac_fastapi.core.egg-info/PKG-INFO +5 -4
  7. {stac_fastapi_core-2.3.0 → stac_fastapi_core-2.3.1}/stac_fastapi.core.egg-info/SOURCES.txt +1 -0
  8. {stac_fastapi_core-2.3.0 → stac_fastapi_core-2.3.1}/stac_fastapi.core.egg-info/requires.txt +4 -3
  9. {stac_fastapi_core-2.3.0 → stac_fastapi_core-2.3.1}/README.md +0 -0
  10. {stac_fastapi_core-2.3.0 → stac_fastapi_core-2.3.1}/setup.cfg +0 -0
  11. {stac_fastapi_core-2.3.0 → stac_fastapi_core-2.3.1}/stac_fastapi/core/__init__.py +0 -0
  12. {stac_fastapi_core-2.3.0 → stac_fastapi_core-2.3.1}/stac_fastapi/core/base_database_logic.py +0 -0
  13. {stac_fastapi_core-2.3.0 → stac_fastapi_core-2.3.1}/stac_fastapi/core/base_settings.py +0 -0
  14. {stac_fastapi_core-2.3.0 → stac_fastapi_core-2.3.1}/stac_fastapi/core/datetime_utils.py +0 -0
  15. {stac_fastapi_core-2.3.0 → stac_fastapi_core-2.3.1}/stac_fastapi/core/extensions/__init__.py +0 -0
  16. {stac_fastapi_core-2.3.0 → stac_fastapi_core-2.3.1}/stac_fastapi/core/extensions/filter.py +0 -0
  17. {stac_fastapi_core-2.3.0 → stac_fastapi_core-2.3.1}/stac_fastapi/core/extensions/query.py +0 -0
  18. {stac_fastapi_core-2.3.0 → stac_fastapi_core-2.3.1}/stac_fastapi/core/models/__init__.py +0 -0
  19. {stac_fastapi_core-2.3.0 → stac_fastapi_core-2.3.1}/stac_fastapi/core/models/links.py +0 -0
  20. {stac_fastapi_core-2.3.0 → stac_fastapi_core-2.3.1}/stac_fastapi/core/models/search.py +0 -0
  21. {stac_fastapi_core-2.3.0 → stac_fastapi_core-2.3.1}/stac_fastapi/core/serializers.py +0 -0
  22. {stac_fastapi_core-2.3.0 → stac_fastapi_core-2.3.1}/stac_fastapi/core/session.py +0 -0
  23. {stac_fastapi_core-2.3.0 → stac_fastapi_core-2.3.1}/stac_fastapi/core/types/core.py +0 -0
  24. {stac_fastapi_core-2.3.0 → stac_fastapi_core-2.3.1}/stac_fastapi/core/utilities.py +0 -0
  25. {stac_fastapi_core-2.3.0 → stac_fastapi_core-2.3.1}/stac_fastapi.core.egg-info/dependency_links.txt +0 -0
  26. {stac_fastapi_core-2.3.0 → stac_fastapi_core-2.3.1}/stac_fastapi.core.egg-info/not-zip-safe +0 -0
  27. {stac_fastapi_core-2.3.0 → stac_fastapi_core-2.3.1}/stac_fastapi.core.egg-info/top_level.txt +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: stac-fastapi.core
3
- Version: 2.3.0
3
+ Version: 2.3.1
4
4
  Summary: Core library for the Elasticsearch and Opensearch stac-fastapi backends.
5
5
  Home-page: https://github.com/stac-utils/stac-fastapi-elasticsearch-opensearch
6
6
  License: MIT
@@ -18,13 +18,14 @@ Requires-Dist: fastapi
18
18
  Requires-Dist: attrs
19
19
  Requires-Dist: pydantic[dotenv]<2
20
20
  Requires-Dist: stac_pydantic==2.0.*
21
- Requires-Dist: stac-fastapi.types==2.5.3
22
- Requires-Dist: stac-fastapi.api==2.5.3
23
- Requires-Dist: stac-fastapi.extensions==2.5.3
21
+ Requires-Dist: stac-fastapi.types==2.5.5.post1
22
+ Requires-Dist: stac-fastapi.api==2.5.5.post1
23
+ Requires-Dist: stac-fastapi.extensions==2.5.5.post1
24
24
  Requires-Dist: pystac[validation]
25
25
  Requires-Dist: orjson
26
26
  Requires-Dist: overrides
27
27
  Requires-Dist: geojson-pydantic
28
28
  Requires-Dist: pygeofilter==0.2.1
29
+ Requires-Dist: typing_extensions==4.4.0
29
30
 
30
31
  # stac-fastapi core library for Elasticsearch and Opensearch backends
@@ -10,14 +10,15 @@ install_requires = [
10
10
  "attrs",
11
11
  "pydantic[dotenv]<2",
12
12
  "stac_pydantic==2.0.*",
13
- "stac-fastapi.types==2.5.3",
14
- "stac-fastapi.api==2.5.3",
15
- "stac-fastapi.extensions==2.5.3",
13
+ "stac-fastapi.types==2.5.5.post1",
14
+ "stac-fastapi.api==2.5.5.post1",
15
+ "stac-fastapi.extensions==2.5.5.post1",
16
16
  "pystac[validation]",
17
17
  "orjson",
18
18
  "overrides",
19
19
  "geojson-pydantic",
20
20
  "pygeofilter==0.2.1",
21
+ "typing_extensions==4.4.0",
21
22
  ]
22
23
 
23
24
  setup(
@@ -0,0 +1,115 @@
1
+ """Basic Authentication Module."""
2
+
3
+ import json
4
+ import logging
5
+ import os
6
+ import secrets
7
+ from typing import Any, Dict
8
+
9
+ from fastapi import Depends, HTTPException, Request, status
10
+ from fastapi.routing import APIRoute
11
+ from fastapi.security import HTTPBasic, HTTPBasicCredentials
12
+ from typing_extensions import Annotated
13
+
14
+ from stac_fastapi.api.app import StacApi
15
+
16
+ _LOGGER = logging.getLogger("uvicorn.default")
17
+ _SECURITY = HTTPBasic()
18
+ _BASIC_AUTH: Dict[str, Any] = {}
19
+
20
+
21
+ def has_access(
22
+ request: Request, credentials: Annotated[HTTPBasicCredentials, Depends(_SECURITY)]
23
+ ) -> str:
24
+ """Check if the provided credentials match the expected \
25
+ username and password stored in environment variables for basic authentication.
26
+
27
+ Args:
28
+ request (Request): The FastAPI request object.
29
+ credentials (HTTPBasicCredentials): The HTTP basic authentication credentials.
30
+
31
+ Returns:
32
+ str: The username if authentication is successful.
33
+
34
+ Raises:
35
+ HTTPException: If authentication fails due to incorrect username or password.
36
+ """
37
+ global _BASIC_AUTH
38
+
39
+ users = _BASIC_AUTH.get("users")
40
+ user: Dict[str, Any] = next(
41
+ (u for u in users if u.get("username") == credentials.username), {}
42
+ )
43
+
44
+ if not user:
45
+ raise HTTPException(
46
+ status_code=status.HTTP_401_UNAUTHORIZED,
47
+ detail="Incorrect username or password",
48
+ headers={"WWW-Authenticate": "Basic"},
49
+ )
50
+
51
+ # Compare the provided username and password with the correct ones using compare_digest
52
+ if not secrets.compare_digest(
53
+ credentials.username.encode("utf-8"), user.get("username").encode("utf-8")
54
+ ) or not secrets.compare_digest(
55
+ credentials.password.encode("utf-8"), user.get("password").encode("utf-8")
56
+ ):
57
+ raise HTTPException(
58
+ status_code=status.HTTP_401_UNAUTHORIZED,
59
+ detail="Incorrect username or password",
60
+ headers={"WWW-Authenticate": "Basic"},
61
+ )
62
+
63
+ permissions = user.get("permissions", [])
64
+ path = request.url.path
65
+ method = request.method
66
+
67
+ if permissions == "*":
68
+ return credentials.username
69
+ for permission in permissions:
70
+ if permission["path"] == path and method in permission.get("method", []):
71
+ return credentials.username
72
+
73
+ raise HTTPException(
74
+ status_code=status.HTTP_403_FORBIDDEN,
75
+ detail=f"Insufficient permissions for [{method} {path}]",
76
+ )
77
+
78
+
79
+ def apply_basic_auth(api: StacApi) -> None:
80
+ """Apply basic authentication to the provided FastAPI application \
81
+ based on environment variables for username, password, and endpoints.
82
+
83
+ Args:
84
+ api (StacApi): The FastAPI application.
85
+
86
+ Raises:
87
+ HTTPException: If there are issues with the configuration or format
88
+ of the environment variables.
89
+ """
90
+ global _BASIC_AUTH
91
+
92
+ basic_auth_json_str = os.environ.get("BASIC_AUTH")
93
+ if not basic_auth_json_str:
94
+ _LOGGER.info("Basic authentication disabled.")
95
+ return
96
+
97
+ try:
98
+ _BASIC_AUTH = json.loads(basic_auth_json_str)
99
+ except json.JSONDecodeError as exception:
100
+ _LOGGER.error(f"Invalid JSON format for BASIC_AUTH. {exception=}")
101
+ raise
102
+ public_endpoints = _BASIC_AUTH.get("public_endpoints", [])
103
+ users = _BASIC_AUTH.get("users")
104
+ if not users:
105
+ raise Exception("Invalid JSON format for BASIC_AUTH. Key 'users' undefined.")
106
+
107
+ app = api.app
108
+ for route in app.routes:
109
+ if isinstance(route, APIRoute):
110
+ for method in route.methods:
111
+ endpoint = {"path": route.path, "method": method}
112
+ if endpoint not in public_endpoints:
113
+ api.add_route_dependencies([endpoint], [Depends(has_access)])
114
+
115
+ _LOGGER.info("Basic authentication enabled.")
@@ -677,7 +677,7 @@ class TransactionsClient(AsyncBaseTransactionsClient):
677
677
  else:
678
678
  item = await self.database.prep_create_item(item=item, base_url=base_url)
679
679
  await self.database.create_item(item, refresh=kwargs.get("refresh", False))
680
- return item
680
+ return ItemSerializer.db_to_stac(item, base_url)
681
681
 
682
682
  @overrides
683
683
  async def update_item(
@@ -1,2 +1,2 @@
1
1
  """library version."""
2
- __version__ = "2.3.0"
2
+ __version__ = "2.3.1"
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: stac-fastapi.core
3
- Version: 2.3.0
3
+ Version: 2.3.1
4
4
  Summary: Core library for the Elasticsearch and Opensearch stac-fastapi backends.
5
5
  Home-page: https://github.com/stac-utils/stac-fastapi-elasticsearch-opensearch
6
6
  License: MIT
@@ -18,13 +18,14 @@ Requires-Dist: fastapi
18
18
  Requires-Dist: attrs
19
19
  Requires-Dist: pydantic[dotenv]<2
20
20
  Requires-Dist: stac_pydantic==2.0.*
21
- Requires-Dist: stac-fastapi.types==2.5.3
22
- Requires-Dist: stac-fastapi.api==2.5.3
23
- Requires-Dist: stac-fastapi.extensions==2.5.3
21
+ Requires-Dist: stac-fastapi.types==2.5.5.post1
22
+ Requires-Dist: stac-fastapi.api==2.5.5.post1
23
+ Requires-Dist: stac-fastapi.extensions==2.5.5.post1
24
24
  Requires-Dist: pystac[validation]
25
25
  Requires-Dist: orjson
26
26
  Requires-Dist: overrides
27
27
  Requires-Dist: geojson-pydantic
28
28
  Requires-Dist: pygeofilter==0.2.1
29
+ Requires-Dist: typing_extensions==4.4.0
29
30
 
30
31
  # stac-fastapi core library for Elasticsearch and Opensearch backends
@@ -10,6 +10,7 @@ stac_fastapi.core.egg-info/top_level.txt
10
10
  stac_fastapi/core/__init__.py
11
11
  stac_fastapi/core/base_database_logic.py
12
12
  stac_fastapi/core/base_settings.py
13
+ stac_fastapi/core/basic_auth.py
13
14
  stac_fastapi/core/core.py
14
15
  stac_fastapi/core/datetime_utils.py
15
16
  stac_fastapi/core/serializers.py
@@ -2,11 +2,12 @@ fastapi
2
2
  attrs
3
3
  pydantic[dotenv]<2
4
4
  stac_pydantic==2.0.*
5
- stac-fastapi.types==2.5.3
6
- stac-fastapi.api==2.5.3
7
- stac-fastapi.extensions==2.5.3
5
+ stac-fastapi.types==2.5.5.post1
6
+ stac-fastapi.api==2.5.5.post1
7
+ stac-fastapi.extensions==2.5.5.post1
8
8
  pystac[validation]
9
9
  orjson
10
10
  overrides
11
11
  geojson-pydantic
12
12
  pygeofilter==0.2.1
13
+ typing_extensions==4.4.0