-
Notifications
You must be signed in to change notification settings - Fork 99
/
config.py
59 lines (43 loc) · 1.6 KB
/
config.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
"""Application settings."""
from typing import Optional, Set
from pydantic import BaseSettings
class ApiSettings(BaseSettings):
"""Application settings"""
environment: str
debug: bool = False
postgres_user: str
postgres_pass: str
postgres_host_reader: str
postgres_host_writer: str
postgres_port: str
postgres_dbname: str
# Fields which are defined by STAC but not included in the database model
forbidden_fields: Set[str] = {"type", "stac_version"}
# Fields which are item properties but indexed as distinct fields in the database model
indexed_fields: Set[str] = {"datetime"}
# Fields which are always included in the response (fields extension)
default_includes: Set[str] = {
"id",
"type",
"geometry",
"bbox",
"links",
"assets",
"properties.datetime",
}
class Config:
"""model config"""
env_file = ".env"
@property
def reader_connection_string(self):
"""Create reader psql connection string"""
return f"postgresql://{self.postgres_user}:{self.postgres_pass}@{self.postgres_host_reader}:{self.postgres_port}/{self.postgres_dbname}"
@property
def writer_connection_string(self):
"""Create writer psql connection string"""
return f"postgresql://{self.postgres_user}:{self.postgres_pass}@{self.postgres_host_writer}:{self.postgres_port}/{self.postgres_dbname}"
settings: Optional[ApiSettings] = None
def inject_settings(base_settings: ApiSettings):
"""Inject settings to global scope"""
global settings
settings = base_settings