|
1 | 1 | """Postgres API configuration.""" |
2 | 2 |
|
| 3 | +import json |
3 | 4 | import warnings |
4 | 5 | from typing import Annotated, Any, List, Optional, Sequence, Type |
5 | 6 | from urllib.parse import quote_plus as quote |
6 | 7 |
|
7 | 8 | from pydantic import BaseModel, BeforeValidator, Field, model_validator |
8 | | -from pydantic_settings import BaseSettings, SettingsConfigDict |
| 9 | +from pydantic_settings import BaseSettings, NoDecode, SettingsConfigDict |
9 | 10 | from stac_fastapi.types.config import ApiSettings |
10 | 11 | from typing_extensions import Self |
11 | 12 |
|
@@ -158,8 +159,12 @@ def connection_string(self): |
158 | 159 |
|
159 | 160 | def str_to_list(value: Any) -> Any: |
160 | 161 | if isinstance(value, str): |
161 | | - return [v.strip() for v in value.split(",")] |
162 | | - return value |
| 162 | + if value.startswith("["): |
| 163 | + return json.loads(value) |
| 164 | + else: |
| 165 | + return [v.strip() for v in value.split(",")] |
| 166 | + else: |
| 167 | + return value |
163 | 168 |
|
164 | 169 |
|
165 | 170 | class Settings(ApiSettings): |
@@ -201,15 +206,17 @@ class Settings(ApiSettings): |
201 | 206 | Implies that the `Transactions` extension is enabled. |
202 | 207 | """ |
203 | 208 |
|
204 | | - cors_origins: Annotated[Sequence[str], BeforeValidator(str_to_list)] = ("*",) |
| 209 | + cors_origins: Annotated[Sequence[str], BeforeValidator(str_to_list), NoDecode] = ( |
| 210 | + "*", |
| 211 | + ) |
205 | 212 | cors_origin_regex: Optional[str] = None |
206 | | - cors_methods: Annotated[Sequence[str], BeforeValidator(str_to_list)] = ( |
| 213 | + cors_methods: Annotated[Sequence[str], BeforeValidator(str_to_list), NoDecode] = ( |
207 | 214 | "GET", |
208 | 215 | "POST", |
209 | 216 | "OPTIONS", |
210 | 217 | ) |
211 | 218 | cors_credentials: bool = False |
212 | | - cors_headers: Annotated[Sequence[str], BeforeValidator(str_to_list)] = ( |
| 219 | + cors_headers: Annotated[Sequence[str], BeforeValidator(str_to_list), NoDecode] = ( |
213 | 220 | "Content-Type", |
214 | 221 | ) |
215 | 222 |
|
|
0 commit comments