Skip to content

Commit 216e01d

Browse files
committed
chore: cleanup config
1 parent 4b1f4d1 commit 216e01d

File tree

3 files changed

+22
-17
lines changed

3 files changed

+22
-17
lines changed

docker-compose.yaml

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -46,10 +46,8 @@ services:
4646
build:
4747
context: .
4848
environment:
49-
STAC_AUTH_PROXY_UPSTREAM_URL: ${STAC_AUTH_PROXY_UPSTREAM_URL:-http://stac:8001}
50-
STAC_AUTH_PROXY_OIDC_DISCOVERY_URL: ${STAC_AUTH_PROXY_OIDC_DISCOVERY_URL}
51-
ports:
52-
- "8000:8000"
49+
UPSTREAM_URL: ${UPSTREAM_URL:-http://stac:8001}
50+
OIDC_DISCOVERY_URL: ${OIDC_DISCOVERY_URL:-https://accounts.google.com/.well-known/openid-configuration}
5351
env_file:
5452
- path: .env
5553
required: false

src/stac_auth_proxy/config.py

Lines changed: 17 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,15 @@
11
"""Configuration for the STAC Auth Proxy."""
22

33
import importlib
4-
from typing import Optional, Sequence, TypeAlias
4+
from typing import Literal, Optional, Sequence, TypeAlias
55

66
from pydantic import BaseModel, Field
77
from pydantic.networks import HttpUrl
88
from pydantic_settings import BaseSettings, SettingsConfigDict
99

10-
EndpointMethods: TypeAlias = dict[str, list[str]]
10+
EndpointMethods: TypeAlias = dict[
11+
str, list[Literal["GET", "POST", "PUT", "DELETE", "PATCH"]]
12+
]
1113
_PREFIX_PATTERN = r"^/.*$"
1214

1315

@@ -29,12 +31,21 @@ def __call__(self):
2931
class Settings(BaseSettings):
3032
"""Configuration settings for the STAC Auth Proxy."""
3133

32-
upstream_url: HttpUrl = HttpUrl(url="https://earth-search.aws.element84.com/v1")
34+
# External URLs
35+
upstream_url: HttpUrl
3336
oidc_discovery_url: HttpUrl
3437

3538
# Endpoints
3639
healthz_prefix: str = Field(pattern=_PREFIX_PATTERN, default="/healthz")
40+
openapi_spec_endpoint: Optional[str] = Field(pattern=_PREFIX_PATTERN, default=None)
41+
42+
# Auth
3743
default_public: bool = False
44+
public_endpoints: EndpointMethods = {
45+
r"^/api.html$": ["GET"],
46+
r"^/api$": ["GET"],
47+
r"^/healthz": ["GET"],
48+
}
3849
private_endpoints: EndpointMethods = {
3950
# https://github.com/stac-api-extensions/collection-transaction/blob/v1.0.0-beta.1/README.md#methods
4051
r"^/collections$": ["POST"],
@@ -45,18 +56,12 @@ class Settings(BaseSettings):
4556
# https://stac-utils.github.io/stac-fastapi/api/stac_fastapi/extensions/third_party/bulk_transactions/#bulktransactionextension
4657
r"^/collections/([^/]+)/bulk_items$": ["POST"],
4758
}
48-
public_endpoints: EndpointMethods = {r"^/api.html$": ["GET"], r"^/api$": ["GET"]}
49-
openapi_spec_endpoint: Optional[str] = None
50-
51-
# collections_filter: Optional[ClassInput] = None
52-
# collections_filter_endpoints: Optional[EndpointMethods] = {
53-
# r"^/collections$": ["GET"],
54-
# r"^/collections$/([^/]+)": ["GET"],
55-
# }
59+
60+
# Filters
5661
items_filter: Optional[ClassInput] = None
5762
items_filter_endpoints: Optional[EndpointMethods] = {
5863
r"^/search$": ["POST"],
5964
r"^/collections/([^/]+)/items$": ["GET", "POST"],
6065
}
6166

62-
model_config = SettingsConfigDict(env_prefix="STAC_AUTH_PROXY_")
67+
model_config = SettingsConfigDict()

src/stac_auth_proxy/utils/requests.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66

77
from starlette.requests import Request
88

9+
from ..config import EndpointMethods
10+
911

1012
def extract_variables(url: str) -> dict:
1113
"""
@@ -24,7 +26,7 @@ def dict_to_bytes(d: dict) -> bytes:
2426
return json.dumps(d, separators=(",", ":")).encode("utf-8")
2527

2628

27-
def matches_route(request: Request, url_patterns: dict[str, list[str]]) -> bool:
29+
def matches_route(request: Request, url_patterns: EndpointMethods) -> bool:
2830
"""
2931
Test if the incoming request.path and request.method match any of the patterns
3032
(and their methods) in url_patterns.

0 commit comments

Comments
 (0)