Skip to content

Commit 9bc1d34

Browse files
committed
Merge branch 'main' into chore/tests
2 parents b75a2f6 + 6bb3e71 commit 9bc1d34

File tree

11 files changed

+45
-8
lines changed

11 files changed

+45
-8
lines changed

.github/workflows/cicd.yaml

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
on:
2+
- push
3+
4+
jobs:
5+
lint:
6+
runs-on: ubuntu-latest
7+
8+
steps:
9+
- uses: actions/checkout@v4
10+
- uses: actions/setup-python@v3
11+
- uses: pre-commit/[email protected]

.pre-commit-config.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
repos:
22
- repo: https://github.com/abravalheri/validate-pyproject
3-
rev: v0.12.1
3+
rev: v0.23
44
hooks:
55
- id: validate-pyproject
66

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ known_first_party = ["stac_auth_proxy"]
2929
profile = "black"
3030

3131
[tool.ruff]
32-
ignore = ["E501"]
32+
ignore = ["E501", "D203", "D212"]
3333
select = ["D", "E", "F"]
3434

3535
[build-system]

src/stac_auth_proxy/__init__.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
"""STAC Auth Proxy package.
1+
"""
2+
STAC Auth Proxy package.
23
34
This package contains the components for the STAC authentication and proxying system.
45
It includes FastAPI routes for handling authentication, authorization, and interaction

src/stac_auth_proxy/__main__.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
"""Main module for the STAC Auth Proxy."""
2+
13
import uvicorn
24
from uvicorn.config import LOGGING_CONFIG
35

src/stac_auth_proxy/app.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
"""STAC Auth Proxy API.
1+
"""
2+
STAC Auth Proxy API.
23
34
This module defines the FastAPI application for the STAC Auth Proxy, which handles
45
authentication, authorization, and proxying of requests to some internal STAC API.
@@ -16,6 +17,7 @@
1617

1718

1819
def create_app(settings: Optional[Settings] = None) -> FastAPI:
20+
"""FastAPI Application Factory."""
1921
settings = settings or Settings()
2022

2123
app = FastAPI(openapi_url=None)

src/stac_auth_proxy/config.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
"""Configuration for the STAC Auth Proxy."""
2+
13
from typing import Optional, TypeAlias
24

35
from pydantic.networks import HttpUrl
@@ -7,7 +9,9 @@
79

810

911
class Settings(BaseSettings):
10-
upstream_url: HttpUrl = "https://earth-search.aws.element84.com/v1"
12+
"""Configuration settings for the STAC Auth Proxy."""
13+
14+
upstream_url: HttpUrl = HttpUrl(url="https://earth-search.aws.element84.com/v1")
1115
oidc_discovery_url: HttpUrl
1216

1317
# Endpoints
@@ -26,4 +30,6 @@ class Settings(BaseSettings):
2630
openapi_spec_endpoint: Optional[str] = None
2731

2832
class Config:
33+
"""Pydantic configuration."""
34+
2935
env_prefix = "STAC_AUTH_PROXY_"

src/stac_auth_proxy/handlers.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
"""Custom request handlers."""
2+
13
import logging
24
from dataclasses import dataclass
35

@@ -12,14 +14,14 @@
1214

1315
@dataclass
1416
class OpenApiSpecHandler:
17+
"""Handler for OpenAPI spec requests."""
18+
1519
proxy: ReverseProxy
1620
oidc_config_url: str
1721
auth_scheme_name: str = "oidcAuth"
1822

1923
async def dispatch(self, req: Request, res: Response):
20-
"""Proxy the OpenAPI spec from the upstream STAC API, updating it with OIDC security
21-
requirements.
22-
"""
24+
"""Proxy the OpenAPI spec from the upstream STAC API, updating it with OIDC security requirements."""
2325
oidc_spec_response = await self.proxy.proxy_request(req)
2426
openapi_spec = oidc_spec_response.json()
2527

src/stac_auth_proxy/middleware.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,16 @@
1+
"""Custom middleware."""
2+
13
import time
24

35
from fastapi import Request, Response
46
from starlette.middleware.base import BaseHTTPMiddleware
57

68

79
class AddProcessTimeHeaderMiddleware(BaseHTTPMiddleware):
10+
"""Middleware to add a header with the process time to the response."""
11+
812
async def dispatch(self, request: Request, call_next) -> Response:
13+
"""Add a header with the process time to the response."""
914
start_time = time.perf_counter()
1015
response = await call_next(request)
1116
process_time = time.perf_counter() - start_time

src/stac_auth_proxy/proxy.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
"""Tooling to manage the reverse proxying of requests to an upstream STAC API."""
2+
13
import logging
24
import time
35
from dataclasses import dataclass
@@ -13,16 +15,20 @@
1315

1416
@dataclass
1517
class ReverseProxy:
18+
"""Reverse proxy functionality."""
19+
1620
upstream: str
1721
client: httpx.AsyncClient = None
1822

1923
def __post_init__(self):
24+
"""Initialize the HTTP client."""
2025
self.client = self.client or httpx.AsyncClient(
2126
base_url=self.upstream,
2227
timeout=httpx.Timeout(timeout=15.0),
2328
)
2429

2530
async def proxy_request(self, request: Request, *, stream=False) -> httpx.Response:
31+
"""Proxy a request to the upstream STAC API."""
2632
headers = MutableHeaders(request.headers)
2733

2834
# https://github.com/fastapi/fastapi/discussions/7382#discussioncomment-5136466

0 commit comments

Comments
 (0)