Skip to content

Commit 260b098

Browse files
committed
chore: add pre-commit github action
1 parent 0c5cf4e commit 260b098

File tree

11 files changed

+67
-18
lines changed

11 files changed

+67
-18
lines changed

.github/workflows/cicd.yaml

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
on:
2+
- push
3+
4+
jobs:
5+
lint:
6+
runs-on: ubuntu-latest
7+
8+
steps:
9+
- uses: actions/checkout@v4
10+
11+
- name: Restore cached virtualenv
12+
uses: actions/cache/restore@v4
13+
with:
14+
key: venv-${{ runner.os }}-${{ hashFiles('uv.lock') }}
15+
path: .venv
16+
17+
- name: Install uv
18+
uses: astral-sh/setup-uv@v4
19+
20+
- name: Run pre-commit
21+
run: uv run pre-commit run --all-files
22+
23+
- name: Saved cached virtualenv
24+
uses: actions/cache/save@v4
25+
if: always()
26+
with:
27+
key: venv-${{ runner.os }}-${{ hashFiles('uv.lock') }}
28+
path: .venv

.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 & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
1+
"""Main module for the STAC Auth Proxy."""
2+
13
import uvicorn
24
from uvicorn.config import LOGGING_CONFIG
35

4-
56
LOGGING_CONFIG["loggers"][__package__] = {
67
"level": "DEBUG",
78
"handlers": ["default"],

src/stac_auth_proxy/app.py

Lines changed: 5 additions & 3 deletions
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.
@@ -9,13 +10,14 @@
910
from fastapi import Depends, FastAPI
1011
from fastapi.security import OpenIdConnect
1112

12-
from .proxy import ReverseProxy
1313
from .config import Settings
14-
from .middleware import AddProcessTimeHeaderMiddleware
1514
from .handlers import OpenApiSpecHandler
15+
from .middleware import AddProcessTimeHeaderMiddleware
16+
from .proxy import ReverseProxy
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: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
1-
from dataclasses import dataclass
1+
"""Custom request handlers."""
2+
23
import logging
4+
from dataclasses import dataclass
35

46
from fastapi import Request, Response
57
from fastapi.routing import APIRoute
@@ -12,15 +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-
"""
21-
Proxy the OpenAPI spec from the upstream STAC API, updating it with OIDC security
22-
requirements.
23-
"""
24+
"""Proxy the OpenAPI spec from the upstream STAC API, updating it with OIDC security requirements."""
2425
oidc_spec_response = await self.proxy.proxy_request(req)
2526
openapi_spec = oidc_spec_response.json()
2627

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: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,34 @@
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
46

57
import httpx
68
from fastapi import Request
9+
from starlette.background import BackgroundTask
710
from starlette.datastructures import MutableHeaders
811
from starlette.responses import StreamingResponse
9-
from starlette.background import BackgroundTask
10-
1112

1213
logger = logging.getLogger(__name__)
1314

1415

1516
@dataclass
1617
class ReverseProxy:
18+
"""Reverse proxy functionality."""
19+
1720
upstream: str
1821
client: httpx.AsyncClient = None
1922

2023
def __post_init__(self):
24+
"""Initialize the HTTP client."""
2125
self.client = self.client or httpx.AsyncClient(
2226
base_url=self.upstream,
2327
timeout=httpx.Timeout(timeout=15.0),
2428
)
2529

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

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

src/stac_auth_proxy/utils.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1+
"""Utility functions."""
2+
13
from httpx import Headers
24

35

46
def safe_headers(headers: Headers) -> dict[str, str]:
5-
"""
6-
Scrub headers that should not be proxied to the client.
7-
"""
7+
"""Scrub headers that should not be proxied to the client."""
88
excluded_headers = [
99
"content-length",
1010
"content-encoding",

0 commit comments

Comments
 (0)