Skip to content

Commit 9a06de7

Browse files
committed
pre-commit cleanup
1 parent 631ecb7 commit 9a06de7

File tree

13 files changed

+43
-35
lines changed

13 files changed

+43
-35
lines changed

src/stac_auth_proxy/app.py

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,17 +10,16 @@
1010

1111
from fastapi import FastAPI
1212

13+
from .config import Settings
14+
from .handlers import ReverseProxyHandler
1315
from .middleware import (
14-
OpenApiMiddleware,
1516
AddProcessTimeHeaderMiddleware,
16-
EnforceAuthMiddleware,
17-
BuildCql2FilterMiddleware,
1817
ApplyCql2FilterMiddleware,
18+
BuildCql2FilterMiddleware,
19+
EnforceAuthMiddleware,
20+
OpenApiMiddleware,
1921
)
2022

21-
from .config import Settings
22-
from .handlers import ReverseProxyHandler
23-
2423
logger = logging.getLogger(__name__)
2524

2625

src/stac_auth_proxy/filters/template.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
11
"""Generate CQL2 filter expressions via Jinja2 templating."""
22

3-
from typing import Any
43
from dataclasses import dataclass, field
4+
from typing import Any
55

66
from cql2 import Expr
7-
from fastapi import Request
87
from jinja2 import BaseLoader, Environment
98

109

src/stac_auth_proxy/handlers/reverse_proxy.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010
from starlette.datastructures import MutableHeaders
1111
from starlette.responses import StreamingResponse
1212

13-
1413
logger = logging.getLogger(__name__)
1514

1615

src/stac_auth_proxy/middleware/AddProcessTimeHeaderMiddleware.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
1-
from fastapi import Request, Response
2-
from starlette.middleware.base import BaseHTTPMiddleware
3-
1+
"""Middleware to add a header with the process time to the response."""
42

53
import time
64

5+
from fastapi import Request, Response
6+
from starlette.middleware.base import BaseHTTPMiddleware
7+
78

89
class AddProcessTimeHeaderMiddleware(BaseHTTPMiddleware):
910
"""Middleware to add a header with the process time to the response."""

src/stac_auth_proxy/middleware/Cql2FilterMiddleware.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
1-
from logging import getLogger
1+
"""Middleware to build and apply CQL2 filters."""
2+
23
import json
34
from dataclasses import dataclass
5+
from logging import getLogger
46
from typing import Callable, Optional
57

68
from cql2 import Expr
7-
from starlette.types import ASGIApp, Message, Receive, Scope, Send
89
from starlette.requests import Request
10+
from starlette.types import ASGIApp, Message, Receive, Scope, Send
911

1012
from ..utils import filters, requests
1113

@@ -25,6 +27,7 @@ class BuildCql2FilterMiddleware:
2527
state_key: str = "cql2_filter"
2628

2729
async def __call__(self, scope: Scope, receive: Receive, send: Send) -> None:
30+
"""Build the CQL2 filter, place on the request state."""
2831
if scope["type"] != "http":
2932
return await self.app(scope, receive, send)
3033

@@ -35,6 +38,7 @@ async def __call__(self, scope: Scope, receive: Receive, send: Send) -> None:
3538
return await self.app(scope, receive, send)
3639

3740
async def set_filter(body: Optional[dict] = None) -> None:
41+
assert filter_builder is not None
3842
cql2_filter = await filter_builder(
3943
{
4044
"req": {

src/stac_auth_proxy/middleware/EnforceAuthMiddleware.py

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,16 @@
1-
from dataclasses import dataclass, field
2-
from typing import Annotated, Optional, Sequence
1+
"""Middleware to enforce authentication."""
2+
33
import json
44
import logging
55
import urllib.request
6+
from dataclasses import dataclass, field
7+
from typing import Annotated, Optional, Sequence
68

7-
from fastapi import HTTPException, Security, status, Request
9+
import jwt
10+
from fastapi import HTTPException, Request, Security, status
811
from pydantic import HttpUrl
9-
from starlette.middleware.base import ASGIApp
1012
from starlette.responses import JSONResponse
1113
from starlette.types import ASGIApp, Receive, Scope, Send
12-
import jwt
1314

1415
from ..config import EndpointMethods
1516
from ..utils.requests import matches_route

src/stac_auth_proxy/middleware/UpdateOpenApiMiddleware.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
1+
"""Middleware to add auth information to the OpenAPI spec served by upstream API."""
2+
13
import json
24
from dataclasses import dataclass
35
from typing import Any
46

5-
from starlette.types import ASGIApp, Message, Receive, Scope, Send
67
from starlette.requests import Request
8+
from starlette.types import ASGIApp, Message, Receive, Scope, Send
79

810
from ..config import EndpointMethods
911
from ..utils.requests import dict_to_bytes
@@ -52,6 +54,7 @@ async def augment_oidc_spec(message: Message):
5254
return await self.app(scope, receive, augment_oidc_spec)
5355

5456
def augment_spec(self, openapi_spec) -> dict[str, Any]:
57+
"""Augment the OpenAPI spec with auth information."""
5558
components = openapi_spec.setdefault("components", {})
5659
securitySchemes = components.setdefault("securitySchemes", {})
5760
securitySchemes[self.oidc_auth_scheme_name] = {
Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,17 @@
11
"""Custom middleware."""
22

3-
from .UpdateOpenApiMiddleware import OpenApiMiddleware
43
from .AddProcessTimeHeaderMiddleware import AddProcessTimeHeaderMiddleware
4+
from .Cql2FilterMiddleware import ApplyCql2FilterMiddleware, BuildCql2FilterMiddleware
55
from .EnforceAuthMiddleware import EnforceAuthMiddleware
6-
from .Cql2FilterMiddleware import BuildCql2FilterMiddleware, ApplyCql2FilterMiddleware
6+
from .UpdateOpenApiMiddleware import OpenApiMiddleware
77

88
__all__ = [
9-
OpenApiMiddleware,
10-
AddProcessTimeHeaderMiddleware,
11-
EnforceAuthMiddleware,
12-
BuildCql2FilterMiddleware,
13-
ApplyCql2FilterMiddleware,
9+
x.__name__
10+
for x in [
11+
OpenApiMiddleware,
12+
AddProcessTimeHeaderMiddleware,
13+
EnforceAuthMiddleware,
14+
BuildCql2FilterMiddleware,
15+
ApplyCql2FilterMiddleware,
16+
]
1417
]

src/stac_auth_proxy/utils/requests.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,9 +40,8 @@ def dict_to_bytes(d: dict) -> bytes:
4040

4141
def matches_route(request: Request, url_patterns: dict[str, list[str]]) -> bool:
4242
"""
43-
Returns True if the incoming request.path and request.method
44-
match any of the patterns (and their methods) in url_patterns.
45-
Otherwise returns False.
43+
Test if the incoming request.path and request.method match any of the patterns
44+
(and their methods) in url_patterns.
4645
"""
4746
path = request.url.path # e.g. '/collections/123'
4847
method = request.method.casefold() # e.g. 'post'

tests/conftest.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
import os
55
import threading
66
from typing import Any, AsyncGenerator
7-
from unittest.mock import AsyncMock, MagicMock, patch, DEFAULT
7+
from unittest.mock import DEFAULT, AsyncMock, MagicMock, patch
88

99
import pytest
1010
import uvicorn

0 commit comments

Comments
 (0)