Skip to content

Commit db1eca5

Browse files
committed
pre-commit cleanup
1 parent 22811ae commit db1eca5

File tree

2 files changed

+6
-7
lines changed

2 files changed

+6
-7
lines changed

src/stac_auth_proxy/middleware/UpdateOpenApiMiddleware.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,20 @@
11
"""Middleware to add auth information to the OpenAPI spec served by upstream API."""
22

3-
import brotli
43
import gzip
54
import json
65
import re
76
import zlib
87
from dataclasses import dataclass
9-
from typing import Any
8+
from typing import Any, Optional
109

10+
import brotli
1111
from starlette.datastructures import MutableHeaders
1212
from starlette.requests import Request
1313
from starlette.types import ASGIApp, Message, Receive, Scope, Send
1414

1515
from ..config import EndpointMethods
1616
from ..utils.requests import dict_to_bytes
1717

18-
1918
ENCODING_HANDLERS = {
2019
"gzip": gzip,
2120
"deflate": zlib,
@@ -40,7 +39,7 @@ async def __call__(self, scope: Scope, receive: Receive, send: Send) -> None:
4039
if scope["type"] != "http" or Request(scope).url.path != self.openapi_spec_path:
4140
return await self.app(scope, receive, send)
4241

43-
start_message = None
42+
start_message: Optional[Message] = None
4443
body = b""
4544

4645
async def augment_oidc_spec(message: Message):
@@ -80,6 +79,7 @@ async def augment_oidc_spec(message: Message):
8079

8180
# Update the content-length header
8281
headers["content-length"] = str(len(body))
82+
assert start_message, "Expected start_message to be set"
8383
start_message["headers"] = [
8484
(key.encode(), value.encode()) for key, value in headers.items()
8585
]
@@ -120,7 +120,7 @@ def augment_spec(self, openapi_spec) -> dict[str, Any]:
120120
return openapi_spec
121121

122122
@staticmethod
123-
def path_matches(path: str, method: str, endpoints: dict[str, list[str]]) -> bool:
123+
def path_matches(path: str, method: str, endpoints: EndpointMethods) -> bool:
124124
"""Check if the given path and method match any of the regex patterns and methods in the endpoints."""
125125
for pattern, endpoint_methods in endpoints.items():
126126
if not re.match(pattern, path):

tests/test_openapi.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
11
"""Tests for OpenAPI spec handling."""
22

3+
34
from fastapi import FastAPI
45
from fastapi.testclient import TestClient
56
from utils import AppFactory
6-
import gzip
7-
from fastapi import Request, Response
87

98
app_factory = AppFactory(
109
oidc_discovery_url="https://example-stac-api.com/.well-known/openid-configuration"

0 commit comments

Comments
 (0)