Skip to content

Commit 6718991

Browse files
authored
feat(config): expand default endpoints (#79)
* add conformance endpoint to default public endpoints * openapi endpoint now defaults to `/api` (matching `stac-fastapi-*`), instead of `null` * swagger ui endpoint now defaults to `/api.html`, matching recommendation by stac docs, instead of `null`
1 parent 58d05ea commit 6718991

File tree

3 files changed

+26
-13
lines changed

3 files changed

+26
-13
lines changed

docs/user-guide/configuration.md

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,7 @@ The application is configurable via environment variables.
124124
"^/$": ["GET"],
125125
"^/api.html$": ["GET"],
126126
"^/api$": ["GET"],
127+
"^/conformance$": ["GET"],
127128
"^/docs/oauth2-redirect": ["GET"],
128129
"^/healthz": ["GET"]
129130
}
@@ -143,9 +144,9 @@ The application is configurable via environment variables.
143144

144145
: Path of OpenAPI specification, used for augmenting spec response with auth configuration
145146

146-
**Type:** string or null
147-
**Required:** No, defaults to `null` (disabled)
148-
**Example:** `/api`
147+
**Type:** string or null
148+
**Required:** No, defaults to `/api`
149+
**Example:** `''` (disabled)
149150

150151
### `OPENAPI_AUTH_SCHEME_NAME`
151152

@@ -175,9 +176,9 @@ The application is configurable via environment variables.
175176

176177
: Path of Swagger UI, used to indicate that a custom Swagger UI should be hosted, typically useful when providing accompanying `SWAGGER_UI_INIT_OAUTH` arguments
177178

178-
**Type:** string or null
179-
**Required:** No, defaults to `null` (disabled)
180-
**Example:** `/api.html`
179+
**Type:** string or null
180+
**Required:** No, defaults to `/api.html`
181+
**Example:** `''` (disabled)
181182

182183
### `SWAGGER_UI_INIT_OAUTH`
183184

src/stac_auth_proxy/app.py

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -80,18 +80,25 @@ async def lifespan(app: FastAPI):
8080
# Handlers (place catch-all proxy handler last)
8181
#
8282

83-
if settings.swagger_ui_endpoint:
84-
assert (
85-
settings.openapi_spec_endpoint
86-
), "openapi_spec_endpoint must be set when using swagger_ui_endpoint"
83+
# If we have customized Swagger UI Init settings (e.g. a provided client_id)
84+
# then we need to serve our own Swagger UI in place of the upstream's. This requires
85+
# that we know the Swagger UI endpoint and the OpenAPI spec endpoint.
86+
if all(
87+
[
88+
settings.swagger_ui_endpoint,
89+
settings.openapi_spec_endpoint,
90+
settings.swagger_ui_init_oauth,
91+
]
92+
):
8793
app.add_route(
8894
settings.swagger_ui_endpoint,
8995
SwaggerUI(
90-
openapi_url=settings.openapi_spec_endpoint,
96+
openapi_url=settings.openapi_spec_endpoint, # type: ignore
9197
init_oauth=settings.swagger_ui_init_oauth,
9298
).route,
9399
include_in_schema=False,
94100
)
101+
95102
if settings.healthz_prefix:
96103
app.include_router(
97104
HealthzHandler(upstream_url=str(settings.upstream_url)).router,

src/stac_auth_proxy/config.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,10 +57,14 @@ class Settings(BaseSettings):
5757
enable_compression: bool = True
5858

5959
# OpenAPI / Swagger UI
60-
openapi_spec_endpoint: Optional[str] = Field(pattern=_PREFIX_PATTERN, default=None)
60+
openapi_spec_endpoint: Optional[str] = Field(
61+
pattern=_PREFIX_PATTERN, default="/api"
62+
)
6163
openapi_auth_scheme_name: str = "oidcAuth"
6264
openapi_auth_scheme_override: Optional[dict] = None
63-
swagger_ui_endpoint: Optional[str] = None
65+
swagger_ui_endpoint: Optional[str] = Field(
66+
pattern=_PREFIX_PATTERN, default="/api.html"
67+
)
6468
swagger_ui_init_oauth: dict = Field(default_factory=dict)
6569

6670
# Auth
@@ -70,6 +74,7 @@ class Settings(BaseSettings):
7074
r"^/$": ["GET"],
7175
r"^/api.html$": ["GET"],
7276
r"^/api$": ["GET"],
77+
r"^/conformance$": ["GET"],
7378
r"^/docs/oauth2-redirect": ["GET"],
7479
r"^/healthz": ["GET"],
7580
}

0 commit comments

Comments
 (0)