Skip to content

Commit 0faee7b

Browse files
committed
Push keycloak config to env vars
1 parent 2fee7d8 commit 0faee7b

File tree

3 files changed

+13
-10
lines changed

3 files changed

+13
-10
lines changed

docker-compose.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,10 @@ services:
4444
- POSTGRES_PORT=5432
4545
- DB_MIN_CONN_SIZE=1
4646
- DB_MAX_CONN_SIZE=10
47+
- KEYCLOAK_REALM=eoapi
48+
- KEYCLOAK_HOST=http://localhost:8080
49+
- KEYCLOAK_CLIENT_ID=stac-api
50+
- KEYCLOAK_INTERNAL_HOST=http://keycloak:8080
4751
depends_on:
4852
- database
4953
command: bash -c "bash /tmp/scripts/wait-for-it.sh -t 120 -h database -p 5432 && /start-reload.sh"

runtime/eoapi/stac/eoapi/stac/app.py

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -35,12 +35,7 @@
3535
tiles_settings = TilesApiSettings()
3636
settings = Settings()
3737

38-
keycloak = KeycloakAuth(
39-
realm="eoapi",
40-
client_id="stac-api",
41-
host="http://localhost:8080",
42-
internal_host="http://keycloak:8080",
43-
)
38+
keycloak = KeycloakAuth()
4439

4540

4641
@asynccontextmanager

runtime/eoapi/stac/eoapi/stac/auth.py

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,24 @@
11
from typing import Annotated, Dict, Iterable, List, Optional, TypedDict
2-
from dataclasses import dataclass, field
32
from functools import cached_property
43

54
import jwt
5+
import pydantic
66
from fastapi import HTTPException, Security, security, status
77

88

9-
@dataclass
10-
class KeycloakAuth:
9+
class KeycloakAuth(pydantic.BaseSettings):
1110
realm: str
1211
host: str
1312
client_id: str
1413
internal_host: Optional[str] = None
1514

1615
required_audience: Optional[str | Iterable[str]] = None
17-
scopes: Dict[str, str] = field(default_factory=lambda: {})
16+
scopes: Dict[str, str] = pydantic.Field(default_factory=lambda: {})
17+
18+
class Config:
19+
env_file = ".env"
20+
env_prefix = "KEYCLOAK_"
21+
keep_untouched = (cached_property,)
1822

1923
def _build_url(self, host: str):
2024
return f"{host}/realms/{self.realm}/protocol/openid-connect"

0 commit comments

Comments
 (0)