-
Notifications
You must be signed in to change notification settings - Fork 0
/
settings.py
77 lines (54 loc) · 1.77 KB
/
settings.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
"""API settings."""
from typing import Literal
from pydantic import Field, field_validator, model_validator
from pydantic_settings import BaseSettings
from typing_extensions import Annotated
class ApiSettings(BaseSettings):
"""API settings"""
name: str = "titiler-cmr"
cors_origins: str = "*"
cachecontrol: str = "public, max-age=3600"
root_path: str = ""
debug: bool = False
model_config = {
"env_prefix": "TITILER_CMR_API_",
"env_file": ".env",
"extra": "ignore",
}
@field_validator("cors_origins")
def parse_cors_origin(cls, v):
"""Parse CORS origins."""
return [origin.strip() for origin in v.split(",")]
class CacheSettings(BaseSettings):
"""Cache settings"""
# TTL of the cache in seconds
ttl: int = 300
# Maximum size of the cache in Number of element
maxsize: int = 512
# Whether or not caching is enabled
disable: bool = False
model_config = {"env_prefix": "TITILER_CMR_CACHE_", "env_file": ".env"}
@model_validator(mode="after")
def check_enable(self):
"""Check if cache is disabled."""
if self.disable:
self.ttl = 0
self.maxsize = 0
return self
class RetrySettings(BaseSettings):
"""Retry settings"""
retry: Annotated[int, Field(ge=0)] = 3
delay: Annotated[float, Field(ge=0.0)] = 0.0
model_config = {
"env_prefix": "TITILER_CMR_API_",
"env_file": ".env",
"extra": "ignore",
}
class AuthSettings(BaseSettings):
"""AWS credential settings."""
strategy: Literal["environment", "iam", "netrc"] = "environment"
access: Literal["direct", "external"] = "direct"
model_config = {
"env_prefix": "TITILER_CMR_S3_AUTH_",
"env_file": ".env",
}